@fluentui/react-spinbutton 0.0.0-nightly-20230321-0440.1 → 0.0.0-nightly-20230322-0439.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 (54) hide show
  1. package/.swcrc +30 -0
  2. package/CHANGELOG.json +86 -17
  3. package/CHANGELOG.md +29 -11
  4. package/lib/SpinButton.js.map +1 -1
  5. package/lib/SpinButtonField.js.map +1 -1
  6. package/lib/components/SpinButton/SpinButton.js.map +1 -1
  7. package/lib/components/SpinButton/SpinButton.types.js +1 -1
  8. package/lib/components/SpinButton/SpinButton.types.js.map +1 -1
  9. package/lib/components/SpinButton/index.js.map +1 -1
  10. package/lib/components/SpinButton/renderSpinButton.js +1 -9
  11. package/lib/components/SpinButton/renderSpinButton.js.map +1 -1
  12. package/lib/components/SpinButton/useSpinButton.js +4 -3
  13. package/lib/components/SpinButton/useSpinButton.js.map +1 -1
  14. package/lib/components/SpinButton/useSpinButtonStyles.js.map +1 -1
  15. package/lib/components/SpinButtonField/SpinButtonField.js +1 -2
  16. package/lib/components/SpinButtonField/SpinButtonField.js.map +1 -1
  17. package/lib/components/SpinButtonField/index.js.map +1 -1
  18. package/lib/index.js.map +1 -1
  19. package/lib/utils/clamp.js.map +1 -1
  20. package/lib/utils/getBound.js.map +1 -1
  21. package/lib/utils/index.js.map +1 -1
  22. package/lib/utils/precision.js +6 -7
  23. package/lib/utils/precision.js.map +1 -1
  24. package/lib-commonjs/SpinButton.js +5 -4
  25. package/lib-commonjs/SpinButton.js.map +1 -1
  26. package/lib-commonjs/SpinButtonField.js +5 -4
  27. package/lib-commonjs/SpinButtonField.js.map +1 -1
  28. package/lib-commonjs/components/SpinButton/SpinButton.js +19 -20
  29. package/lib-commonjs/components/SpinButton/SpinButton.js.map +1 -1
  30. package/lib-commonjs/components/SpinButton/SpinButton.types.js +5 -2
  31. package/lib-commonjs/components/SpinButton/SpinButton.types.js.map +1 -1
  32. package/lib-commonjs/components/SpinButton/index.js +9 -8
  33. package/lib-commonjs/components/SpinButton/index.js.map +1 -1
  34. package/lib-commonjs/components/SpinButton/renderSpinButton.js +13 -24
  35. package/lib-commonjs/components/SpinButton/renderSpinButton.js.map +1 -1
  36. package/lib-commonjs/components/SpinButton/useSpinButton.js +248 -259
  37. package/lib-commonjs/components/SpinButton/useSpinButton.js.map +1 -1
  38. package/lib-commonjs/components/SpinButton/useSpinButtonStyles.js +506 -246
  39. package/lib-commonjs/components/SpinButton/useSpinButtonStyles.js.map +1 -1
  40. package/lib-commonjs/components/SpinButtonField/SpinButtonField.js +17 -11
  41. package/lib-commonjs/components/SpinButtonField/SpinButtonField.js.map +1 -1
  42. package/lib-commonjs/components/SpinButtonField/index.js +5 -4
  43. package/lib-commonjs/components/SpinButtonField/index.js.map +1 -1
  44. package/lib-commonjs/index.js +21 -49
  45. package/lib-commonjs/index.js.map +1 -1
  46. package/lib-commonjs/utils/clamp.js +28 -21
  47. package/lib-commonjs/utils/clamp.js.map +1 -1
  48. package/lib-commonjs/utils/getBound.js +16 -14
  49. package/lib-commonjs/utils/getBound.js.map +1 -1
  50. package/lib-commonjs/utils/index.js +7 -6
  51. package/lib-commonjs/utils/index.js.map +1 -1
  52. package/lib-commonjs/utils/precision.js +33 -33
  53. package/lib-commonjs/utils/precision.js.map +1 -1
  54. package/package.json +10 -10
