UNPKG

@kiwicom/orbit-components

Version:

Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.

95 lines (92 loc) 2.91 kB
import * as React from "react"; import styled from "styled-components"; import { SIZE_OPTIONS } from "../../InputField/consts"; import PlusCircle from "../../icons/PlusCircle"; import MinusCircle from "../../icons/MinusCircle"; import ButtonLink from "../../ButtonLink"; import InputField, { Input, Prefix } from "../../InputField"; import defaultTheme from "../../defaultTheme"; import getSpacingToken from "../../common/getSpacingToken"; const StyledInputStepper = styled.div.withConfig({ displayName: "InputStepperStateless__StyledInputStepper", componentId: "sc-1u2800i-0" })(["width:100%;margin-bottom:", ";font-family:", ";", "{text-align:center;&[type=\"number\"]{-moz-appearance:textfield;}}", "{padding:0;pointer-events:auto;}"], getSpacingToken, ({ theme }) => theme.orbit.fontFamily, Input, Prefix); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198 StyledInputStepper.defaultProps = { theme: defaultTheme }; const InputStepperStateless = ({ label, error, onBlur, onFocus, onChange, onKeyDown, help, disabled, name, dataTest, size = SIZE_OPTIONS.NORMAL, maxValue, minValue, required, readOnly, tabIndex, forwardedRef, spaceAfter, value, onDecrement, onIncrement, disabledIncrement, width, disabledDecrement, titleIncrement, titleDecrement }) => { return /*#__PURE__*/React.createElement(StyledInputStepper, { spaceAfter: spaceAfter }, /*#__PURE__*/React.createElement(InputField, { dataTest: dataTest, size: size, label: label, width: width, disabled: disabled, required: required, readOnly: readOnly, name: name, error: error, help: help, type: typeof value === "number" ? "number" : "text", onChange: onChange, onBlur: onBlur, onFocus: onFocus, onKeyDown: onKeyDown, value: value, minValue: minValue, maxValue: maxValue, tabIndex: tabIndex, ref: forwardedRef, prefix: /*#__PURE__*/React.createElement(ButtonLink, { type: "primary", disabled: disabledDecrement || disabled || typeof value === "number" && value <= +minValue, compact: true, iconLeft: /*#__PURE__*/React.createElement(MinusCircle, null), size: size, onClick: !disabled ? onDecrement : undefined, title: titleDecrement, asComponent: props => /*#__PURE__*/React.createElement("div", props) }), suffix: /*#__PURE__*/React.createElement(ButtonLink, { disabled: disabledIncrement || disabled || typeof value === "number" && value >= +maxValue, type: "primary", compact: true, iconLeft: /*#__PURE__*/React.createElement(PlusCircle, null), size: size, onClick: !disabled ? onIncrement : undefined, title: titleIncrement, asComponent: props => /*#__PURE__*/React.createElement("div", props) }) })); }; export default InputStepperStateless;