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 | const {
|
48 | className,
|
49 | defaultValue,
|
50 | disabled,
|
51 | endAdornment,
|
52 | error,
|
53 | id,
|
54 | max,
|
55 | min,
|
56 | onBlur,
|
57 | onInputChange,
|
58 | onFocus,
|
59 | onChange,
|
60 | placeholder,
|
61 | required,
|
62 | readOnly = false,
|
63 | shiftMultiplier,
|
64 | startAdornment,
|
65 | step,
|
66 | value,
|
67 | slotProps = {},
|
68 | slots = {}
|
69 | } = props,
|
70 | rest = _objectWithoutPropertiesLoose(props, _excluded);
|
71 | const {
|
72 | getRootProps,
|
73 | getInputProps,
|
74 | getIncrementButtonProps,
|
75 | getDecrementButtonProps,
|
76 | focused,
|
77 | error: errorState,
|
78 | disabled: disabledState,
|
79 | formControlContext,
|
80 | isIncrementDisabled,
|
81 | isDecrementDisabled
|
82 | } = useNumberInput({
|
83 | min,
|
84 | max,
|
85 | step,
|
86 | shiftMultiplier,
|
87 | defaultValue,
|
88 | disabled,
|
89 | error,
|
90 | onFocus,
|
91 | onInputChange,
|
92 | onBlur,
|
93 | onChange,
|
94 | required,
|
95 | readOnly,
|
96 | value,
|
97 | inputId: id,
|
98 | componentName: 'NumberInput'
|
99 | });
|
100 | const ownerState = _extends({}, props, {
|
101 | disabled: disabledState,
|
102 | error: errorState,
|
103 | focused,
|
104 | readOnly,
|
105 | formControlContext,
|
106 | isIncrementDisabled,
|
107 | isDecrementDisabled
|
108 | });
|
109 | const classes = useUtilityClasses(ownerState);
|
110 | const propsForwardedToInputSlot = {
|
111 | placeholder
|
112 | };
|
113 | const Root = slots.root ?? 'div';
|
114 | const rootProps = useSlotProps({
|
115 | elementType: Root,
|
116 | getSlotProps: getRootProps,
|
117 | externalSlotProps: slotProps.root,
|
118 | externalForwardedProps: rest,
|
119 | additionalProps: {
|
120 | ref: forwardedRef
|
121 | },
|
122 | ownerState,
|
123 | className: [classes.root, className]
|
124 | });
|
125 | const Input = slots.input ?? 'input';
|
126 | const inputProps = useSlotProps({
|
127 | elementType: Input,
|
128 | getSlotProps: otherHandlers => getInputProps(_extends({}, propsForwardedToInputSlot, otherHandlers)),
|
129 | externalSlotProps: slotProps.input,
|
130 | ownerState,
|
131 | className: classes.input
|
132 | });
|
133 | const IncrementButton = slots.incrementButton ?? 'button';
|
134 | const incrementButtonProps = useSlotProps({
|
135 | elementType: IncrementButton,
|
136 | getSlotProps: getIncrementButtonProps,
|
137 | externalSlotProps: slotProps.incrementButton,
|
138 | ownerState,
|
139 | className: classes.incrementButton
|
140 | });
|
141 | const DecrementButton = slots.decrementButton ?? 'button';
|
142 | const decrementButtonProps = useSlotProps({
|
143 | elementType: DecrementButton,
|
144 | getSlotProps: getDecrementButtonProps,
|
145 | externalSlotProps: slotProps.decrementButton,
|
146 | ownerState,
|
147 | className: classes.decrementButton
|
148 | });
|
149 | return _jsxs(Root, _extends({}, rootProps, {
|
150 | children: [_jsx(DecrementButton, _extends({}, decrementButtonProps)), _jsx(IncrementButton, _extends({}, incrementButtonProps)), startAdornment, _jsx(Input, _extends({}, inputProps)), endAdornment]
|
151 | }));
|
152 | });
|
153 | process.env.NODE_ENV !== "production" ? NumberInput.propTypes = {
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | |
159 |
|
160 |
|
161 | children: PropTypes.node,
|
162 | |
163 |
|
164 |
|
165 | className: PropTypes.string,
|
166 | |
167 |
|
168 |
|
169 | defaultValue: PropTypes.number,
|
170 | |
171 |
|
172 |
|
173 |
|
174 | disabled: PropTypes.bool,
|
175 | |
176 |
|
177 |
|
178 | endAdornment: PropTypes.node,
|
179 | |
180 |
|
181 |
|
182 | error: PropTypes.bool,
|
183 | |
184 |
|
185 |
|
186 | id: PropTypes.string,
|
187 | |
188 |
|
189 |
|
190 | max: PropTypes.number,
|
191 | |
192 |
|
193 |
|
194 | min: PropTypes.number,
|
195 | |
196 |
|
197 |
|
198 | onBlur: PropTypes.func,
|
199 | |
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 | onChange: PropTypes.func,
|
208 | |
209 |
|
210 |
|
211 | onFocus: PropTypes.func,
|
212 | |
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | onInputChange: PropTypes.func,
|
220 | |
221 |
|
222 |
|
223 | placeholder: PropTypes.string,
|
224 | |
225 |
|
226 |
|
227 |
|
228 |
|
229 | readOnly: PropTypes.bool,
|
230 | |
231 |
|
232 |
|
233 |
|
234 | required: PropTypes.bool,
|
235 | |
236 |
|
237 |
|
238 |
|
239 | shiftMultiplier: PropTypes.number,
|
240 | |
241 |
|
242 |
|
243 |
|
244 | slotProps: PropTypes.shape({
|
245 | decrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
246 | incrementButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
247 | input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
248 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
249 | }),
|
250 | |
251 |
|
252 |
|
253 |
|
254 |
|
255 | slots: PropTypes.shape({
|
256 | decrementButton: PropTypes.elementType,
|
257 | incrementButton: PropTypes.elementType,
|
258 | input: PropTypes.elementType,
|
259 | root: PropTypes.elementType
|
260 | }),
|
261 | |
262 |
|
263 |
|
264 | startAdornment: PropTypes.node,
|
265 | |
266 |
|
267 |
|
268 | step: PropTypes.number,
|
269 | |
270 |
|
271 |
|
272 |
|
273 | value: PropTypes.number
|
274 | } : void 0;
|
275 | export { NumberInput }; |
\ | No newline at end of file |