@fluentui/react-spinbutton 0.0.0-nightly-20230316-0427.1 → 0.0.0-nightly-20230317-1454.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/.swcrc +39 -0
  2. package/CHANGELOG.json +44 -17
  3. package/CHANGELOG.md +22 -11
  4. package/lib/SpinButton.js +1 -1
  5. package/lib/SpinButton.js.map +1 -1
  6. package/lib/SpinButtonField.js +1 -1
  7. package/lib/SpinButtonField.js.map +1 -1
  8. package/lib/components/SpinButton/SpinButton.js +6 -6
  9. package/lib/components/SpinButton/SpinButton.js.map +1 -1
  10. package/lib/components/SpinButton/SpinButton.types.js +1 -1
  11. package/lib/components/SpinButton/SpinButton.types.js.map +1 -1
  12. package/lib/components/SpinButton/index.js +5 -5
  13. package/lib/components/SpinButton/index.js.map +1 -1
  14. package/lib/components/SpinButton/renderSpinButton.js +3 -11
  15. package/lib/components/SpinButton/renderSpinButton.js.map +1 -1
  16. package/lib/components/SpinButton/useSpinButton.js +56 -57
  17. package/lib/components/SpinButton/useSpinButton.js.map +1 -1
  18. package/lib/components/SpinButton/useSpinButtonStyles.js +14 -14
  19. package/lib/components/SpinButton/useSpinButtonStyles.js.map +1 -1
  20. package/lib/components/SpinButtonField/SpinButtonField.js +2 -3
  21. package/lib/components/SpinButtonField/SpinButtonField.js.map +1 -1
  22. package/lib/components/SpinButtonField/index.js +1 -1
  23. package/lib/components/SpinButtonField/index.js.map +1 -1
  24. package/lib/index.js +2 -2
  25. package/lib/index.js.map +1 -1
  26. package/lib/utils/clamp.js +1 -1
  27. package/lib/utils/clamp.js.map +1 -1
  28. package/lib/utils/getBound.js +4 -4
  29. package/lib/utils/getBound.js.map +1 -1
  30. package/lib/utils/index.js +3 -3
  31. package/lib/utils/index.js.map +1 -1
  32. package/lib/utils/precision.js +6 -7
  33. package/lib/utils/precision.js.map +1 -1
  34. package/lib-commonjs/SpinButton.js +5 -4
  35. package/lib-commonjs/SpinButton.js.map +1 -1
  36. package/lib-commonjs/SpinButtonField.js +5 -4
  37. package/lib-commonjs/SpinButtonField.js.map +1 -1
  38. package/lib-commonjs/components/SpinButton/SpinButton.js +19 -20
  39. package/lib-commonjs/components/SpinButton/SpinButton.js.map +1 -1
  40. package/lib-commonjs/components/SpinButton/SpinButton.types.js +5 -2
  41. package/lib-commonjs/components/SpinButton/SpinButton.types.js.map +1 -1
  42. package/lib-commonjs/components/SpinButton/index.js +9 -8
  43. package/lib-commonjs/components/SpinButton/index.js.map +1 -1
  44. package/lib-commonjs/components/SpinButton/renderSpinButton.js +13 -24
  45. package/lib-commonjs/components/SpinButton/renderSpinButton.js.map +1 -1
  46. package/lib-commonjs/components/SpinButton/useSpinButton.js +246 -259
  47. package/lib-commonjs/components/SpinButton/useSpinButton.js.map +1 -1
  48. package/lib-commonjs/components/SpinButton/useSpinButtonStyles.js +506 -246
  49. package/lib-commonjs/components/SpinButton/useSpinButtonStyles.js.map +1 -1
  50. package/lib-commonjs/components/SpinButtonField/SpinButtonField.js +17 -11
  51. package/lib-commonjs/components/SpinButtonField/SpinButtonField.js.map +1 -1
  52. package/lib-commonjs/components/SpinButtonField/index.js +5 -4
  53. package/lib-commonjs/components/SpinButtonField/index.js.map +1 -1
  54. package/lib-commonjs/index.js +21 -49
  55. package/lib-commonjs/index.js.map +1 -1
  56. package/lib-commonjs/utils/clamp.js +28 -21
  57. package/lib-commonjs/utils/clamp.js.map +1 -1
  58. package/lib-commonjs/utils/getBound.js +16 -14
  59. package/lib-commonjs/utils/getBound.js.map +1 -1
  60. package/lib-commonjs/utils/index.js +7 -6
  61. package/lib-commonjs/utils/index.js.map +1 -1
  62. package/lib-commonjs/utils/precision.js +33 -33
  63. package/lib-commonjs/utils/precision.js.map +1 -1
  64. package/package.json +10 -10