@@ -1,273 +1,262 @@
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
+ var _overrides_inputDefaultAppearance;
38
+ 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;
39
+ const precision = _react.useMemo(()=>{
40
+ return precisionFromProps !== null && precisionFromProps !== void 0 ? precisionFromProps : Math.max((0, _index.calculatePrecision)(step), 0);
41
+ }, [
42
+ precisionFromProps,
43
+ step
44
+ ]);
45
+ const [currentValue, setCurrentValue] = (0, _reactUtilities.useControllableState)({
46
+ state: value,
47
+ defaultState: defaultValue,
48
+ initialState: 0
49
+ });
50
+ const isControlled = value !== undefined;
51
+ const [textValue, setTextValue] = _react.useState(undefined);
52
+ const [keyboardSpinState, setKeyboardSpinState] = _react.useState('rest');
53
+ const internalState = _react.useRef({
54
+ value: currentValue,
55
+ spinState: 'rest',
56
+ spinTime: 0,
57
+ spinDelay: DEFAULT_SPIN_DELAY_MS,
58
+ atBound: currentValue !== null ? (0, _index.getBound)((0, _index.precisionRound)(currentValue, precision), min, max) : 'none'
59
+ });
60
+ const [setStepTimeout, clearStepTimeout] = (0, _reactUtilities.useTimeout)();
61
+ const stepValue = (e, direction, startFrom)=>{
62
+ let startValue = internalState.current.value;
63
+ if (startFrom) {
64
+ const num = parseFloat(startFrom);
65
+ if (!isNaN(num)) {
66
+ startValue = num;
67
+ }
68
+ }
69
+ const val = startValue;
70
+ const dir = direction === 'up' || direction === 'upPage' ? 1 : -1;
71
+ const stepSize = direction === 'upPage' || direction === 'downPage' ? stepPage : step;
72
+ if (val === null) {
73
+ const stepStart = min === undefined ? 0 : min;
74
+ const nullStep = (0, _index.clamp)(stepStart + stepSize * dir, min, max);
75
+ commit(e, nullStep);
76
+ return;
77
+ }
78
+ let newValue = val + stepSize * dir;
79
+ if (!Number.isNaN(newValue)) {
80
+ newValue = (0, _index.clamp)(newValue, min, max);
81
+ }
82
+ commit(e, newValue);
83
+ if (internalState.current.spinState !== 'rest') {
84
+ setStepTimeout(()=>{
85
+ // Ease the step speed a bit
86
+ internalState.current.spinTime += internalState.current.spinDelay;
87
+ internalState.current.spinDelay = lerp(DEFAULT_SPIN_DELAY_MS, MIN_SPIN_DELAY_MS, internalState.current.spinTime / MAX_SPIN_TIME_MS);
88
+ stepValue(e, direction);
89
+ }, internalState.current.spinDelay);
90
+ }
91
+ };
92
+ const handleInputChange = (e)=>{
93
+ if (!internalState.current.previousTextValue) {
94
+ internalState.current.previousTextValue = textValue !== null && textValue !== void 0 ? textValue : String(currentValue);
95
+ }
96
+ const newValue = e.target.value;
97
+ setTextValue(newValue);
98
+ };
99
+ const handleIncrementMouseDown = (e)=>{
100
+ internalState.current.spinState = 'up';
101
+ stepValue(e, 'up');
102
+ };
103
+ const handleDecrementMouseDown = (e)=>{
104
+ internalState.current.spinState = 'down';
105
+ stepValue(e, 'down');
106
+ };
107
+ const handleStepMouseUpOrLeave = (e)=>{
108
+ clearStepTimeout();
109
+ internalState.current.spinState = 'rest';
110
+ internalState.current.spinDelay = DEFAULT_SPIN_DELAY_MS;
111
+ internalState.current.spinTime = 0;
112
+ };
113
+ const handleBlur = (e)=>{
114
+ commit(e, currentValue, textValue);
157
115
  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',
116
+ };
117
+ const handleKeyDown = (e)=>{
118
+ let nextKeyboardSpinState = 'rest';
119
+ if (e.key === _keyboardKeys.ArrowUp) {
120
+ stepValue(e, 'up', textValue);
121
+ nextKeyboardSpinState = 'up';
122
+ } else if (e.key === _keyboardKeys.ArrowDown) {
123
+ stepValue(e, 'down', textValue);
124
+ nextKeyboardSpinState = 'down';
125
+ } else if (e.key === _keyboardKeys.PageUp) {
126
+ e.preventDefault();
127
+ stepValue(e, 'upPage', textValue);
128
+ nextKeyboardSpinState = 'up';
129
+ } else if (e.key === _keyboardKeys.PageDown) {
130
+ e.preventDefault();
131
+ stepValue(e, 'downPage', textValue);
132
+ nextKeyboardSpinState = 'down';
133
+ } else if (!e.shiftKey && e.key === _keyboardKeys.Home && min !== undefined) {
134
+ commit(e, min);
135
+ nextKeyboardSpinState = 'down';
136
+ } else if (!e.shiftKey && e.key === _keyboardKeys.End && max !== undefined) {
137
+ commit(e, max);
138
+ nextKeyboardSpinState = 'up';
139
+ } else if (e.key === _keyboardKeys.Enter) {
140
+ commit(e, currentValue, textValue);
141
+ internalState.current.previousTextValue = undefined;
142
+ } else if (e.key === _keyboardKeys.Escape) {
143
+ if (internalState.current.previousTextValue) {
144
+ setTextValue(undefined);
145
+ internalState.current.previousTextValue = undefined;
146
+ }
147
+ }
148
+ if (keyboardSpinState !== nextKeyboardSpinState) {
149
+ setKeyboardSpinState(nextKeyboardSpinState);
150
+ }
151
+ };
152
+ const handleKeyUp = (e)=>{
153
+ if (keyboardSpinState !== 'rest') {
154
+ setKeyboardSpinState('rest');
155
+ internalState.current.spinState = 'rest';
156
+ }
157
+ };
158
+ const commit = (e, newValue, newDisplayValue)=>{
159
+ const valueChanged = newValue !== undefined && currentValue !== newValue;
160
+ const displayValueChanged = newDisplayValue !== undefined && internalState.current.previousTextValue !== undefined && internalState.current.previousTextValue !== newDisplayValue;
161
+ let roundedValue;
162
+ if (valueChanged) {
163
+ roundedValue = (0, _index.precisionRound)(newValue, precision);
164
+ setCurrentValue(roundedValue);
165
+ } else if (displayValueChanged && !isControlled) {
166
+ const nextValue = parseFloat(newDisplayValue);
167
+ if (!isNaN(nextValue)) {
168
+ setCurrentValue((0, _index.precisionRound)(nextValue, precision));
169
+ }
170
+ }
171
+ if (valueChanged || displayValueChanged) {
172
+ onChange === null || onChange === void 0 ? void 0 : onChange(e, {
173
+ value: roundedValue,
174
+ displayValue: newDisplayValue
175
+ });
176
+ }
177
+ setTextValue(undefined);
178
+ };
179
+ const state = {
180
+ size,
212
181
  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);
