import * as React from 'react'; import classNames from 'classnames'; import RcInputNumber, { InputNumberProps as RcInputNumberProps } from 'rc-input-number'; import UpOutlined from '@ant-design/icons/UpOutlined'; import DownOutlined from '@ant-design/icons/DownOutlined'; import { ConfigContext } from '../config-provider'; import SizeContext, { SizeType } from '../config-provider/SizeContext'; import { cloneElement } from '../_util/reactNode'; type ValueType = string | number; export interface InputNumberProps extends Omit, 'size'> { prefixCls?: string; addonBefore?: React.ReactNode; addonAfter?: React.ReactNode; size?: SizeType; bordered?: boolean; } const InputNumber = React.forwardRef((props, ref) => { const { getPrefixCls, direction } = React.useContext(ConfigContext); const size = React.useContext(SizeContext); const { className, size: customizeSize, prefixCls: customizePrefixCls, addonBefore, addonAfter, bordered = true, readOnly, ...others } = props; const prefixCls = getPrefixCls('input-number', customizePrefixCls); const upIcon = ; const downIcon = ; const mergeSize = customizeSize || size; const inputNumberClass = classNames( { [`${prefixCls}-lg`]: mergeSize === 'large', [`${prefixCls}-sm`]: mergeSize === 'small', [`${prefixCls}-rtl`]: direction === 'rtl', [`${prefixCls}-readonly`]: readOnly, [`${prefixCls}-borderless`]: !bordered, }, className, ); const element = ( ); if (addonBefore != null || addonAfter != null) { const wrapperClassName = `${prefixCls}-group`; const addonClassName = `${wrapperClassName}-addon`; const addonBeforeNode = addonBefore ? (
{addonBefore}
) : null; const addonAfterNode = addonAfter ?
{addonAfter}
: null; const mergedWrapperClassName = classNames(`${prefixCls}-wrapper`, wrapperClassName, { [`${wrapperClassName}-rtl`]: direction === 'rtl', }); const mergedGroupClassName = classNames( `${prefixCls}-group-wrapper`, { [`${prefixCls}-group-wrapper-sm`]: size === 'small', [`${prefixCls}-group-wrapper-lg`]: size === 'large', [`${prefixCls}-group-wrapper-rtl`]: direction === 'rtl', }, className, ); return (
{addonBeforeNode} {cloneElement(element, { style: null })} {addonAfterNode}
); } return element; }); export default InputNumber as (( props: React.PropsWithChildren> & { ref?: React.Ref; }, ) => React.ReactElement) & { displayName?: string };