@@ -1,273 +1,260 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useSpinButton_unstable", {
6
+ enumerable: true,
7
+ get: ()=>useSpinButton_unstable
5
8
  });
6
- exports.useSpinButton_unstable = void 0;
7
- const React = /*#__PURE__*/require("react");
8
- const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
9
- const keyboard_keys_1 = /*#__PURE__*/require("@fluentui/keyboard-keys");
10
- const index_1 = /*#__PURE__*/require("../../utils/index");
11
- const react_icons_1 = /*#__PURE__*/require("@fluentui/react-icons");
12
- const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _reactUtilities = require("@fluentui/react-utilities");
12
+ const _keyboardKeys = require("@fluentui/keyboard-keys");
13
+ const _index = require("../../utils/index");
14
+ const _reactIcons = require("@fluentui/react-icons");
15
+ const _reactSharedContexts = require("@fluentui/react-shared-contexts");
13
16
  const DEFAULT_SPIN_DELAY_MS = 150;
14
17
  const MIN_SPIN_DELAY_MS = 80;
15
18
  const MAX_SPIN_TIME_MS = 1000;
16
19
  // This is here to give an ease for the mouse held down case.
17
20
  // Exact easing it to be defined. Once it is we'll likely
18
21
  // pull this out into a util function in the SpinButton package.
