1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
5 | const _excluded = ["className", "defaultValue", "disabled", "endAdornment", "error", "id", "max", "min", "onBlur", "onInputChange", "onFocus", "onChange", "placeholder", "required", "readOnly", "shiftMultiplier", "startAdornment", "step", "value", "slotProps", "slots"];
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import { getNumberInputUtilityClass } from './numberInputClasses';
|
9 | import { unstable_useNumberInput as useNumberInput } from '../unstable_useNumberInput';
|
10 | import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
11 | import { useSlotProps } from '../utils';
|
12 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
13 | import { jsx as _jsx } from "react/jsx-runtime";
|
14 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
15 | const useUtilityClasses = ownerState => {
|
16 | const {
|
17 | disabled,
|
18 | error,
|
19 | focused,
|
20 | readOnly,
|
21 | formControlContext,
|
22 | isIncrementDisabled,
|
23 | isDecrementDisabled,
|
24 | startAdornment,
|
25 | endAdornment
|
26 | } = ownerState;
|
27 | const slots = {
|
28 | root: ['root', disabled && 'disabled', error && 'error', focused && 'focused', readOnly && 'readOnly', Boolean(formControlContext) && 'formControl', Boolean(startAdornment) && 'adornedStart', Boolean(endAdornment) && 'adornedEnd'],
|
29 | input: ['input', disabled && 'disabled', readOnly && 'readOnly'],
|
30 | incrementButton: ['incrementButton', isIncrementDisabled && 'disabled'],
|
31 | decrementButton: ['decrementButton', isDecrementDisabled && 'disabled']
|
32 | };
|
33 | return composeClasses(slots, useClassNamesOverride(getNumberInputUtilityClass));
|
34 | };
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | const NumberInput = React.forwardRef(function NumberInput(props, forwardedRef) {
|
47 | var _slots$root, _slots$input, _slots$incrementButto, _slots$decrementButto;
|
48 | const {
|
49 | className,
|
50 | defaultValue,
|
51 | disabled,
|
52 | endAdornment,
|
53 | error,
|
54 | id,
|
55 | max,
|
56 | min,
|
57 | onBlur,
|
58 | onInputChange,
|
59 | onFocus,
|
60 | onChange,
|
61 | placeholder,
|
62 | required,
|
63 | readOnly = false,
|
64 | shiftMultiplier,
|
65 | startAdornment,
|
66 | step,
|
67 | value,
|
68 | slotProps = {},
|
69 | slots = {}
|
70 | } = props,
|
71 | rest = _objectWithoutPropertiesLoose(props, _excluded);
|
72 | const {
|
73 | getRootProps,
|
74 | getInputProps,
|
75 | getIncrementButtonProps,
|
76 | getDecrementButtonProps,
|
77 | focused,
|
78 | error: errorState,
|
79 | disabled: disabledState,
|
80 | formControlContext,
|
81 | isIncrementDisabled,
|
82 | isDecrementDisabled
|
83 | } = useNumberInput({
|
84 | min,
|
85 | max,
|
86 | step,
|
87 | shiftMultiplier,
|
88 | defaultValue,
|
89 | disabled,
|
90 | error,
|
91 | onFocus,
|
92 | onInputChange,
|
93 | onBlur,
|
94 | onChange,
|
95 | required,
|
96 | readOnly,
|
97 | value,
|
98 | inputId: id,
|
99 | componentName: 'NumberInput'
|
100 | });
|
101 | const ownerState = _extends({}, props, {
|
102 | disabled: disabledState,
|
103 | error: errorState,
|
104 | focused,
|
105 | readOnly,
|
106 | formControlContext,
|
107 | isIncrementDisabled,
|
108 | isDecrementDisabled
|
109 | });
|
110 | const classes = useUtilityClasses(ownerState);
|
111 | const propsForwardedToInputSlot = {
|
112 | placeholder
|
113 | };
|
114 | const Root = (_slots$root = slots.root) != null ? _slots$root : 'div';
|
115 | const rootProps = useSlotProps({
|
116 | elementType: Root,
|
117 | getSlotProps: getRootProps,
|
118 | externalSlotProps: slotProps.root,
|
119 | externalForwardedProps: rest,
|
120 | additionalProps: {
|
121 | ref: forwardedRef
|
122 | },
|
123 | ownerState,
|
124 | className: [classes.root, className]
|
125 | });
|
126 | const Input = (_slots$input = slots.input) != null ? _slots$input : 'input';
|
127 | const inputProps = useSlotProps({
|
128 | elementType: Input,
|
129 | getSlotProps: otherHandlers => getInputProps(_extends({}, propsForwardedToInputSlot, otherHandlers)),
|
130 | externalSlotProps: slotProps.input,
|
131 | ownerState,
|
132 | className: classes.input
|
133 | });
|
134 | const IncrementButton = (_slots$incrementButto = slots.incrementButton) != null ? _slots$incrementButto : 'button';
|
135 | const incrementButtonProps = useSlotProps({
|
136 | elementType: IncrementButton,
|
137 | getSlotProps: getIncrementButtonProps,
|
138 | externalSlotProps: slotProps.incrementButton,
|
139 | ownerState,
|
140 | className: classes.incrementButton
|
141 | });
|
142 | const DecrementButton = (_slots$decrementButto = slots.decrementButton) != null ? _slots$decrementButto : 'button';
|
143 | const decrementButtonProps = useSlotProps({
|
144 | elementType: DecrementButton,
|
145 | getSlotProps: getDecrementButtonProps,
|
146 | externalSlotProps: slotProps.decrementButton,
|
147 | ownerState,
|
148 | className: classes.decrementButton
|
149 | });
|
150 | return _jsxs(Root, _extends({}, rootProps, {
|
151 | children: [_jsx(DecrementButton, _extends({}, decrementButtonProps)), _jsx(IncrementButton, _extends({}, incrementButtonProps)), startAdornment, _jsx(Input, _extends({}, inputProps)), endAdornment]
|
152 | }));
|
153 | });
|
154 | process.env.NODE_ENV !== "production" ? NumberInput.propTypes = {
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | |
160 |
|
161 |
|
162 | children: PropTypes.node,
|
163 | |
164 |
|
165 |
|
166 | className: PropTypes.string,
|
167 | |
168 |
|
169 |
|
170 | defaultValue: PropTypes.number,
|
171 | |
172 |
|
173 |
|
174 |
|
175 | disabled: PropTypes.bool,
|
176 | |
177 |
|
178 |
|
179 | endAdornment: PropTypes.node,
|
180 | |
181 |
|
182 |
|
183 | error: PropTypes.bool,
|
184 | |
185 |
|
186 |
|
187 | id: PropTypes.string,
|
188 | |
189 |
|
190 |
|
191 | max: PropTypes.number,
|
192 | |
193 |
|
194 |
|
195 | min: PropTypes.number,
|
196 | |
197 |
|
198 |
|
199 | onBlur: PropTypes.func,
|
200 | |
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 | onChange: PropTypes.func,
|
209 | |
210 |
|
211 |
|
212 | onFocus: PropTypes.func,
|
213 | |
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | onInputChange: PropTypes.func,
|
221 | |
222 |
|
223 |
|
224 | placeholder: PropTypes.string,
|
225 | |
226 |
|
227 |
|
228 |
|
229 |
|
230 | readOnly: PropTypes.bool,
|
231 | |
232 |
|
233 |
|
234 |
|
235 | required: PropTypes.bool,
|
236 | |
237 |
|
238 |
|
239 |
|
240 | shiftMultiplier: PropTypes.number,
|
241 | |
242 |
|
243 |
|
244 |
|
245 | slotProps: PropTypes.shape({
|
246 | decrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
247 | incrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
248 | input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
249 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
250 | }),
|
251 | |
252 |
|
253 |
|
254 |
|
255 |
|
256 | slots: PropTypes.shape({
|
257 | decrementButton: PropTypes.elementType,
|
258 | incrementButton: PropTypes.elementType,
|
259 | input: PropTypes.elementType,
|
260 | root: PropTypes.elementType
|
261 | }),
|
262 | |
263 |
|
264 |
|
265 | startAdornment: PropTypes.node,
|
266 | |
267 |
|
268 |
|
269 | step: PropTypes.number,
|
270 | |
271 |
|
272 |
|
273 |
|
274 | value: PropTypes.number
|
275 | } : void 0;
|
276 | export { NumberInput }; |
\ | No newline at end of file |