All files / src/TimePicker TimeTicker.js

100% Statements 2/2
100% Branches 0/0
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                                                                              97x   97x                                              
/** @jsx createElement */
import {Component, createElement} from 'react'
import PropTypes from 'prop-types'
import Button from '../Button'
 
/**
 * A component which increments or decrements a unit of time,
 * e.g. (01-12 for hours, 00-59 for minutes, and AM/PM)
 * @param {object} props - the props of the TimeTicker
 */
 
// TODO: Generalize this to a general incrementor/decrementor
// component that can cycle through a range of numbers or an enum
 
class TimeTicker extends Component {
  static propTypes = {
    previousLabel: PropTypes.node,
    nextLabel: PropTypes.node,
    value: PropTypes.any,
    onIncrement: PropTypes.func,
    onDecrement: PropTypes.func,
    refocusOnClick: PropTypes.bool,
    className: PropTypes.string,
  }
 
  static defaultProps = {
    previousLabel: <span>&#709;</span>,
    nextLabel: <span>&#708;</span>,
  }
 
  render() {
    const {
      className,
      previousLabel,
      nextLabel,
      value,
      onIncrement,
      onDecrement,
      ...props
    } = this.props
 
    return (
      <div {...props} className={`rev-TimeTicker ${className}`}>
        <Button
          onClick={onIncrement}
          className="rev-TimeTicker-button rev-TimeTicker-button--next"
        >
          {nextLabel}
        </Button>
 
        <div className="rev-TimeTicker-value">{value}</div>
 
        <Button
          onClick={onDecrement}
          className="rev-TimeTicker-button rev-TimeTicker-button--previous"
        >
          {previousLabel}
        </Button>
      </div>
    )
  }
}
 
export default TimeTicker