19
- const lerp = (start, end, percent) => start + (end - start) * percent;
20
- /**
21
- * Create the state required to render SpinButton.
22
- *
23
- * The returned state can be modified with hooks such as useSpinButtonStyles_unstable,
24
- * before being passed to renderSpinButton_unstable.
25
- *
26
- * @param props - props from this instance of SpinButton
27
- * @param ref - reference to root HTMLElement of SpinButton
28
- */
29
- const useSpinButton_unstable = (props, ref) => {
30
- var _a, _b;
31
- const nativeProps = react_utilities_1.getPartitionedNativeProps({
32
- props,
33
- primarySlotTagName: 'input',
34
- excludedPropNames: ['defaultValue', 'max', 'min', 'onChange', 'size', 'value']
35
- });
36
- const overrides = react_shared_contexts_1.useOverrides_unstable();
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 = (_a = overrides.inputDefaultAppearance) !== null && _a !== void 0 ? _a : '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(index_1.calculatePrecision(step), 0);
56
- }, [precisionFromProps, step]);
57
- const [currentValue, setCurrentValue] = react_utilities_1.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 ? index_1.getBound(index_1.precisionRound(currentValue, precision), min, max) : 'none'
71
- });
72
- const [setStepTimeout, clearStepTimeout] = react_utilities_1.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 = index_1.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 = index_1.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 === keyboard_keys_1.ArrowUp) {
132
- stepValue(e, 'up', textValue);
133
- nextKeyboardSpinState = 'up';
134
- } else if (e.key === keyboard_keys_1.ArrowDown) {
135
- stepValue(e, 'down', textValue);
136
- nextKeyboardSpinState = 'down';
137
- } else if (e.key === keyboard_keys_1.PageUp) {
138
- e.preventDefault();
139
- stepValue(e, 'upPage', textValue);
140
- nextKeyboardSpinState = 'up';
141
- } else if (e.key === keyboard_keys_1.PageDown) {
142
- e.preventDefault();
143
- stepValue(e, 'downPage', textValue);
144
- nextKeyboardSpinState = 'down';
145
- } else if (!e.shiftKey && e.key === keyboard_keys_1.Home && min !== undefined) {
146
- commit(e, min);
147
- nextKeyboardSpinState = 'down';
148
- } else if (!e.shiftKey && e.key === keyboard_keys_1.End && max !== undefined) {
149
- commit(e, max);
150
- nextKeyboardSpinState = 'up';
151
- } else if (e.key === keyboard_keys_1.Enter) {
152
- commit(e, currentValue, textValue);
153
- internalState.current.previousTextValue = undefined;
154
- } else if (e.key === keyboard_keys_1.Escape) {
155
- if (internalState.current.previousTextValue) {
156
- setTextValue(undefined);
22
+ const lerp = (start, end, percent)=>start + (end - start) * percent;
23
+ const useSpinButton_unstable = (props, ref)=>{
24
+ const nativeProps = (0, _reactUtilities.getPartitionedNativeProps)({
25
+ props,
26
+ primarySlotTagName: "input",
27
+ excludedPropNames: [
28
+ "defaultValue",
29
+ "max",
30
+ "min",
31
+ "onChange",
32
+ "size",
33
+ "value"
34
+ ]
35
+ });
36
+ const overrides = (0, _reactSharedContexts.useOverrides_unstable)();
37
+ const { value , displayValue , defaultValue , min , max , step =1 , stepPage =1 , precision: precisionFromProps , onChange , size ="medium" , appearance =overrides.inputDefaultAppearance ?? "outline" , root , input , incrementButton , decrementButton } = props;
38
+ const precision = _react.useMemo(()=>{
39
+ return precisionFromProps ?? Math.max((0, _index.calculatePrecision)(step), 0);
40
+ }, [
41
+ precisionFromProps,
42
+ step
43
+ ]);
44
+ const [currentValue, setCurrentValue] = (0, _reactUtilities.useControllableState)({
45
+ state: value,
46
+ defaultState: defaultValue,
47
+ initialState: 0
48
+ });
49
+ const isControlled = value !== undefined;
50
+ const [textValue, setTextValue] = _react.useState(undefined);
51
+ const [keyboardSpinState, setKeyboardSpinState] = _react.useState("rest");
52
+ const internalState = _react.useRef({
53
+ value: currentValue,
54
+ spinState: "rest",
55
+ spinTime: 0,
56
+ spinDelay: DEFAULT_SPIN_DELAY_MS,
57
+ atBound: currentValue !== null ? (0, _index.getBound)((0, _index.precisionRound)(currentValue, precision), min, max) : "none"
58
+ });
59
+ const [setStepTimeout, clearStepTimeout] = (0, _reactUtilities.useTimeout)();
60
+ const stepValue = (e, direction, startFrom)=>{
61
+ let startValue = internalState.current.value;
62
+ if (startFrom) {
63
+ const num = parseFloat(startFrom);
64
+ if (!isNaN(num)) {
65
+ startValue = num;
66
+ }
67
+ }
68
+ const val = startValue;
69
+ const dir = direction === "up" || direction === "upPage" ? 1 : -1;
70
+ const stepSize = direction === "upPage" || direction === "downPage" ? stepPage : step;
71
+ if (val === null) {
72
+ const stepStart = min === undefined ? 0 : min;
73
+ const nullStep = (0, _index.clamp)(stepStart + stepSize * dir, min, max);
74
+ commit(e, nullStep);
75
+ return;
76
+ }
77
+ let newValue = val + stepSize * dir;
78
+ if (!Number.isNaN(newValue)) {
79
+ newValue = (0, _index.clamp)(newValue, min, max);
80
+ }
81
+ commit(e, newValue);
82
+ if (internalState.current.spinState !== "rest") {
83
+ setStepTimeout(()=>{
84
+ // Ease the step speed a bit
85
+ internalState.current.spinTime += internalState.current.spinDelay;
86
+ internalState.current.spinDelay = lerp(DEFAULT_SPIN_DELAY_MS, MIN_SPIN_DELAY_MS, internalState.current.spinTime / MAX_SPIN_TIME_MS);
87
+ stepValue(e, direction);
88
+ }, internalState.current.spinDelay);
89
+ }
90
+ };
91
+ const handleInputChange = (e)=>{
92
+ if (!internalState.current.previousTextValue) {
93
+ internalState.current.previousTextValue = textValue ?? String(currentValue);
94
+ }
95
+ const newValue = e.target.value;
96
+ setTextValue(newValue);
97
+ };
98
+ const handleIncrementMouseDown = (e)=>{
99
+ internalState.current.spinState = "up";
100
+ stepValue(e, "up");
101
+ };
102
+ const handleDecrementMouseDown = (e)=>{
103
+ internalState.current.spinState = "down";
104
+ stepValue(e, "down");
105
+ };
106
+ const handleStepMouseUpOrLeave = (e)=>{
107
+ clearStepTimeout();
108
+ internalState.current.spinState = "rest";
109
+ internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;
110
+ internalState.current.spinTime = 0;
111
+ };
112
+ const handleBlur = (e)=>{
113
+ commit(e, currentValue, textValue);
157
114
  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 = index_1.precisionRound(newValue, precision);
176
- setCurrentValue(roundedValue);
177
- } else if (displayValueChanged && !isControlled) {
178
- const nextValue = parseFloat(newDisplayValue);
179
- if (!isNaN(nextValue)) {
180
- setCurrentValue(index_1.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: react_utilities_1.resolveShorthand(root, {
203
- required: true,
204
- defaultProps: nativeProps.root
205
- }),
206
- input: react_utilities_1.resolveShorthand(input, {
207
- required: true,
208
- defaultProps: {
209
- ref,
210
- autoComplete: 'off',
211
- role: 'spinbutton',
115
+ };
116
+ const handleKeyDown = (e)=>{
117
+ let nextKeyboardSpinState = "rest";
118
+ if (e.key === _keyboardKeys.ArrowUp) {
119
+ stepValue(e, "up", textValue);
120
+ nextKeyboardSpinState = "up";
121
+ } else if (e.key === _keyboardKeys.ArrowDown) {
122
+ stepValue(e, "down", textValue);
123
+ nextKeyboardSpinState = "down";
124
+ } else if (e.key === _keyboardKeys.PageUp) {
125
+ e.preventDefault();
126
+ stepValue(e, "upPage", textValue);
127
+ nextKeyboardSpinState = "up";
128
+ } else if (e.key === _keyboardKeys.PageDown) {
129
+ e.preventDefault();
130
+ stepValue(e, "downPage", textValue);
131
+ nextKeyboardSpinState = "down";
132
+ } else if (!e.shiftKey && e.key === _keyboardKeys.Home && min !== undefined) {
133
+ commit(e, min);
134
+ nextKeyboardSpinState = "down";
135
+ } else if (!e.shiftKey && e.key === _keyboardKeys.End && max !== undefined) {
136
+ commit(e, max);
137
+ nextKeyboardSpinState = "up";
138
+ } else if (e.key === _keyboardKeys.Enter) {
139
+ commit(e, currentValue, textValue);
140
+ internalState.current.previousTextValue = undefined;
141
+ } else if (e.key === _keyboardKeys.Escape) {
142
+ if (internalState.current.previousTextValue) {
143
+ setTextValue(undefined);
144
+ internalState.current.previousTextValue = undefined;
145
+ }
146
+ }
147
+ if (keyboardSpinState !== nextKeyboardSpinState) {
148
+ setKeyboardSpinState(nextKeyboardSpinState);
149
+ }
150
+ };
151
+ const handleKeyUp = (e)=>{
152
+ if (keyboardSpinState !== "rest") {
153
+ setKeyboardSpinState("rest");
154
+ internalState.current.spinState = "rest";
155
+ }
156
+ };
157
+ const commit = (e, newValue, newDisplayValue)=>{
158
+ const valueChanged = newValue !== undefined && currentValue !== newValue;
159
+ const displayValueChanged = newDisplayValue !== undefined && internalState.current.previousTextValue !== undefined && internalState.current.previousTextValue !== newDisplayValue;
160
+ let roundedValue;
161
+ if (valueChanged) {
162
+ roundedValue = (0, _index.precisionRound)(newValue, precision);
163
+ setCurrentValue(roundedValue);
164
+ } else if (displayValueChanged && !isControlled) {
165
+ const nextValue = parseFloat(newDisplayValue);
166
+ if (!isNaN(nextValue)) {
167
+ setCurrentValue((0, _index.precisionRound)(nextValue, precision));
168
+ }
169
+ }
170
+ if (valueChanged || displayValueChanged) {
171
+ onChange?.(e, {
172
+ value: roundedValue,
173
+ displayValue: newDisplayValue
174
+ });
175
+ }
176
+ setTextValue(undefined);
177
+ };
178
+ const state = {
179
+ size,
212
180
  appearance,
213
- type: 'text',
214
- ...nativeProps.primary
215
- }
216
- }),
217
- incrementButton: react_utilities_1.resolveShorthand(incrementButton, {
218
- required: true,
219
- defaultProps: {
220
- tabIndex: -1,
221
- children: React.createElement(react_icons_1.ChevronUp16Regular, null),
222
- disabled: nativeProps.primary.disabled,
223
- 'aria-label': 'Increment value',
224
- type: 'button'
225
- }
226
- }),
227
- decrementButton: react_utilities_1.resolveShorthand(decrementButton, {
228
- required: true,
229
- defaultProps: {
230
- tabIndex: -1,
231
- children: React.createElement(react_icons_1.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 = index_1.precisionRound(currentValue, precision);
247
- internalState.current.value = roundedValue;
248
- internalState.current.atBound = index_1.getBound(roundedValue, min, max);
249
- if (isControlled) {
250
- valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : String(roundedValue);
181
+ spinState: keyboardSpinState,
182
+ atBound: internalState.current.atBound,
183
+ components: {
184
+ root: "span",
185
+ input: "input",
186
+ incrementButton: "button",
187
+ decrementButton: "button"
188
+ },
189
+ root: (0, _reactUtilities.resolveShorthand)(root, {
190
+ required: true,
191
+ defaultProps: nativeProps.root
192
+ }),
193
+ input: (0, _reactUtilities.resolveShorthand)(input, {
194
+ required: true,
195
+ defaultProps: {
196
+ ref,
197
+ autoComplete: "off",
198
+ role: "spinbutton",
199
+ appearance,
200
+ type: "text",
201
+ ...nativeProps.primary
202
+ }
203
+ }),
204
+ incrementButton: (0, _reactUtilities.resolveShorthand)(incrementButton, {
205
+ required: true,
206
+ defaultProps: {
207
+ tabIndex: -1,
208
+ children: /*#__PURE__*/ _react.createElement(_reactIcons.ChevronUp16Regular, null),
209
+ disabled: nativeProps.primary.disabled,
210
+ "aria-label": "Increment value",
211
+ type: "button"
212
+ }
213
+ }),
214
+ decrementButton: (0, _reactUtilities.resolveShorthand)(decrementButton, {
215
+ required: true,
216
+ defaultProps: {
217
+ tabIndex: -1,
218
+ children: /*#__PURE__*/ _react.createElement(_reactIcons.ChevronDown16Regular, null),
219
+ disabled: nativeProps.primary.disabled,
220
+ "aria-label": "Decrement value",
221
+ type: "button"
222
+ }
223
+ })
224
+ };
225
+ let valueToDisplay;
226
+ if (textValue !== undefined) {
227
+ valueToDisplay = textValue;
228
+ } else if (value === null || currentValue === null) {
229
+ valueToDisplay = displayValue ?? "";
230
+ internalState.current.value = null;
231
+ internalState.current.atBound = "none";
251
232
  } else {
252
- valueToDisplay = String(roundedValue);
233
+ const roundedValue = (0, _index.precisionRound)(currentValue, precision);
234
+ internalState.current.value = roundedValue;
235
+ internalState.current.atBound = (0, _index.getBound)(roundedValue, min, max);
236
+ if (isControlled) {
237
+ valueToDisplay = displayValue ?? String(roundedValue);
238
+ } else {
239
+ valueToDisplay = String(roundedValue);
240
+ }
253
241
  }
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
- state.input['aria-valuetext'] = (_b = state.input['aria-valuetext']) !== null && _b !== void 0 ? _b : value !== undefined && displayValue || undefined;
260
- state.input.onChange = react_utilities_1.mergeCallbacks(state.input.onChange, handleInputChange);
261
- state.input.onBlur = react_utilities_1.mergeCallbacks(state.input.onBlur, handleBlur);
262
- state.input.onKeyDown = react_utilities_1.mergeCallbacks(state.input.onKeyDown, handleKeyDown);
263
- state.input.onKeyUp = react_utilities_1.mergeCallbacks(state.input.onKeyUp, handleKeyUp);
264
- state.incrementButton.onMouseDown = react_utilities_1.mergeCallbacks(handleIncrementMouseDown, state.incrementButton.onMouseDown);
265
- state.incrementButton.onMouseUp = react_utilities_1.mergeCallbacks(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);
266
- state.incrementButton.onMouseLeave = react_utilities_1.mergeCallbacks(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);
267
- state.decrementButton.onMouseDown = react_utilities_1.mergeCallbacks(handleDecrementMouseDown, state.decrementButton.onMouseDown);
268
- state.decrementButton.onMouseUp = react_utilities_1.mergeCallbacks(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);
269
- state.decrementButton.onMouseLeave = react_utilities_1.mergeCallbacks(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);
270
- return state;
271
- };
272
- exports.useSpinButton_unstable = useSpinButton_unstable;
242
+ state.input.value = valueToDisplay;
243
+ state.input["aria-valuemin"] = min;
244
+ state.input["aria-valuemax"] = max;
245
+ state.input["aria-valuenow"] = currentValue ?? undefined;
246
+ state.input["aria-valuetext"] = state.input["aria-valuetext"] ?? (value !== undefined && displayValue || undefined);
247
+ state.input.onChange = (0, _reactUtilities.mergeCallbacks)(state.input.onChange, handleInputChange);
248
+ state.input.onBlur = (0, _reactUtilities.mergeCallbacks)(state.input.onBlur, handleBlur);
249
+ state.input.onKeyDown = (0, _reactUtilities.mergeCallbacks)(state.input.onKeyDown, handleKeyDown);
250
+ state.input.onKeyUp = (0, _reactUtilities.mergeCallbacks)(state.input.onKeyUp, handleKeyUp);
251
+ state.incrementButton.onMouseDown = (0, _reactUtilities.mergeCallbacks)(handleIncrementMouseDown, state.incrementButton.onMouseDown);
252
+ state.incrementButton.onMouseUp = (0, _reactUtilities.mergeCallbacks)(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);
253
+ state.incrementButton.onMouseLeave = (0, _reactUtilities.mergeCallbacks)(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);
254
+ state.decrementButton.onMouseDown = (0, _reactUtilities.mergeCallbacks)(handleDecrementMouseDown, state.decrementButton.onMouseDown);
255
+ state.decrementButton.onMouseUp = (0, _reactUtilities.mergeCallbacks)(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);
256
+ state.decrementButton.onMouseLeave = (0, _reactUtilities.mergeCallbacks)(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);
257
+ return state;
258
+ }; //# sourceMappingURL=useSpinButton.js.map
259
+
273
260
  //# sourceMappingURL=useSpinButton.js.map