UNPKG

6.79 kBJavaScriptView Raw
1"use client";
2
3var __rest = this && this.__rest || function (s, e) {
4 var t = {};
5 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6 if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
8 }
9 return t;
10};
11import * as React from 'react';
12import DownOutlined from "@ant-design/icons/es/icons/DownOutlined";
13import UpOutlined from "@ant-design/icons/es/icons/UpOutlined";
14import classNames from 'classnames';
15import RcInputNumber from 'rc-input-number';
16import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
17import { devUseWarning } from '../_util/warning';
18import ConfigProvider, { ConfigContext } from '../config-provider';
19import DisabledContext from '../config-provider/DisabledContext';
20import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
21import useSize from '../config-provider/hooks/useSize';
22import { FormItemInputContext, NoFormStyle } from '../form/context';
23import useVariant from '../form/hooks/useVariants';
24import { NoCompactStyle, useCompactItemContext } from '../space/Compact';
25import useStyle from './style';
26const InputNumber = /*#__PURE__*/React.forwardRef((props, ref) => {
27 if (process.env.NODE_ENV !== 'production') {
28 const {
29 deprecated
30 } = devUseWarning('InputNumber');
31 deprecated(!('bordered' in props), 'bordered', 'variant');
32 }
33 const {
34 getPrefixCls,
35 direction
36 } = React.useContext(ConfigContext);
37 const inputRef = React.useRef(null);
38 React.useImperativeHandle(ref, () => inputRef.current);
39 const {
40 className,
41 rootClassName,
42 size: customizeSize,
43 disabled: customDisabled,
44 prefixCls: customizePrefixCls,
45 addonBefore,
46 addonAfter,
47 prefix,
48 bordered,
49 readOnly,
50 status: customStatus,
51 controls,
52 variant: customVariant
53 } = props,
54 others = __rest(props, ["className", "rootClassName", "size", "disabled", "prefixCls", "addonBefore", "addonAfter", "prefix", "bordered", "readOnly", "status", "controls", "variant"]);
55 const prefixCls = getPrefixCls('input-number', customizePrefixCls);
56 // Style
57 const rootCls = useCSSVarCls(prefixCls);
58 const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls, rootCls);
59 const {
60 compactSize,
61 compactItemClassnames
62 } = useCompactItemContext(prefixCls, direction);
63 let upIcon = /*#__PURE__*/React.createElement(UpOutlined, {
64 className: `${prefixCls}-handler-up-inner`
65 });
66 let downIcon = /*#__PURE__*/React.createElement(DownOutlined, {
67 className: `${prefixCls}-handler-down-inner`
68 });
69 const controlsTemp = typeof controls === 'boolean' ? controls : undefined;
70 if (typeof controls === 'object') {
71 upIcon = typeof controls.upIcon === 'undefined' ? upIcon : ( /*#__PURE__*/React.createElement("span", {
72 className: `${prefixCls}-handler-up-inner`
73 }, controls.upIcon));
74 downIcon = typeof controls.downIcon === 'undefined' ? downIcon : ( /*#__PURE__*/React.createElement("span", {
75 className: `${prefixCls}-handler-down-inner`
76 }, controls.downIcon));
77 }
78 const {
79 hasFeedback,
80 status: contextStatus,
81 isFormItemInput,
82 feedbackIcon
83 } = React.useContext(FormItemInputContext);
84 const mergedStatus = getMergedStatus(contextStatus, customStatus);
85 const mergedSize = useSize(ctx => {
86 var _a;
87 return (_a = customizeSize !== null && customizeSize !== void 0 ? customizeSize : compactSize) !== null && _a !== void 0 ? _a : ctx;
88 });
89 // ===================== Disabled =====================
90 const disabled = React.useContext(DisabledContext);
91 const mergedDisabled = customDisabled !== null && customDisabled !== void 0 ? customDisabled : disabled;
92 const [variant, enableVariantCls] = useVariant(customVariant, bordered);
93 // eslint-disable-next-line react/jsx-no-useless-fragment
94 const suffixNode = hasFeedback && /*#__PURE__*/React.createElement(React.Fragment, null, feedbackIcon);
95 const inputNumberClass = classNames({
96 [`${prefixCls}-lg`]: mergedSize === 'large',
97 [`${prefixCls}-sm`]: mergedSize === 'small',
98 [`${prefixCls}-rtl`]: direction === 'rtl',
99 [`${prefixCls}-in-form-item`]: isFormItemInput
100 }, hashId);
101 const wrapperClassName = `${prefixCls}-group`;
102 const element = /*#__PURE__*/React.createElement(RcInputNumber, Object.assign({
103 ref: inputRef,
104 disabled: mergedDisabled,
105 className: classNames(cssVarCls, rootCls, className, rootClassName, compactItemClassnames),
106 upHandler: upIcon,
107 downHandler: downIcon,
108 prefixCls: prefixCls,
109 readOnly: readOnly,
110 controls: controlsTemp,
111 prefix: prefix,
112 suffix: suffixNode,
113 addonAfter: addonAfter && ( /*#__PURE__*/React.createElement(NoCompactStyle, null, /*#__PURE__*/React.createElement(NoFormStyle, {
114 override: true,
115 status: true
116 }, addonAfter))),
117 addonBefore: addonBefore && ( /*#__PURE__*/React.createElement(NoCompactStyle, null, /*#__PURE__*/React.createElement(NoFormStyle, {
118 override: true,
119 status: true
120 }, addonBefore))),
121 classNames: {
122 input: inputNumberClass,
123 variant: classNames({
124 [`${prefixCls}-${variant}`]: enableVariantCls
125 }, getStatusClassNames(prefixCls, mergedStatus, hasFeedback)),
126 affixWrapper: classNames({
127 [`${prefixCls}-affix-wrapper-sm`]: mergedSize === 'small',
128 [`${prefixCls}-affix-wrapper-lg`]: mergedSize === 'large',
129 [`${prefixCls}-affix-wrapper-rtl`]: direction === 'rtl'
130 }, hashId),
131 wrapper: classNames({
132 [`${wrapperClassName}-rtl`]: direction === 'rtl'
133 }, hashId),
134 groupWrapper: classNames({
135 [`${prefixCls}-group-wrapper-sm`]: mergedSize === 'small',
136 [`${prefixCls}-group-wrapper-lg`]: mergedSize === 'large',
137 [`${prefixCls}-group-wrapper-rtl`]: direction === 'rtl',
138 [`${prefixCls}-group-wrapper-${variant}`]: enableVariantCls
139 }, getStatusClassNames(`${prefixCls}-group-wrapper`, mergedStatus, hasFeedback), hashId)
140 }
141 }, others));
142 return wrapCSSVar(element);
143});
144const TypedInputNumber = InputNumber;
145/** @private Internal Component. Do not use in your production. */
146const PureInputNumber = props => ( /*#__PURE__*/React.createElement(ConfigProvider, {
147 theme: {
148 components: {
149 InputNumber: {
150 handleVisible: true
151 }
152 }
153 }
154}, /*#__PURE__*/React.createElement(InputNumber, Object.assign({}, props))));
155if (process.env.NODE_ENV !== 'production') {
156 TypedInputNumber.displayName = 'InputNumber';
157}
158TypedInputNumber._InternalPanelDoNotUseOrYouWillBeFired = PureInputNumber;
159export default TypedInputNumber;
\No newline at end of file