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    
ui-component-library / src / inputs / Incrementer / renderProps.tsx
Size: Mime:
import React from 'react'
import { IncrementerProps, DefaultIncrementerState } from './typings'
import {
  StyledInput,
  InputBoxWrapper,
  StyledButton,
  StyledPlusIcon,
  StyledMinusIcon,
  InnerWrapper,
  IncrementerWrapper,
} from './styled'

function defaultOnIncrement(
  props: IncrementerProps,
  state: DefaultIncrementerState
) {
  return state.incrementCount(props)
}

function defaultOnDecrement(
  props: IncrementerProps,
  state: DefaultIncrementerState
) {
  return state.decrementCount(props)
}

function defaultRenderBox(
  props: IncrementerProps,
  state: DefaultIncrementerState
) {
  const increment = event => defaultOnIncrement(props, state)
  const decrement = event => defaultOnDecrement(props, state)
  const { onChange } = props

  return (
    <InnerWrapper>
      <StyledButton onClick={decrement} isDisabled={!state.shouldDecrement}>
        <StyledMinusIcon />
      </StyledButton>
      <InputBoxWrapper>
        <StyledInput
          type="text"
          value={state.count}
          onChange={onChange(state.count)}
        />
      </InputBoxWrapper>
      <StyledButton onClick={increment} isDisabled={!state.shouldIncrement}>
        <StyledPlusIcon />
      </StyledButton>
    </InnerWrapper>
  )
}

function defaultRenderWrapper(props: IncrementerProps) {
  const { children, nowrap, className } = props

  if (nowrap) {
    return <React.Fragment>{children}</React.Fragment>
  } else {
    return (
      <IncrementerWrapper className={className}>{children}</IncrementerWrapper>
    )
  }
}

export { defaultRenderBox, defaultRenderWrapper }