Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui / src / inputs / Incrementer / IncrementerBox.tsx
Size: Mime:
import React from 'react'
import { isFunction } from 'exotic'
import { observer } from 'xmobx/mobx-react'
import { IncrementerBoxProps } from './typings'
import { StyledInput, StyledPlusButton, StyledMinusButton } from './styled'

@observer
export class IncrementerBox extends React.Component<IncrementerBoxProps> {
  handleDecrement = () => {
    const { state, onValueChange } = this.props
    state.decrementCount()
    if (isFunction(onValueChange)) {
      onValueChange(state.count)
    }
  }

  handleIncrement = () => {
    const { state, onValueChange } = this.props
    state.incrementCount()
     if (isFunction(onValueChange)) {
      onValueChange(state.count)
    }
  }

  handleChange = () => {
    const { state, onValueChange } = this.props
    state.handleChange(event)
    if (isFunction(onValueChange)) {
      onValueChange(state.count)
    }
  }
  
  render() {
    const {
      state,
    } = this.props

    return (
      <React.Fragment>
        <StyledMinusButton
          onClick={this.handleDecrement}
          isDisabled={!state.shouldDecrement}
        />
        <StyledInput
          value={state.count}
          onChange={this.handleChange}
          onBlur={state.handleBlur}
        />
        <StyledPlusButton
          onClick={this.handleIncrement}
          isDisabled={!state.shouldIncrement}
        />
      </React.Fragment>
    )
  }
}