UNPKG

@antv/s2-react-components

Version:

React components for S2

29 lines 1.26 kB
import { __rest } from "tslib"; import { S2_PREFIX_CLS } from '@antv/s2'; import { InputNumber } from 'antd'; import { debounce } from 'lodash'; import React from 'react'; const PRE_CLASS = `${S2_PREFIX_CLS}-frozen-input-number`; export const FrozenInputNumber = React.memo((props) => { const { disabled, value, onChange } = props, attrs = __rest(props, ["disabled", "value", "onChange"]); const [inputValue, setInputValue] = React.useState(value); const onDebounceChange = React.useMemo(() => { return debounce((nextValue) => { onChange === null || onChange === void 0 ? void 0 : onChange(nextValue); }, 500); }, []); React.useEffect(() => { if (value !== inputValue) { setInputValue(value); } return () => { onDebounceChange.cancel(); }; }, [value]); return (React.createElement(InputNumber, Object.assign({ className: PRE_CLASS, size: "small", min: 0, max: 20, step: 1, precision: 0, disabled: disabled }, attrs, { value: inputValue, onChange: (nextValue) => { setInputValue(nextValue); onDebounceChange(nextValue); } }))); }); FrozenInputNumber.displayName = 'FrozenInputNumber'; //# sourceMappingURL=index.js.map