UNPKG

@td-design/react-native

Version:

react-native UI组件库

96 lines 3 kB
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import React, { forwardRef } from 'react'; import { composeRestyleFunctions, layout, useRestyle, useTheme } from '@shopify/restyle'; import Box from '../box'; import Flex from '../flex'; import helpers from '../helpers'; import Input from '../input'; import Pressable from '../pressable'; import SvgIcon from '../svg-icon'; import useStepper from './useStepper'; const { ONE_PIXEL, px } = helpers; const Stepper = /*#__PURE__*/forwardRef((_ref, // eslint-disable-next-line @typescript-eslint/no-unused-vars _) => { let { min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY, value, onChange, step = 1, width = px(200), defaultValue, disabled = false, allowClear = true, editable = true, activeOpacity = 0.6, ...layoutProps } = _ref; const restyleFunctions = composeRestyleFunctions([layout]); const theme = useTheme(); const props = useRestyle(restyleFunctions, layoutProps); const { current, handleAdd, handleMinus, handleChange } = useStepper({ defaultValue, value, min, max, onChange, step }); return /*#__PURE__*/React.createElement(Flex, _extends({}, props, { width: width, minWidth: px(120) }), /*#__PURE__*/React.createElement(Pressable, { activeOpacity: activeOpacity, onPress: handleMinus, disabled: disabled || +current - step < min }, /*#__PURE__*/React.createElement(Box, { padding: "x2", justifyContent: "center", alignItems: "center", borderWidth: ONE_PIXEL, borderColor: "border", borderRadius: "x1" }, /*#__PURE__*/React.createElement(SvgIcon, { name: "minus", color: disabled ? theme.colors.disabled : theme.colors.gray500 }))), /*#__PURE__*/React.createElement(Box, { flex: 1, minWidth: px(80), paddingHorizontal: "x1" }, /*#__PURE__*/React.createElement(Input, { keyboardType: "number-pad", value: String(current), onChange: handleChange, disabled: disabled || !editable, allowClear, inputStyle: { textAlign: 'center' } })), /*#__PURE__*/React.createElement(Pressable, { activeOpacity: activeOpacity, onPress: handleAdd, disabled: disabled || +current + step > max }, /*#__PURE__*/React.createElement(Box, { padding: "x2", justifyContent: "center", alignItems: "center", borderWidth: ONE_PIXEL, borderColor: "border", borderRadius: "x1" }, /*#__PURE__*/React.createElement(SvgIcon, { name: "plus", color: disabled ? theme.colors.disabled : theme.colors.gray500 })))); }); Stepper.displayName = 'Stepper'; export default Stepper; //# sourceMappingURL=index.js.map