All files / source/button_plus button_plus.js

100% Statements 14/14
100% Branches 2/2
75% Functions 3/4
100% Lines 14/14
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81                    3x     3x           2x     2x 2x       2x 1x       2x           3x     3x         3x               3x                 3x               3x                  
// Dependencies.
import React from 'react'
import PropTypes from 'prop-types'
import { Button } from '@t7/forms'
import { bind } from '@t7/utils'
 
// Define class.
class ButtonPlus extends React.Component {
  constructor (props) {
    // Pass `props` into scope.
    super(props)
 
    // Bind context.
    bind(this)
  }
 
  // Click event.
  handleClick () {
    // Props.
    let { count } = this.props
 
    // Increment.
    try {
      count++
    } catch (e) {}
 
    // Ensure numeric.
    if (isNaN(count)) {
      count = 0
    }
 
    // Fire callback.
    this.props.handleClick(count)
  }
 
  // Render method.
  render () {
    // Events.
    const { handleClick } = this
 
    // Style.
    const style = {
      fontFamily: 'monospace'
    }
 
    // Props for button.
    const propsForButton = {
      handleClick,
      style,
      children: '+',
      title: 'Plus'
    }
 
    // Expose UI.
    return (
      <Button
        {...propsForButton}
      />
    )
  }
}
 
// Validation.
ButtonPlus.propTypes = {
  count: PropTypes.number,
 
  // Events.
  handleClick: PropTypes.func
}
 
// Defaults.
ButtonPlus.defaultProps = {
  count: 0,
 
  // Events.
  handleClick: () => {}
}
 
// Export.
export default ButtonPlus