182
+ spinState: keyboardSpinState,
183
+ atBound: internalState.current.atBound,
184
+ components: {
185
+ root: 'span',
186
+ input: 'input',
187
+ incrementButton: 'button',
188
+ decrementButton: 'button'
189
+ },
190
+ root: (0, _reactUtilities.resolveShorthand)(root, {
191
+ required: true,
192
+ defaultProps: nativeProps.root
193
+ }),
194
+ input: (0, _reactUtilities.resolveShorthand)(input, {
195
+ required: true,
196
+ defaultProps: {
197
+ ref,
198
+ autoComplete: 'off',
199
+ role: 'spinbutton',
200
+ appearance,
201
+ type: 'text',
202
+ ...nativeProps.primary
203
+ }
204
+ }),
205
+ incrementButton: (0, _reactUtilities.resolveShorthand)(incrementButton, {
206
+ required: true,
207
+ defaultProps: {
208
+ tabIndex: -1,
209
+ children: /*#__PURE__*/ _react.createElement(_reactIcons.ChevronUp16Regular, null),
210
+ disabled: nativeProps.primary.disabled,
211
+ 'aria-label': 'Increment value',
212
+ type: 'button'
213
+ }
214
+ }),
215
+ decrementButton: (0, _reactUtilities.resolveShorthand)(decrementButton, {
216
+ required: true,
217
+ defaultProps: {
218
+ tabIndex: -1,
219
+ children: /*#__PURE__*/ _react.createElement(_reactIcons.ChevronDown16Regular, null),
220
+ disabled: nativeProps.primary.disabled,
221
+ 'aria-label': 'Decrement value',
222
+ type: 'button'
223
+ }
224
+ })
225
+ };
226
+ let valueToDisplay;
227
+ if (textValue !== undefined) {
228
+ valueToDisplay = textValue;
229
+ } else if (value === null || currentValue === null) {
230
+ valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : '';
231
+ internalState.current.value = null;
232
+ internalState.current.atBound = 'none';
251
233
  } else {
252
- valueToDisplay = String(roundedValue);
234
+ const roundedValue = (0, _index.precisionRound)(currentValue, precision);
235
+ internalState.current.value = roundedValue;
236
+ internalState.current.atBound = (0, _index.getBound)(roundedValue, min, max);
237
+ if (isControlled) {
238
+ valueToDisplay = displayValue !== null && displayValue !== void 0 ? displayValue : String(roundedValue);
239
+ } else {
240
+ valueToDisplay = String(roundedValue);
241
+ }
253
242
  }
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;
243
+ state.input.value = valueToDisplay;
244
+ state.input['aria-valuemin'] = min;
245
+ state.input['aria-valuemax'] = max;
246
+ state.input['aria-valuenow'] = currentValue !== null && currentValue !== void 0 ? currentValue : undefined;
247
+ var _state_input_ariavaluetext;
248
+ state.input['aria-valuetext'] = (_state_input_ariavaluetext = state.input['aria-valuetext']) !== null && _state_input_ariavaluetext !== void 0 ? _state_input_ariavaluetext : value !== undefined && displayValue || undefined;
249
+ state.input.onChange = (0, _reactUtilities.mergeCallbacks)(state.input.onChange, handleInputChange);
250
+ state.input.onBlur = (0, _reactUtilities.mergeCallbacks)(state.input.onBlur, handleBlur);
251
+ state.input.onKeyDown = (0, _reactUtilities.mergeCallbacks)(state.input.onKeyDown, handleKeyDown);
252
+ state.input.onKeyUp = (0, _reactUtilities.mergeCallbacks)(state.input.onKeyUp, handleKeyUp);
253
+ state.incrementButton.onMouseDown = (0, _reactUtilities.mergeCallbacks)(handleIncrementMouseDown, state.incrementButton.onMouseDown);
254
+ state.incrementButton.onMouseUp = (0, _reactUtilities.mergeCallbacks)(state.incrementButton.onMouseUp, handleStepMouseUpOrLeave);
255
+ state.incrementButton.onMouseLeave = (0, _reactUtilities.mergeCallbacks)(state.incrementButton.onMouseLeave, handleStepMouseUpOrLeave);
256
+ state.decrementButton.onMouseDown = (0, _reactUtilities.mergeCallbacks)(handleDecrementMouseDown, state.decrementButton.onMouseDown);
257
+ state.decrementButton.onMouseUp = (0, _reactUtilities.mergeCallbacks)(state.decrementButton.onMouseUp, handleStepMouseUpOrLeave);
258
+ state.decrementButton.onMouseLeave = (0, _reactUtilities.mergeCallbacks)(state.decrementButton.onMouseLeave, handleStepMouseUpOrLeave);
259
+ return state;
260
+ }; //# sourceMappingURL=useSpinButton.js.map
261
+
273
262
  //# sourceMappingURL=useSpinButton.js.map