1 | "use client";
|
2 |
|
3 | var __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 | };
|
11 | import * as React from 'react';
|
12 | import DownOutlined from "@ant-design/icons/es/icons/DownOutlined";
|
13 | import UpOutlined from "@ant-design/icons/es/icons/UpOutlined";
|
14 | import classNames from 'classnames';
|
15 | import RcInputNumber from 'rc-input-number';
|
16 | import { getMergedStatus, getStatusClassNames } from '../_util/statusUtils';
|
17 | import { devUseWarning } from '../_util/warning';
|
18 | import ConfigProvider, { ConfigContext } from '../config-provider';
|
19 | import DisabledContext from '../config-provider/DisabledContext';
|
20 | import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
21 | import useSize from '../config-provider/hooks/useSize';
|
22 | import { FormItemInputContext, NoFormStyle } from '../form/context';
|
23 | import useVariant from '../form/hooks/useVariants';
|
24 | import { NoCompactStyle, useCompactItemContext } from '../space/Compact';
|
25 | import useStyle from './style';
|
26 | const InputNumber = 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 |
|
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 = React.createElement(UpOutlined, {
|
64 | className: `${prefixCls}-handler-up-inner`
|
65 | });
|
66 | let downIcon = 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 : ( React.createElement("span", {
|
72 | className: `${prefixCls}-handler-up-inner`
|
73 | }, controls.upIcon));
|
74 | downIcon = typeof controls.downIcon === 'undefined' ? downIcon : ( 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 |
|
90 | const disabled = React.useContext(DisabledContext);
|
91 | const mergedDisabled = customDisabled !== null && customDisabled !== void 0 ? customDisabled : disabled;
|
92 | const [variant, enableVariantCls] = useVariant(customVariant, bordered);
|
93 |
|
94 | const suffixNode = hasFeedback && 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 = 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 && ( React.createElement(NoCompactStyle, null, React.createElement(NoFormStyle, {
|
114 | override: true,
|
115 | status: true
|
116 | }, addonAfter))),
|
117 | addonBefore: addonBefore && ( React.createElement(NoCompactStyle, null, 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 | });
|
144 | const TypedInputNumber = InputNumber;
|
145 |
|
146 | const PureInputNumber = props => ( React.createElement(ConfigProvider, {
|
147 | theme: {
|
148 | components: {
|
149 | InputNumber: {
|
150 | handleVisible: true
|
151 | }
|
152 | }
|
153 | }
|
154 | }, React.createElement(InputNumber, Object.assign({}, props))));
|
155 | if (process.env.NODE_ENV !== 'production') {
|
156 | TypedInputNumber.displayName = 'InputNumber';
|
157 | }
|
158 | TypedInputNumber._InternalPanelDoNotUseOrYouWillBeFired = PureInputNumber;
|
159 | export default TypedInputNumber; |
\ | No newline at end of file |