@fluentui/react-spinbutton 9.2.14 → 9.2.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. package/CHANGELOG.json +79 -1
  2. package/CHANGELOG.md +28 -2
  3. package/lib/SpinButton.js +0 -1
  4. package/lib/SpinButton.js.map +1 -1
  5. package/lib/components/SpinButton/SpinButton.js +5 -7
  6. package/lib/components/SpinButton/SpinButton.js.map +1 -1
  7. package/lib/components/SpinButton/SpinButton.types.js +0 -1
  8. package/lib/components/SpinButton/SpinButton.types.js.map +1 -1
  9. package/lib/components/SpinButton/index.js +0 -1
  10. package/lib/components/SpinButton/index.js.map +1 -1
  11. package/lib/components/SpinButton/renderSpinButton.js +4 -9
  12. package/lib/components/SpinButton/renderSpinButton.js.map +1 -1
  13. package/lib/components/SpinButton/useSpinButton.js +239 -247
  14. package/lib/components/SpinButton/useSpinButton.js.map +1 -1
  15. package/lib/components/SpinButton/useSpinButtonStyles.styles.js.map +1 -1
  16. package/lib/index.js +0 -1
  17. package/lib/index.js.map +1 -1
  18. package/lib/utils/clamp.js +21 -17
  19. package/lib/utils/clamp.js.map +1 -1
  20. package/lib/utils/getBound.js +9 -10
  21. package/lib/utils/getBound.js.map +1 -1
  22. package/lib/utils/index.js +0 -1
  23. package/lib/utils/index.js.map +1 -1
  24. package/lib/utils/precision.js +19 -22
  25. package/lib/utils/precision.js.map +1 -1
  26. package/lib-commonjs/SpinButton.js +0 -3
  27. package/lib-commonjs/SpinButton.js.map +1 -1
  28. package/lib-commonjs/components/SpinButton/SpinButton.js +1 -3
  29. package/lib-commonjs/components/SpinButton/SpinButton.js.map +1 -1
  30. package/lib-commonjs/components/SpinButton/SpinButton.types.js +0 -3
  31. package/lib-commonjs/components/SpinButton/SpinButton.types.js.map +1 -1
  32. package/lib-commonjs/components/SpinButton/index.js +0 -3
  33. package/lib-commonjs/components/SpinButton/index.js.map +1 -1
  34. package/lib-commonjs/components/SpinButton/renderSpinButton.js +1 -3
  35. package/lib-commonjs/components/SpinButton/renderSpinButton.js.map +1 -1
  36. package/lib-commonjs/components/SpinButton/useSpinButton.js +1 -3
  37. package/lib-commonjs/components/SpinButton/useSpinButton.js.map +1 -1
  38. package/lib-commonjs/components/SpinButton/useSpinButtonStyles.styles.js +0 -2
  39. package/lib-commonjs/components/SpinButton/useSpinButtonStyles.styles.js.map +1 -1
  40. package/lib-commonjs/index.js +0 -3
  41. package/lib-commonjs/index.js.map +1 -1
  42. package/lib-commonjs/utils/clamp.js +1 -3
  43. package/lib-commonjs/utils/clamp.js.map +1 -1
  44. package/lib-commonjs/utils/getBound.js +1 -3
  45. package/lib-commonjs/utils/getBound.js.map +1 -1
  46. package/lib-commonjs/utils/index.js +0 -3
  47. package/lib-commonjs/utils/index.js.map +1 -1
  48. package/lib-commonjs/utils/precision.js +6 -8
  49. package/lib-commonjs/utils/precision.js.map +1 -1
  50. package/package.json +7 -7
@@ -11,7 +11,7 @@ const MAX_SPIN_TIME_MS = 1000;
11
11
  // This is here to give an ease for the mouse held down case.
12
12
  // Exact easing it to be defined. Once it is we'll likely
13
13
  // pull this out into a util function in the SpinButton package.
