2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2015-11-25 15:46:44 +08:00
|
|
|
import classNames from 'classnames';
|
2021-02-22 22:07:19 +08:00
|
|
|
import RcInputNumber, { InputNumberProps as RcInputNumberProps } from 'rc-input-number';
|
2020-03-02 12:09:38 +08:00
|
|
|
import UpOutlined from '@ant-design/icons/UpOutlined';
|
|
|
|
import DownOutlined from '@ant-design/icons/DownOutlined';
|
2019-08-13 14:07:17 +08:00
|
|
|
|
2020-10-12 10:59:40 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2020-01-03 13:38:16 +08:00
|
|
|
import SizeContext, { SizeType } from '../config-provider/SizeContext';
|
2018-05-22 10:46:20 +08:00
|
|
|
|
2021-02-22 22:07:19 +08:00
|
|
|
type ValueType = string | number;
|
2018-05-22 10:46:20 +08:00
|
|
|
|
2021-02-22 22:07:19 +08:00
|
|
|
export interface InputNumberProps<T extends ValueType = ValueType>
|
|
|
|
extends Omit<RcInputNumberProps<T>, 'size'> {
|
2016-08-19 17:11:06 +08:00
|
|
|
prefixCls?: string;
|
2020-01-03 13:38:16 +08:00
|
|
|
size?: SizeType;
|
2021-02-01 17:06:20 +08:00
|
|
|
bordered?: boolean;
|
2016-08-19 17:11:06 +08:00
|
|
|
}
|
|
|
|
|
2021-02-22 22:07:19 +08:00
|
|
|
const InputNumber = React.forwardRef<HTMLInputElement, InputNumberProps>((props, ref) => {
|
2020-10-12 10:59:40 +08:00
|
|
|
const { getPrefixCls, direction } = React.useContext(ConfigContext);
|
|
|
|
const size = React.useContext(SizeContext);
|
2015-11-25 15:46:44 +08:00
|
|
|
|
2020-10-12 10:59:40 +08:00
|
|
|
const {
|
|
|
|
className,
|
|
|
|
size: customizeSize,
|
|
|
|
prefixCls: customizePrefixCls,
|
2021-02-01 17:06:20 +08:00
|
|
|
bordered = true,
|
2020-10-12 10:59:40 +08:00
|
|
|
readOnly,
|
|
|
|
...others
|
|
|
|
} = props;
|
2020-01-03 13:38:16 +08:00
|
|
|
|
2020-10-12 10:59:40 +08:00
|
|
|
const prefixCls = getPrefixCls('input-number', customizePrefixCls);
|
|
|
|
const upIcon = <UpOutlined className={`${prefixCls}-handler-up-inner`} />;
|
|
|
|
const downIcon = <DownOutlined className={`${prefixCls}-handler-down-inner`} />;
|
2017-09-15 15:47:06 +08:00
|
|
|
|
2020-10-12 10:59:40 +08:00
|
|
|
const mergeSize = customizeSize || size;
|
|
|
|
const inputNumberClass = classNames(
|
|
|
|
{
|
|
|
|
[`${prefixCls}-lg`]: mergeSize === 'large',
|
|
|
|
[`${prefixCls}-sm`]: mergeSize === 'small',
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
|
|
[`${prefixCls}-readonly`]: readOnly,
|
2021-02-01 17:06:20 +08:00
|
|
|
[`${prefixCls}-borderless`]: !bordered,
|
2020-10-12 10:59:40 +08:00
|
|
|
},
|
|
|
|
className,
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<RcInputNumber
|
|
|
|
ref={ref}
|
|
|
|
className={inputNumberClass}
|
|
|
|
upHandler={upIcon}
|
|
|
|
downHandler={downIcon}
|
|
|
|
prefixCls={prefixCls}
|
|
|
|
readOnly={readOnly}
|
|
|
|
{...others}
|
|
|
|
/>
|
|
|
|
);
|
2020-04-22 09:48:10 +08:00
|
|
|
});
|
|
|
|
|
2021-02-22 22:07:19 +08:00
|
|
|
export default InputNumber as (<T extends ValueType = ValueType>(
|
|
|
|
props: React.PropsWithChildren<InputNumberProps<T>> & {
|
|
|
|
ref?: React.Ref<HTMLInputElement>;
|
|
|
|
},
|
|
|
|
) => React.ReactElement) & { displayName?: string };
|