14
- const lerp = (start, end, percent) => start + (end - start) * percent;
14
+ const lerp = (start, end, percent)=>start + (end - start) * percent;
15
15
  /**
16
16
  * Create the state required to render SpinButton.
17
17
  *
@@ -20,254 +20,246 @@ const lerp = (start, end, percent) => start + (end - start) * percent;
20
20
  *
21
21
  * @param props - props from this instance of SpinButton
22
22
  * @param ref - reference to root HTMLElement of SpinButton
23
- */
24
- export const useSpinButton_unstable = (props, ref) => {
25
- // Merge props from surrounding <Field>, if any
26
- props = useFieldControlProps_unstable(props, {
27
- supportsLabelFor: true,
28
- supportsRequired: true
29
- });
30
- const nativeProps = getPartitionedNativeProps({
31
- props,
32
- primarySlotTagName: 'input',
33
- excludedPropNames: ['defaultValue', 'max', 'min', 'onChange', 'size', 'value']
34
- });
35
- const overrides = useOverrides();
36
- var _overrides_inputDefaultAppearance;
37
- const {
38
- value,
39
- displayValue,
40
- defaultValue,
41
- min,
42
- max,
43
- step = 1,
44
- stepPage = 1,
45
- precision: precisionFromProps,
46
- onChange,
47
- size = 'medium',
48
- appearance = (_overrides_inputDefaultAppearance = overrides.inputDefaultAppearance) !== null && _overrides_inputDefaultAppearance !== void 0 ? _overrides_inputDefaultAppearance : 'outline',
49
- root,
50
- input,
51
- incrementButton,
52
- decrementButton
53
- } = props;
54
- const precision = React.useMemo(() => {
55
- return precisionFromProps !== null && precisionFromProps !== void 0 ? precisionFromProps : Math.max(calculatePrecision(step), 0);
56
- }, [precisionFromProps, step]);
57
- const [currentValue, setCurrentValue] = useControllableState({
58
- state: value,
59
- defaultState: defaultValue,
60
- initialState: 0
61
- });
62
- const isControlled = value !== undefined;
63
- const [textValue, setTextValue] = React.useState(undefined);
64
- const [keyboardSpinState, setKeyboardSpinState] = React.useState('rest');
65
- const internalState = React.useRef({
66
- value: currentValue,
67
- spinState: 'rest',
68
- spinTime: 0,
69
- spinDelay: DEFAULT_SPIN_DELAY_MS,
70
- atBound: currentValue !== null ? getBound(precisionRound(currentValue, precision), min, max) : 'none'
71
- });
72
- const [setStepTimeout, clearStepTimeout] = useTimeout();
73
- const stepValue = (e, direction, startFrom) => {
74
- let startValue = internalState.current.value;
75
- if (startFrom) {
76
- const num = parseFloat(startFrom);
77
- if (!isNaN(num)) {
78
- startValue = num;
79
- }
80
- }
81
- const val = startValue;
82
- const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;
83
- const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;
84
- if (val === null) {
85
- const stepStart = min === undefined ? 0 : min;
86
- const nullStep = clamp(stepStart + stepSize * dir, min, max);
87
- commit(e, nullStep);
88
- return;
89
- }
90
- let newValue = val + stepSize * dir;
91
- if (!Number.isNaN(newValue)) {
92
- newValue = clamp(newValue, min, max);
93
- }
94
- commit(e, newValue);
95
- if (internalState.current.spinState !== 'rest') {
96
- setStepTimeout(() => {
97
- // Ease the step speed a bit
98
- internalState.current.spinTime += internalState.current.spinDelay;
99
- internalState.current.spinDelay = lerp(DEFAULT_SPIN_DELAY_MS, MIN_SPIN_DELAY_MS, internalState.current.spinTime / MAX_SPIN_TIME_MS);
100
- stepValue(e, direction);
101
- }, internalState.current.spinDelay);
102
- }
103
- };
104
- const handleInputChange = e => {
105
- if (!internalState.current.previousTextValue) {
106
- internalState.current.previousTextValue = textValue !== null && textValue !== void 0 ? textValue : String(currentValue);
107
- }
108
- const newValue = e.target.value;
109
- setTextValue(newValue);
110
- };
111
- const handleIncrementMouseDown = e => {
112
- internalState.current.spinState = 'up';
113
- stepValue(e, 'up');
114
- };
115
- const handleDecrementMouseDown = e => {
116
- internalState.current.spinState = 'down';
117
- stepValue(e, 'down');
118
- };
119
- const handleStepMouseUpOrLeave = e => {
120
- clearStepTimeout();
121
- internalState.current.spinState = 'rest';
122
- internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;
123
- internalState.current.spinTime = 0;
124
- };
125
- const handleBlur = e => {
126
- commit(e, currentValue, textValue);
127
- internalState.current.previousTextValue = undefined;
128
- };
129
- const handleKeyDown = e => {
130
- let nextKeyboardSpinState = 'rest';
131
- if (e.key === ArrowUp) {
132
- stepValue(e, 'up', textValue);
133
- nextKeyboardSpinState = 'up';
134
- } else if (e.key === ArrowDown) {
135
- stepValue(e, 'down', textValue);
136
- nextKeyboardSpinState = 'down';
137
- } else if (e.key === PageUp) {
138
- e.preventDefault();
139
- stepValue(e, 'upPage', textValue);
140
- nextKeyboardSpinState = 'up';
141
- } else if (e.key === PageDown) {
142
- e.preventDefault();
143
- stepValue(e, 'downPage', textValue);
144
- nextKeyboardSpinState = 'down';
145
- } else if (!e.shiftKey && e.key === Home && min !== undefined) {
146
- commit(e, min);
147
- nextKeyboardSpinState = 'down';
148
- } else if (!e.shiftKey && e.key === End && max !== undefined) {
149
- commit(e, max);
150
- nextKeyboardSpinState = 'up';
151
- } else if (e.key === Enter) {
152
- commit(e, currentValue, textValue);
153
- internalState.current.previousTextValue = undefined;
154
- } else if (e.key === Escape) {
155
- if (internalState.current.previousTextValue) {
156
- setTextValue(undefined);
23
+ */ export const useSpinButton_unstable = (props, ref)=>{
24
+ // Merge props from surrounding <Field>, if any
25
+ props = useFieldControlProps_unstable(props, {
26
+ supportsLabelFor: true,
27
+ supportsRequired: true
28
+ });
29
+ const nativeProps = getPartitionedNativeProps({
30
+ props,
31
+ primarySlotTagName: 'input',
32
+ excludedPropNames: [
33
+ 'defaultValue',
34
+ 'max',
35
+ 'min',
36
+ 'onChange',
37
+ 'size',
38
+ 'value'
39
+ ]
40
+ });
41
+ const overrides = useOverrides();
42
+ var _overrides_inputDefaultAppearance;
43
+ const { value , displayValue , defaultValue , min , max , step =1 , stepPage =1 , precision: precisionFromProps , onChange , size ='medium' , appearance =(_overrides_inputDefaultAppearance = overrides.inputDefaultAppearance) !== null && _overrides_inputDefaultAppearance !== void 0 ? _overrides_inputDefaultAppearance : 'outline' , root , input , incrementButton , decrementButton } = props;
44
+ const precision = React.useMemo(()=>{
45
+ return precisionFromProps !== null && precisionFromProps !== void 0 ? precisionFromProps : Math.max(calculatePrecision(step), 0);
46
+ }, [
47
+ precisionFromProps,
48
+ step
49
+ ]);
50
+ const [currentValue, setCurrentValue] = useControllableState({
51
+ state: value,
52
+ defaultState: defaultValue,
53
+ initialState: 0
54
+ });
55
+ const isControlled = value !== undefined;
56
+ const [textValue, setTextValue] = React.useState(undefined);
57
+ const [keyboardSpinState, setKeyboardSpinState] = React.useState('rest');
58
+ const internalState = React.useRef({
59
+ value: currentValue,
60
+ spinState: 'rest',
61
+ spinTime: 0,
62
+ spinDelay: DEFAULT_SPIN_DELAY_MS,
63
+ atBound: currentValue !== null ? getBound(precisionRound(currentValue, precision), min, max) : 'none'
64
+ });
65
+ const [setStepTimeout, clearStepTimeout] = useTimeout();
66
+ const stepValue = (e, direction, startFrom)=>{
67
+ let startValue = internalState.current.value;
68
+ if (startFrom) {
69
+ const num = parseFloat(startFrom);
70
+ if (!isNaN(num)) {
71
+ startValue = num;
72
+ }
73
+ }
74
+ const val = startValue;
75
+ const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;
76
+ const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;
77
+ if (val === null) {
78
+ const stepStart = min === undefined ? 0 : min;
79
+ const nullStep = clamp(stepStart + stepSize * dir, min, max);
80
+ commit(e, nullStep);
81
+ return;
82
+ }
83
+ let newValue = val + stepSize * dir;
84
+ if (!Number.isNaN(newValue)) {
85
+ newValue = clamp(newValue, min, max);
86
+ }
87
+ commit(e, newValue);
88
+ if (internalState.current.spinState !== 'rest') {
89
+ setStepTimeout(()=>{
90
+ // Ease the step speed a bit
91
+ internalState.current.spinTime += internalState.current.spinDelay;
92
+ internalState.current.spinDelay = lerp(DEFAULT_SPIN_DELAY_MS, MIN_SPIN_DELAY_MS, internalState.current.spinTime / MAX_SPIN_TIME_MS);
93
+ stepValue(e, direction);
94
+ }, internalState.current.spinDelay);
95
+ }
96
+ };
97
+ const handleInputChange = (e)=>{
98
+ if (!internalState.current.previousTextValue) {
99
+ internalState.current.previousTextValue = textValue !== null && textValue !== void 0 ? textValue : String(currentValue);
100
+ }
101
+ const newValue = e.target.value;
102
+ setTextValue(newValue);
103
+ };
104
+ const handleIncrementMouseDown = (e)=>{
105
+ internalState.current.spinState = 'up';
106
+ stepValue(e, 'up');
107
+ };
108
+ const handleDecrementMouseDown = (e)=>{
109
+ internalState.current.spinState = 'down';
110
+ stepValue(e, 'down');
111
+ };
112
+ const handleStepMouseUpOrLeave = (e)=>{
113
+ clearStepTimeout();
114
+ internalState.current.spinState = 'rest';
115
+ internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;
116
+ internalState.current.spinTime = 0;
117
+ };
118
+ const handleBlur = (e)=>{
119
+ commit(e, currentValue, textValue);
157
120
  internalState.current.previousTextValue = undefined;
158
- }
159
- }
160
- if (keyboardSpinState !== nextKeyboardSpinState) {
161
- setKeyboardSpinState(nextKeyboardSpinState);
162
- }
163
- };
164
- const handleKeyUp = e => {
165
- if (keyboardSpinState !== 'rest') {
166
- setKeyboardSpinState('rest');
167
- internalState.current.spinState = 'rest';
168
- }
169
- };
170
- const commit = (e, newValue, newDisplayValue) => {
171
- const valueChanged = newValue !== undefined && currentValue !== newValue;
172
- const displayValueChanged = newDisplayValue !== undefined && internalState.current.previousTextValue !== undefined && internalState.current.previousTextValue !== newDisplayValue;
173
- let roundedValue;
174
- if (valueChanged) {
175
- roundedValue = precisionRound(newValue, precision);
176
- setCurrentValue(roundedValue);
177
- } else if (displayValueChanged && !isControlled) {
178
- const nextValue = parseFloat(newDisplayValue);
179
- if (!isNaN(nextValue)) {
180
- setCurrentValue(precisionRound(nextValue, precision));
181
- }
182
- }
183
- if (valueChanged || displayValueChanged) {
184
- onChange === null || onChange === void 0 ? void 0 : onChange(e, {
185
- value: roundedValue,
186
- displayValue: newDisplayValue
187
- });
188
- }
189
- setTextValue(undefined);
190
- };
191
- const state = {
192
- size,
193
- appearance,
194
- spinState: keyboardSpinState,
195
- atBound: internalState.current.atBound,
196
- components: {
197
- root: 'span',
198
- input: 'input',
199
- incrementButton: 'button',
200
- decrementButton: 'button'
201
- },
202
- root: resolveShorthand(root, {
203
- required: true,
204
- defaultProps: nativeProps.root
205
- }),
206
- input: resolveShorthand(input, {
207
- required: true,
208
- defaultProps: {
209
- ref,
210
- autoComplete: 'off',
211
- role: 'spinbutton',
121
+ };
122
+ const handleKeyDown = (e)=>{
123
+ let nextKeyboardSpinState = 'rest';
124
+ if (e.key === ArrowUp) {
125
+ stepValue(e, 'up', textValue);
126
+ nextKeyboardSpinState = 'up';
127
+ } else if (e.key === ArrowDown) {
128
+ stepValue(e, 'down', textValue);
129
+ nextKeyboardSpinState = 'down';
130
+ } else if (e.key === PageUp) {
131
+ e.preventDefault();
132
+ stepValue(e, 'upPage', textValue);
133
+ nextKeyboardSpinState = 'up';
134
+ } else if (e.key === PageDown) {
135
+ e.preventDefault();
136
+ stepValue(e, 'downPage', textValue);
137
+ nextKeyboardSpinState = 'down';
138
+ } else if (!e.shiftKey && e.key === Home && min !== undefined) {
139
+ commit(e, min);
140
+ nextKeyboardSpinState = 'down';
141
+ } else if (!e.shiftKey && e.key === End && max !== undefined) {
142
+ commit(e, max);
143
+ nextKeyboardSpinState = 'up';
144
+ } else if (e.key === Enter) {
145
+ commit(e, currentValue, textValue);
146
+ internalState.current.previousTextValue = undefined;
147
+ } else if (e.key === Escape) {
148
+ if (internalState.current.previousTextValue) {
149
+ setTextValue(undefined);
150
+ internalState.current.previousTextValue = undefined;
151
+ }
152
+ }
153
+ if (keyboardSpinState !== nextKeyboardSpinState) {
154
+ setKeyboardSpinState(nextKeyboardSpinState);
155
+ }
156
+ };
157
+ const handleKeyUp = (e)=>{
158
+ if (keyboardSpinState !== 'rest') {
159
+ setKeyboardSpinState('rest');
160
+ internalState.current.spinState = 'rest';
161
+ }
162
+ };
163
+ const commit = (e, newValue, newDisplayValue)=>{
164
+ const valueChanged = newValue !== undefined && currentValue !== newValue;
165
+ const displayValueChanged = newDisplayValue !== undefined && internalState.current.previousTextValue !== undefined && internalState.current.previousTextValue !== newDisplayValue;
166
+ let roundedValue;
167
+ if (valueChanged) {
168
+ roundedValue = precisionRound(newValue, precision);
169
+ setCurrentValue(roundedValue);
170
+ } else if (displayValueChanged && !isControlled) {
171
+ const nextValue = parseFloat(newDisplayValue);
172
+ if (!isNaN(nextValue)) {
173
+ setCurrentValue(precisionRound(nextValue, precision));
174
+ }
175
+ }
176
+ if (valueChanged || displayValueChanged) {
177
+ onChange === null || onChange === void 0 ? void 0 : onChange(e, {
178
+ value: roundedValue,
179
+ displayValue: newDisplayValue
180
+ });
181
+ }
182
+ setTextValue(undefined);
183
+ };
184
+ const state = {
185
+ size,
212
186
  appearance,
213
- type: 'text',
214
- ...nativeProps.primary
215
- }
216
- }),
217
- incrementButton: resolveShorthand(incrementButton, {
218
- required: true,
219
- defaultProps: {
220
- tabIndex: -1,
221
- children: /*#__PURE__*/React.createElement(ChevronUp16Regular, null),
222
- disabled: nativeProps.primary.disabled,
223
- 'aria-label': 'Increment value',
224
- type: 'button'
225
- }
226
- }),
227
- decrementButton: resolveShorthand(decrementButton, {
228
- required: true,
229
- defaultProps: {
230
- tabIndex: -1,
231
- children: /*#__PURE__*/React.createElement(ChevronDown16Regular, null),
232
- disabled: nativeProps.primary.disabled,
233
- 'aria-label': 'Decrement value',
234
- type: 'button'
235
- }
236
- })
237
- };
238
- let valueToDisplay;
239
- if (textValue !== undefined) {
240
- valueToDisplay = textValue;
241
- } else if (value === null || currentValue === null) {
242
- valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : '';
243
- internalState.current.value = null;
244
- internalState.current.atBound = 'none';
245
- } else {
246
- const roundedValue = precisionRound(currentValue, precision);
247
- internalState.current.value = roundedValue;
248
- internalState.current.atBound = getBound(roundedValue, min, max);
249
- if (isControlled) {
250
- valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : String(roundedValue);
187
+ spinState: keyboardSpinState,
188
+ atBound: internalState.current.atBound,
189
+ components: {
190
+ root: 'span',
191
+ input: 'input',
192
+ incrementButton: 'button',
193
+ decrementButton: 'button'
194
+ },
195
+ root: resolveShorthand(root, {
196
+ required: true,
197
+ defaultProps: nativeProps.root
198
+ }),
199
+ input: resolveShorthand(input, {
200
+ required: true,
201
+ defaultProps: {
202
+ ref,
203
+ autoComplete: 'off',
204
+ role: 'spinbutton',
205
+ appearance,
206
+ type: 'text',
207
+ ...nativeProps.primary
208
+ }
209
+ }),
210
+ incrementButton: resolveShorthand(incrementButton, {
211
+ required: true,
212
+ defaultProps: {
213
+ tabIndex: -1,
214
+ children: /*#__PURE__*/ React.createElement(ChevronUp16Regular, null),
215
+ disabled: nativeProps.primary.disabled,
216
+ 'aria-label': 'Increment value',
217
+ type: 'button'
218
+ }
219
+ }),
220
+ decrementButton: resolveShorthand(decrementButton, {
221
+ required: true,
222
+ defaultProps: {
223
+ tabIndex: -1,
224
+ children: /*#__PURE__*/ React.createElement(ChevronDown16Regular, null),
225
+ disabled: nativeProps.primary.disabled,
226
+ 'aria-label': 'Decrement value',
227
+ type: 'button'
228
+ }
229
+ })
230
+ };
231
+ let valueToDisplay;
232
+ if (textValue !== undefined) {
233
+ valueToDisplay = textValue;
234
+ } else if (value === null || currentValue === null) {
235
+ valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : '';
236
+ internalState.current.value = null;
237
+ internalState.current.atBound = 'none';
251
238
  } else {
252
- valueToDisplay = String(roundedValue);
239
+ const roundedValue = precisionRound(currentValue, precision);
240
+ internalState.current.value = roundedValue;
241
+ internalState.current.atBound = getBound(roundedValue, min, max);
242
+ if (isControlled) {
243
+ valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : String(roundedValue);
244
+ } else {
245
+ valueToDisplay = String(roundedValue);
246
+ }
253
247
  }
254
- }
255
- state.input.value = valueToDisplay;
256
- state.input['aria-valuemin'] = min;
257
- state.input['aria-valuemax'] = max;
258
- state.input['aria-valuenow'] = currentValue !== null && currentValue !== void 0 ? currentValue : undefined;
259
- var _state_input_ariavaluetext;
260
- state.input['aria-valuetext'] = (_state_input_ariavaluetext = state.input['aria-valuetext']) !== null && _state_input_ariavaluetext !== void 0 ? _state_input_ariavaluetext : value !== undefined && displayValue || undefined;
261
- state.input.onChange = mergeCallbacks(state.input.onChange, handleInputChange);
262
- state.input.onBlur = mergeCallbacks(state.input.onBlur, handleBlur);
263
- state.input.onKeyDown = mergeCallbacks(state.input.onKeyDown, handleKeyDown);
264
- state.input.onKeyUp = mergeCallbacks(state.input.onKeyUp, handleKeyUp);
265
- state.incrementButton.onMouseDown = mergeCallbacks(handleIncrementMouseDown, state.incrementButton.onMouseDown);
266
- state.incrementButton.onMouseUp = mergeCallbacks(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);
267
- state.incrementButton.onMouseLeave = mergeCallbacks(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);
268
- state.decrementButton.onMouseDown = mergeCallbacks(handleDecrementMouseDown, state.decrementButton.onMouseDown);
269
- state.decrementButton.onMouseUp = mergeCallbacks(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);
270
- state.decrementButton.onMouseLeave = mergeCallbacks(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);
271
- return state;
248
+ state.input.value = valueToDisplay;
249
+ state.input['aria-valuemin'] = min;
250
+ state.input['aria-valuemax'] = max;
251
+ state.input['aria-valuenow'] = currentValue !== null && currentValue !== void 0 ? currentValue : undefined;
252
+ var _state_input_ariavaluetext;
253
+ state.input['aria-valuetext'] = (_state_input_ariavaluetext = state.input['aria-valuetext']) !== null && _state_input_ariavaluetext !== void 0 ? _state_input_ariavaluetext : value !== undefined && displayValue || undefined;
254
+ state.input.onChange = mergeCallbacks(state.input.onChange, handleInputChange);
255
+ state.input.onBlur = mergeCallbacks(state.input.onBlur, handleBlur);
256
+ state.input.onKeyDown = mergeCallbacks(state.input.onKeyDown, handleKeyDown);
257
+ state.input.onKeyUp = mergeCallbacks(state.input.onKeyUp, handleKeyUp);
258
+ state.incrementButton.onMouseDown = mergeCallbacks(handleIncrementMouseDown, state.incrementButton.onMouseDown);
259
+ state.incrementButton.onMouseUp = mergeCallbacks(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);
260
+ state.incrementButton.onMouseLeave = mergeCallbacks(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);
261
+ state.decrementButton.onMouseDown = mergeCallbacks(handleDecrementMouseDown, state.decrementButton.onMouseDown);
262
+ state.decrementButton.onMouseUp = mergeCallbacks(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);
263
+ state.decrementButton.onMouseLeave = mergeCallbacks(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);
264
+ return state;
272
265
  };
273
- //# sourceMappingURL=useSpinButton.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","useFieldControlProps_unstable","getPartitionedNativeProps","mergeCallbacks","resolveShorthand","useControllableState","useTimeout","ArrowUp","ArrowDown","End","Enter","Escape","Home","PageDown","PageUp","calculatePrecision","precisionRound","getBound","clamp","ChevronUp16Regular","ChevronDown16Regular","useOverrides_unstable","useOverrides","DEFAULT_SPIN_DELAY_MS","MIN_SPIN_DELAY_MS","MAX_SPIN_TIME_MS","lerp","start","end","percent","useSpinButton_unstable","props","ref","supportsLabelFor","supportsRequired","nativeProps","primarySlotTagName","excludedPropNames","overrides","_overrides_inputDefaultAppearance","value","displayValue","defaultValue","min","max","step","stepPage","precision","precisionFromProps","onChange","size","appearance","inputDefaultAppearance","root","input","incrementButton","decrementButton","useMemo","Math","currentValue","setCurrentValue","state","defaultState","initialState","isControlled","undefined","textValue","setTextValue","useState","keyboardSpinState","setKeyboardSpinState","internalState","useRef","spinState","spinTime","spinDelay","atBound","setStepTimeout","clearStepTimeout","stepValue","e","direction","startFrom","startValue","current","num","parseFloat","isNaN","val","dir","stepSize","stepStart","nullStep","commit","newValue","Number","handleInputChange","previousTextValue","String","target","handleIncrementMouseDown","handleDecrementMouseDown","handleStepMouseUpOrLeave","handleBlur","handleKeyDown","nextKeyboardSpinState","key","preventDefault","shiftKey","handleKeyUp","newDisplayValue","valueChanged","displayValueChanged","roundedValue","nextValue","components","required","defaultProps","autoComplete","role","type","primary","tabIndex","children","createElement","disabled","valueToDisplay","_state_input_ariavaluetext","onBlur","onKeyDown","onKeyUp","onMouseDown","onMouseUp","onMouseLeave"],"sources":["../../../src/components/SpinButton/useSpinButton.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n resolveShorthand,\n useControllableState,\n useTimeout,\n} from '@fluentui/react-utilities';\nimport { ArrowUp, ArrowDown, End, Enter, Escape, Home, PageDown, PageUp } from '@fluentui/keyboard-keys';\nimport {\n SpinButtonProps,\n SpinButtonState,\n SpinButtonSpinState,\n SpinButtonChangeEvent,\n SpinButtonBounds,\n} from './SpinButton.types';\nimport { calculatePrecision, precisionRound, getBound, clamp } from '../../utils/index';\nimport { ChevronUp16Regular, ChevronDown16Regular } from '@fluentui/react-icons';\nimport { useOverrides_unstable as useOverrides } from '@fluentui/react-shared-contexts';\n\ntype InternalState = {\n value: number | null;\n spinState: SpinButtonSpinState;\n spinTime: number;\n spinDelay: number;\n previousTextValue?: string;\n atBound: SpinButtonBounds;\n};\n\nconst DEFAULT_SPIN_DELAY_MS = 150;\nconst MIN_SPIN_DELAY_MS = 80;\nconst MAX_SPIN_TIME_MS = 1000;\n\n// This is here to give an ease for the mouse held down case.\n// Exact easing it to be defined. Once it is we'll likely\n// pull this out into a util function in the SpinButton package.\nconst lerp = (start: number, end: number, percent: number): number => start + (end - start) * percent;\n\n/**\n * Create the state required to render SpinButton.\n *\n * The returned state can be modified with hooks such as useSpinButtonStyles_unstable,\n * before being passed to renderSpinButton_unstable.\n *\n * @param props - props from this instance of SpinButton\n * @param ref - reference to root HTMLElement of SpinButton\n */\nexport const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HTMLInputElement>): SpinButtonState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['defaultValue', 'max', 'min', 'onChange', 'size', 'value'],\n });\n\n const overrides = useOverrides();\n\n const {\n value,\n displayValue,\n defaultValue,\n min,\n max,\n step = 1,\n stepPage = 1,\n precision: precisionFromProps,\n onChange,\n size = 'medium',\n appearance = overrides.inputDefaultAppearance ?? 'outline',\n root,\n input,\n incrementButton,\n decrementButton,\n } = props;\n\n const precision = React.useMemo(() => {\n return precisionFromProps ?? Math.max(calculatePrecision(step), 0);\n }, [precisionFromProps, step]);\n\n const [currentValue, setCurrentValue] = useControllableState({\n state: value,\n defaultState: defaultValue,\n initialState: 0,\n });\n\n const isControlled = value !== undefined;\n\n const [textValue, setTextValue] = React.useState<string | undefined>(undefined);\n const [keyboardSpinState, setKeyboardSpinState] = React.useState<SpinButtonSpinState>('rest');\n\n const internalState = React.useRef<InternalState>({\n value: currentValue,\n spinState: 'rest',\n spinTime: 0,\n spinDelay: DEFAULT_SPIN_DELAY_MS,\n atBound: currentValue !== null ? getBound(precisionRound(currentValue, precision), min, max) : 'none',\n });\n\n const [setStepTimeout, clearStepTimeout] = useTimeout();\n\n const stepValue = (\n e: SpinButtonChangeEvent,\n direction: 'up' | 'down' | 'upPage' | 'downPage',\n startFrom?: string,\n ) => {\n let startValue = internalState.current.value;\n if (startFrom) {\n const num = parseFloat(startFrom);\n if (!isNaN(num)) {\n startValue = num;\n }\n }\n const val = startValue;\n const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;\n const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;\n\n if (val === null) {\n const stepStart = min === undefined ? 0 : min;\n const nullStep = clamp(stepStart + stepSize * dir, min, max);\n commit(e, nullStep);\n return;\n }\n\n let newValue = val + stepSize * dir;\n if (!Number.isNaN(newValue)) {\n newValue = clamp(newValue, min, max);\n }\n\n commit(e, newValue);\n\n if (internalState.current.spinState !== 'rest') {\n setStepTimeout(() => {\n // Ease the step speed a bit\n internalState.current.spinTime += internalState.current.spinDelay;\n internalState.current.spinDelay = lerp(\n DEFAULT_SPIN_DELAY_MS,\n MIN_SPIN_DELAY_MS,\n internalState.current.spinTime / MAX_SPIN_TIME_MS,\n );\n stepValue(e, direction);\n }, internalState.current.spinDelay);\n }\n };\n\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!internalState.current.previousTextValue) {\n internalState.current.previousTextValue = textValue ?? String(currentValue);\n }\n const newValue = e.target.value;\n setTextValue(newValue);\n };\n\n const handleIncrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n internalState.current.spinState = 'up';\n stepValue(e, 'up');\n };\n\n const handleDecrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n internalState.current.spinState = 'down';\n stepValue(e, 'down');\n };\n\n const handleStepMouseUpOrLeave = (e: React.MouseEvent<HTMLButtonElement>) => {\n clearStepTimeout();\n internalState.current.spinState = 'rest';\n internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;\n internalState.current.spinTime = 0;\n };\n\n const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {\n commit(e, currentValue, textValue);\n internalState.current.previousTextValue = undefined;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n let nextKeyboardSpinState: SpinButtonSpinState = 'rest';\n\n if (e.key === ArrowUp) {\n stepValue(e, 'up', textValue);\n nextKeyboardSpinState = 'up';\n } else if (e.key === ArrowDown) {\n stepValue(e, 'down', textValue);\n nextKeyboardSpinState = 'down';\n } else if (e.key === PageUp) {\n e.preventDefault();\n stepValue(e, 'upPage', textValue);\n nextKeyboardSpinState = 'up';\n } else if (e.key === PageDown) {\n e.preventDefault();\n stepValue(e, 'downPage', textValue);\n nextKeyboardSpinState = 'down';\n } else if (!e.shiftKey && e.key === Home && min !== undefined) {\n commit(e, min);\n nextKeyboardSpinState = 'down';\n } else if (!e.shiftKey && e.key === End && max !== undefined) {\n commit(e, max);\n nextKeyboardSpinState = 'up';\n } else if (e.key === Enter) {\n commit(e, currentValue, textValue);\n internalState.current.previousTextValue = undefined;\n } else if (e.key === Escape) {\n if (internalState.current.previousTextValue) {\n setTextValue(undefined);\n internalState.current.previousTextValue = undefined;\n }\n }\n\n if (keyboardSpinState !== nextKeyboardSpinState) {\n setKeyboardSpinState(nextKeyboardSpinState);\n }\n };\n\n const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (keyboardSpinState !== 'rest') {\n setKeyboardSpinState('rest');\n internalState.current.spinState = 'rest';\n }\n };\n\n const commit = (e: SpinButtonChangeEvent, newValue?: number | null, newDisplayValue?: string) => {\n const valueChanged = newValue !== undefined && currentValue !== newValue;\n const displayValueChanged =\n newDisplayValue !== undefined &&\n internalState.current.previousTextValue !== undefined &&\n internalState.current.previousTextValue !== newDisplayValue;\n\n let roundedValue;\n if (valueChanged) {\n roundedValue = precisionRound(newValue!, precision);\n setCurrentValue(roundedValue);\n } else if (displayValueChanged && !isControlled) {\n const nextValue = parseFloat(newDisplayValue as string);\n if (!isNaN(nextValue)) {\n setCurrentValue(precisionRound(nextValue, precision));\n }\n }\n\n if (valueChanged || displayValueChanged) {\n onChange?.(e, { value: roundedValue, displayValue: newDisplayValue });\n }\n\n setTextValue(undefined);\n };\n\n const state: SpinButtonState = {\n size,\n appearance,\n spinState: keyboardSpinState,\n atBound: internalState.current.atBound,\n\n components: {\n root: 'span',\n input: 'input',\n incrementButton: 'button',\n decrementButton: 'button',\n },\n root: resolveShorthand(root, {\n required: true,\n defaultProps: nativeProps.root,\n }),\n input: resolveShorthand(input, {\n required: true,\n defaultProps: {\n ref,\n autoComplete: 'off',\n role: 'spinbutton',\n appearance,\n type: 'text',\n ...nativeProps.primary,\n },\n }),\n incrementButton: resolveShorthand(incrementButton, {\n required: true,\n defaultProps: {\n tabIndex: -1,\n children: <ChevronUp16Regular />,\n disabled: nativeProps.primary.disabled,\n 'aria-label': 'Increment value',\n type: 'button',\n },\n }),\n decrementButton: resolveShorthand(decrementButton, {\n required: true,\n defaultProps: {\n tabIndex: -1,\n children: <ChevronDown16Regular />,\n disabled: nativeProps.primary.disabled,\n 'aria-label': 'Decrement value',\n type: 'button',\n },\n }),\n };\n\n let valueToDisplay;\n if (textValue !== undefined) {\n valueToDisplay = textValue;\n } else if (value === null || currentValue === null) {\n valueToDisplay = displayValue ?? '';\n internalState.current.value = null;\n internalState.current.atBound = 'none';\n } else {\n const roundedValue = precisionRound(currentValue, precision);\n internalState.current.value = roundedValue;\n internalState.current.atBound = getBound(roundedValue, min, max);\n if (isControlled) {\n valueToDisplay = displayValue ?? String(roundedValue);\n } else {\n valueToDisplay = String(roundedValue);\n }\n }\n\n state.input.value = valueToDisplay;\n state.input['aria-valuemin'] = min;\n state.input['aria-valuemax'] = max;\n state.input['aria-valuenow'] = currentValue ?? undefined;\n state.input['aria-valuetext'] = state.input['aria-valuetext'] ?? ((value !== undefined && displayValue) || undefined);\n state.input.onChange = mergeCallbacks(state.input.onChange, handleInputChange);\n state.input.onBlur = mergeCallbacks(state.input.onBlur, handleBlur);\n state.input.onKeyDown = mergeCallbacks(state.input.onKeyDown, handleKeyDown);\n state.input.onKeyUp = mergeCallbacks(state.input.onKeyUp, handleKeyUp);\n\n state.incrementButton.onMouseDown = mergeCallbacks(handleIncrementMouseDown, state.incrementButton.onMouseDown);\n state.incrementButton.onMouseUp = mergeCallbacks(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);\n state.incrementButton.onMouseLeave = mergeCallbacks(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n state.decrementButton.onMouseDown = mergeCallbacks(handleDecrementMouseDown, state.decrementButton.onMouseDown);\n state.decrementButton.onMouseUp = mergeCallbacks(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);\n state.decrementButton.onMouseLeave = mergeCallbacks(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,6BAA6B,QAAQ;AAC9C,SACEC,yBAAyB,EACzBC,cAAc,EACdC,gBAAgB,EAChBC,oBAAoB,EACpBC,UAAU,QACL;AACP,SAASC,OAAO,EAAEC,SAAS,EAAEC,GAAG,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,MAAM,QAAQ;AAQ/E,SAASC,kBAAkB,EAAEC,cAAc,EAAEC,QAAQ,EAAEC,KAAK,QAAQ;AACpE,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ;AACzD,SAASC,qBAAA,IAAyBC,YAAY,QAAQ;AAWtD,MAAMC,qBAAA,GAAwB;AAC9B,MAAMC,iBAAA,GAAoB;AAC1B,MAAMC,gBAAA,GAAmB;AAEzB;AACA;AACA;AACA,MAAMC,IAAA,GAAOA,CAACC,KAAA,EAAeC,GAAA,EAAaC,OAAA,KAA4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jI,cAAA,CAAe0D,KAAA,CAAML,eAAe,CAAC4E,SAAS,EAAE9B,wBAAA;EAClFzC,KAAA,CAAML,eAAe,CAAC6E,YAAY,GAAGlI,cAAA,CAAe0D,KAAA,CAAML,eAAe,CAAC6E,YAAY,EAAE/B,wBAAA;EAExF,OAAOzC,KAAA;AACT"}
1
+ {"version":3,"sources":["useSpinButton.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useFieldControlProps_unstable } from '@fluentui/react-field';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n resolveShorthand,\n useControllableState,\n useTimeout,\n} from '@fluentui/react-utilities';\nimport { ArrowUp, ArrowDown, End, Enter, Escape, Home, PageDown, PageUp } from '@fluentui/keyboard-keys';\nimport {\n SpinButtonProps,\n SpinButtonState,\n SpinButtonSpinState,\n SpinButtonChangeEvent,\n SpinButtonBounds,\n} from './SpinButton.types';\nimport { calculatePrecision, precisionRound, getBound, clamp } from '../../utils/index';\nimport { ChevronUp16Regular, ChevronDown16Regular } from '@fluentui/react-icons';\nimport { useOverrides_unstable as useOverrides } from '@fluentui/react-shared-contexts';\n\ntype InternalState = {\n value: number | null;\n spinState: SpinButtonSpinState;\n spinTime: number;\n spinDelay: number;\n previousTextValue?: string;\n atBound: SpinButtonBounds;\n};\n\nconst DEFAULT_SPIN_DELAY_MS = 150;\nconst MIN_SPIN_DELAY_MS = 80;\nconst MAX_SPIN_TIME_MS = 1000;\n\n// This is here to give an ease for the mouse held down case.\n// Exact easing it to be defined. Once it is we'll likely\n// pull this out into a util function in the SpinButton package.\nconst lerp = (start: number, end: number, percent: number): number => start + (end - start) * percent;\n\n/**\n * Create the state required to render SpinButton.\n *\n * The returned state can be modified with hooks such as useSpinButtonStyles_unstable,\n * before being passed to renderSpinButton_unstable.\n *\n * @param props - props from this instance of SpinButton\n * @param ref - reference to root HTMLElement of SpinButton\n */\nexport const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HTMLInputElement>): SpinButtonState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n\n const nativeProps = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['defaultValue', 'max', 'min', 'onChange', 'size', 'value'],\n });\n\n const overrides = useOverrides();\n\n const {\n value,\n displayValue,\n defaultValue,\n min,\n max,\n step = 1,\n stepPage = 1,\n precision: precisionFromProps,\n onChange,\n size = 'medium',\n appearance = overrides.inputDefaultAppearance ?? 'outline',\n root,\n input,\n incrementButton,\n decrementButton,\n } = props;\n\n const precision = React.useMemo(() => {\n return precisionFromProps ?? Math.max(calculatePrecision(step), 0);\n }, [precisionFromProps, step]);\n\n const [currentValue, setCurrentValue] = useControllableState({\n state: value,\n defaultState: defaultValue,\n initialState: 0,\n });\n\n const isControlled = value !== undefined;\n\n const [textValue, setTextValue] = React.useState<string | undefined>(undefined);\n const [keyboardSpinState, setKeyboardSpinState] = React.useState<SpinButtonSpinState>('rest');\n\n const internalState = React.useRef<InternalState>({\n value: currentValue,\n spinState: 'rest',\n spinTime: 0,\n spinDelay: DEFAULT_SPIN_DELAY_MS,\n atBound: currentValue !== null ? getBound(precisionRound(currentValue, precision), min, max) : 'none',\n });\n\n const [setStepTimeout, clearStepTimeout] = useTimeout();\n\n const stepValue = (\n e: SpinButtonChangeEvent,\n direction: 'up' | 'down' | 'upPage' | 'downPage',\n startFrom?: string,\n ) => {\n let startValue = internalState.current.value;\n if (startFrom) {\n const num = parseFloat(startFrom);\n if (!isNaN(num)) {\n startValue = num;\n }\n }\n const val = startValue;\n const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;\n const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;\n\n if (val === null) {\n const stepStart = min === undefined ? 0 : min;\n const nullStep = clamp(stepStart + stepSize * dir, min, max);\n commit(e, nullStep);\n return;\n }\n\n let newValue = val + stepSize * dir;\n if (!Number.isNaN(newValue)) {\n newValue = clamp(newValue, min, max);\n }\n\n commit(e, newValue);\n\n if (internalState.current.spinState !== 'rest') {\n setStepTimeout(() => {\n // Ease the step speed a bit\n internalState.current.spinTime += internalState.current.spinDelay;\n internalState.current.spinDelay = lerp(\n DEFAULT_SPIN_DELAY_MS,\n MIN_SPIN_DELAY_MS,\n internalState.current.spinTime / MAX_SPIN_TIME_MS,\n );\n stepValue(e, direction);\n }, internalState.current.spinDelay);\n }\n };\n\n const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n if (!internalState.current.previousTextValue) {\n internalState.current.previousTextValue = textValue ?? String(currentValue);\n }\n const newValue = e.target.value;\n setTextValue(newValue);\n };\n\n const handleIncrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n internalState.current.spinState = 'up';\n stepValue(e, 'up');\n };\n\n const handleDecrementMouseDown = (e: React.MouseEvent<HTMLButtonElement>) => {\n internalState.current.spinState = 'down';\n stepValue(e, 'down');\n };\n\n const handleStepMouseUpOrLeave = (e: React.MouseEvent<HTMLButtonElement>) => {\n clearStepTimeout();\n internalState.current.spinState = 'rest';\n internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;\n internalState.current.spinTime = 0;\n };\n\n const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {\n commit(e, currentValue, textValue);\n internalState.current.previousTextValue = undefined;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n let nextKeyboardSpinState: SpinButtonSpinState = 'rest';\n\n if (e.key === ArrowUp) {\n stepValue(e, 'up', textValue);\n nextKeyboardSpinState = 'up';\n } else if (e.key === ArrowDown) {\n stepValue(e, 'down', textValue);\n nextKeyboardSpinState = 'down';\n } else if (e.key === PageUp) {\n e.preventDefault();\n stepValue(e, 'upPage', textValue);\n nextKeyboardSpinState = 'up';\n } else if (e.key === PageDown) {\n e.preventDefault();\n stepValue(e, 'downPage', textValue);\n nextKeyboardSpinState = 'down';\n } else if (!e.shiftKey && e.key === Home && min !== undefined) {\n commit(e, min);\n nextKeyboardSpinState = 'down';\n } else if (!e.shiftKey && e.key === End && max !== undefined) {\n commit(e, max);\n nextKeyboardSpinState = 'up';\n } else if (e.key === Enter) {\n commit(e, currentValue, textValue);\n internalState.current.previousTextValue = undefined;\n } else if (e.key === Escape) {\n if (internalState.current.previousTextValue) {\n setTextValue(undefined);\n internalState.current.previousTextValue = undefined;\n }\n }\n\n if (keyboardSpinState !== nextKeyboardSpinState) {\n setKeyboardSpinState(nextKeyboardSpinState);\n }\n };\n\n const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (keyboardSpinState !== 'rest') {\n setKeyboardSpinState('rest');\n internalState.current.spinState = 'rest';\n }\n };\n\n const commit = (e: SpinButtonChangeEvent, newValue?: number | null, newDisplayValue?: string) => {\n const valueChanged = newValue !== undefined && currentValue !== newValue;\n const displayValueChanged =\n newDisplayValue !== undefined &&\n internalState.current.previousTextValue !== undefined &&\n internalState.current.previousTextValue !== newDisplayValue;\n\n let roundedValue;\n if (valueChanged) {\n roundedValue = precisionRound(newValue!, precision);\n setCurrentValue(roundedValue);\n } else if (displayValueChanged && !isControlled) {\n const nextValue = parseFloat(newDisplayValue as string);\n if (!isNaN(nextValue)) {\n setCurrentValue(precisionRound(nextValue, precision));\n }\n }\n\n if (valueChanged || displayValueChanged) {\n onChange?.(e, { value: roundedValue, displayValue: newDisplayValue });\n }\n\n setTextValue(undefined);\n };\n\n const state: SpinButtonState = {\n size,\n appearance,\n spinState: keyboardSpinState,\n atBound: internalState.current.atBound,\n\n components: {\n root: 'span',\n input: 'input',\n incrementButton: 'button',\n decrementButton: 'button',\n },\n root: resolveShorthand(root, {\n required: true,\n defaultProps: nativeProps.root,\n }),\n input: resolveShorthand(input, {\n required: true,\n defaultProps: {\n ref,\n autoComplete: 'off',\n role: 'spinbutton',\n appearance,\n type: 'text',\n ...nativeProps.primary,\n },\n }),\n incrementButton: resolveShorthand(incrementButton, {\n required: true,\n defaultProps: {\n tabIndex: -1,\n children: <ChevronUp16Regular />,\n disabled: nativeProps.primary.disabled,\n 'aria-label': 'Increment value',\n type: 'button',\n },\n }),\n decrementButton: resolveShorthand(decrementButton, {\n required: true,\n defaultProps: {\n tabIndex: -1,\n children: <ChevronDown16Regular />,\n disabled: nativeProps.primary.disabled,\n 'aria-label': 'Decrement value',\n type: 'button',\n },\n }),\n };\n\n let valueToDisplay;\n if (textValue !== undefined) {\n valueToDisplay = textValue;\n } else if (value === null || currentValue === null) {\n valueToDisplay = displayValue ?? '';\n internalState.current.value = null;\n internalState.current.atBound = 'none';\n } else {\n const roundedValue = precisionRound(currentValue, precision);\n internalState.current.value = roundedValue;\n internalState.current.atBound = getBound(roundedValue, min, max);\n if (isControlled) {\n valueToDisplay = displayValue ?? String(roundedValue);\n } else {\n valueToDisplay = String(roundedValue);\n }\n }\n\n state.input.value = valueToDisplay;\n state.input['aria-valuemin'] = min;\n state.input['aria-valuemax'] = max;\n state.input['aria-valuenow'] = currentValue ?? undefined;\n state.input['aria-valuetext'] = state.input['aria-valuetext'] ?? ((value !== undefined && displayValue) || undefined);\n state.input.onChange = mergeCallbacks(state.input.onChange, handleInputChange);\n state.input.onBlur = mergeCallbacks(state.input.onBlur, handleBlur);\n state.input.onKeyDown = mergeCallbacks(state.input.onKeyDown, handleKeyDown);\n state.input.onKeyUp = mergeCallbacks(state.input.onKeyUp, handleKeyUp);\n\n state.incrementButton.onMouseDown = mergeCallbacks(handleIncrementMouseDown, state.incrementButton.onMouseDown);\n state.incrementButton.onMouseUp = mergeCallbacks(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);\n state.incrementButton.onMouseLeave = mergeCallbacks(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n state.decrementButton.onMouseDown = mergeCallbacks(handleDecrementMouseDown, state.decrementButton.onMouseDown);\n state.decrementButton.onMouseUp = mergeCallbacks(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);\n state.decrementButton.onMouseLeave = mergeCallbacks(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);\n\n return state;\n};\n"],"names":["React","useFieldControlProps_unstable","getPartitionedNativeProps","mergeCallbacks","resolveShorthand","useControllableState","useTimeout","ArrowUp","ArrowDown","End","Enter","Escape","Home","PageDown","PageUp","calculatePrecision","precisionRound","getBound","clamp","ChevronUp16Regular","ChevronDown16Regular","useOverrides_unstable","useOverrides","DEFAULT_SPIN_DELAY_MS","MIN_SPIN_DELAY_MS","MAX_SPIN_TIME_MS","lerp","start","end","percent","useSpinButton_unstable","props","ref","supportsLabelFor","supportsRequired","nativeProps","primarySlotTagName","excludedPropNames","overrides","value","displayValue","defaultValue","min","max","step","stepPage","precision","precisionFromProps","onChange","size","appearance","inputDefaultAppearance","root","input","incrementButton","decrementButton","useMemo","Math","currentValue","setCurrentValue","state","defaultState","initialState","isControlled","undefined","textValue","setTextValue","useState","keyboardSpinState","setKeyboardSpinState","internalState","useRef","spinState","spinTime","spinDelay","atBound","setStepTimeout","clearStepTimeout","stepValue","e","direction","startFrom","startValue","current","num","parseFloat","isNaN","val","dir","stepSize","stepStart","nullStep","commit","newValue","Number","handleInputChange","previousTextValue","String","target","handleIncrementMouseDown","handleDecrementMouseDown","handleStepMouseUpOrLeave","handleBlur","handleKeyDown","nextKeyboardSpinState","key","preventDefault","shiftKey","handleKeyUp","newDisplayValue","valueChanged","displayValueChanged","roundedValue","nextValue","components","required","defaultProps","autoComplete","role","type","primary","tabIndex","children","disabled","valueToDisplay","onBlur","onKeyDown","onKeyUp","onMouseDown","onMouseUp","onMouseLeave"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,6BAA6B,QAAQ,wBAAwB;AACtE,SACEC,yBAAyB,EACzBC,cAAc,EACdC,gBAAgB,EAChBC,oBAAoB,EACpBC,UAAU,QACL,4BAA4B;AACnC,SAASC,OAAO,EAAEC,SAAS,EAAEC,GAAG,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,MAAM,QAAQ,0BAA0B;AAQzG,SAASC,kBAAkB,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