@react-aria/spinbutton 3.6.3 → 3.6.5
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.
- package/dist/import.mjs +1 -264
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/main.js +2 -265
- package/dist/main.js.map +1 -1
- package/dist/module.js +1 -264
- package/dist/module.js.map +1 -1
- package/dist/useSpinButton.main.js +168 -0
- package/dist/useSpinButton.main.js.map +1 -0
- package/dist/useSpinButton.mjs +163 -0
- package/dist/useSpinButton.module.js +163 -0
- package/dist/useSpinButton.module.js.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
var $cb4b786159079747$exports = require("./intlStrings.main.js");
|
|
2
|
+
var $2pZbw$reactarialiveannouncer = require("@react-aria/live-announcer");
|
|
3
|
+
var $2pZbw$react = require("react");
|
|
4
|
+
var $2pZbw$reactariautils = require("@react-aria/utils");
|
|
5
|
+
var $2pZbw$reactariai18n = require("@react-aria/i18n");
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function $parcel$interopDefault(a) {
|
|
9
|
+
return a && a.__esModule ? a.default : a;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function $parcel$export(e, n, v, s) {
|
|
13
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
$parcel$export(module.exports, "useSpinButton", () => $37bbd4c129023f61$export$e908e06f4b8e3402);
|
|
17
|
+
/*
|
|
18
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
19
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
20
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
21
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
24
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
25
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
26
|
+
* governing permissions and limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
function $37bbd4c129023f61$export$e908e06f4b8e3402(props) {
|
|
33
|
+
const _async = (0, $2pZbw$react.useRef)();
|
|
34
|
+
let { value: value, textValue: textValue, minValue: minValue, maxValue: maxValue, isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, onIncrement: onIncrement, onIncrementPage: onIncrementPage, onDecrement: onDecrement, onDecrementPage: onDecrementPage, onDecrementToMin: onDecrementToMin, onIncrementToMax: onIncrementToMax } = props;
|
|
35
|
+
const stringFormatter = (0, $2pZbw$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($cb4b786159079747$exports))), '@react-aria/spinbutton');
|
|
36
|
+
const clearAsync = ()=>clearTimeout(_async.current);
|
|
37
|
+
// eslint-disable-next-line arrow-body-style
|
|
38
|
+
(0, $2pZbw$react.useEffect)(()=>{
|
|
39
|
+
return ()=>clearAsync();
|
|
40
|
+
}, []);
|
|
41
|
+
let onKeyDown = (e)=>{
|
|
42
|
+
if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || isReadOnly) return;
|
|
43
|
+
switch(e.key){
|
|
44
|
+
case 'PageUp':
|
|
45
|
+
if (onIncrementPage) {
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
onIncrementPage === null || onIncrementPage === void 0 ? void 0 : onIncrementPage();
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
// fallthrough!
|
|
51
|
+
case 'ArrowUp':
|
|
52
|
+
case 'Up':
|
|
53
|
+
if (onIncrement) {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'PageDown':
|
|
59
|
+
if (onDecrementPage) {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
onDecrementPage === null || onDecrementPage === void 0 ? void 0 : onDecrementPage();
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
// fallthrough
|
|
65
|
+
case 'ArrowDown':
|
|
66
|
+
case 'Down':
|
|
67
|
+
if (onDecrement) {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
case 'Home':
|
|
73
|
+
if (onDecrementToMin) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
onDecrementToMin === null || onDecrementToMin === void 0 ? void 0 : onDecrementToMin();
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case 'End':
|
|
79
|
+
if (onIncrementToMax) {
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
onIncrementToMax === null || onIncrementToMax === void 0 ? void 0 : onIncrementToMax();
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
let isFocused = (0, $2pZbw$react.useRef)(false);
|
|
87
|
+
let onFocus = ()=>{
|
|
88
|
+
isFocused.current = true;
|
|
89
|
+
};
|
|
90
|
+
let onBlur = ()=>{
|
|
91
|
+
isFocused.current = false;
|
|
92
|
+
};
|
|
93
|
+
// Replace Unicode hyphen-minus (U+002D) with minus sign (U+2212).
|
|
94
|
+
// This ensures that macOS VoiceOver announces it as "minus" even with other characters between the minus sign
|
|
95
|
+
// and the number (e.g. currency symbol). Otherwise it announces nothing because it assumes the character is a hyphen.
|
|
96
|
+
// In addition, replace the empty string with the word "Empty" so that iOS VoiceOver does not read "50%" for an empty field.
|
|
97
|
+
let ariaTextValue = textValue === '' ? stringFormatter.format('Empty') : (textValue || `${value}`).replace('-', '\u2212');
|
|
98
|
+
(0, $2pZbw$react.useEffect)(()=>{
|
|
99
|
+
if (isFocused.current) {
|
|
100
|
+
(0, $2pZbw$reactarialiveannouncer.clearAnnouncer)('assertive');
|
|
101
|
+
(0, $2pZbw$reactarialiveannouncer.announce)(ariaTextValue, 'assertive');
|
|
102
|
+
}
|
|
103
|
+
}, [
|
|
104
|
+
ariaTextValue
|
|
105
|
+
]);
|
|
106
|
+
const onIncrementPressStart = (0, $2pZbw$reactariautils.useEffectEvent)((initialStepDelay)=>{
|
|
107
|
+
clearAsync();
|
|
108
|
+
onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
|
|
109
|
+
// Start spinning after initial delay
|
|
110
|
+
_async.current = window.setTimeout(()=>{
|
|
111
|
+
if (maxValue === undefined || isNaN(maxValue) || value === undefined || isNaN(value) || value < maxValue) onIncrementPressStart(60);
|
|
112
|
+
}, initialStepDelay);
|
|
113
|
+
});
|
|
114
|
+
const onDecrementPressStart = (0, $2pZbw$reactariautils.useEffectEvent)((initialStepDelay)=>{
|
|
115
|
+
clearAsync();
|
|
116
|
+
onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
|
|
117
|
+
// Start spinning after initial delay
|
|
118
|
+
_async.current = window.setTimeout(()=>{
|
|
119
|
+
if (minValue === undefined || isNaN(minValue) || value === undefined || isNaN(value) || value > minValue) onDecrementPressStart(60);
|
|
120
|
+
}, initialStepDelay);
|
|
121
|
+
});
|
|
122
|
+
let cancelContextMenu = (e)=>{
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
};
|
|
125
|
+
let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $2pZbw$reactariautils.useGlobalListeners)();
|
|
126
|
+
return {
|
|
127
|
+
spinButtonProps: {
|
|
128
|
+
role: 'spinbutton',
|
|
129
|
+
'aria-valuenow': value !== undefined && !isNaN(value) ? value : undefined,
|
|
130
|
+
'aria-valuetext': ariaTextValue,
|
|
131
|
+
'aria-valuemin': minValue,
|
|
132
|
+
'aria-valuemax': maxValue,
|
|
133
|
+
'aria-disabled': isDisabled || undefined,
|
|
134
|
+
'aria-readonly': isReadOnly || undefined,
|
|
135
|
+
'aria-required': isRequired || undefined,
|
|
136
|
+
onKeyDown: onKeyDown,
|
|
137
|
+
onFocus: onFocus,
|
|
138
|
+
onBlur: onBlur
|
|
139
|
+
},
|
|
140
|
+
incrementButtonProps: {
|
|
141
|
+
onPressStart: ()=>{
|
|
142
|
+
onIncrementPressStart(400);
|
|
143
|
+
addGlobalListener(window, 'contextmenu', cancelContextMenu);
|
|
144
|
+
},
|
|
145
|
+
onPressEnd: ()=>{
|
|
146
|
+
clearAsync();
|
|
147
|
+
removeAllGlobalListeners();
|
|
148
|
+
},
|
|
149
|
+
onFocus: onFocus,
|
|
150
|
+
onBlur: onBlur
|
|
151
|
+
},
|
|
152
|
+
decrementButtonProps: {
|
|
153
|
+
onPressStart: ()=>{
|
|
154
|
+
onDecrementPressStart(400);
|
|
155
|
+
addGlobalListener(window, 'contextmenu', cancelContextMenu);
|
|
156
|
+
},
|
|
157
|
+
onPressEnd: ()=>{
|
|
158
|
+
clearAsync();
|
|
159
|
+
removeAllGlobalListeners();
|
|
160
|
+
},
|
|
161
|
+
onFocus: onFocus,
|
|
162
|
+
onBlur: onBlur
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=useSpinButton.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA4BM,SAAS,0CACd,KAAsB;IAEtB,MAAM,SAAS,CAAA,GAAA,mBAAK;IACpB,IAAI,SACF,KAAK,aACL,SAAS,YACT,QAAQ,YACR,QAAQ,cACR,UAAU,cACV,UAAU,cACV,UAAU,eACV,WAAW,mBACX,eAAe,eACf,WAAW,mBACX,eAAe,oBACf,gBAAgB,oBAChB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ACF;AACF","sources":["packages/@react-aria/spinbutton/src/useSpinButton.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {announce, clearAnnouncer} from '@react-aria/live-announcer';\nimport {AriaButtonProps} from '@react-types/button';\nimport {DOMAttributes, InputBase, RangeInputBase, Validation, ValueBase} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useEffect, useRef} from 'react';\nimport {useEffectEvent, useGlobalListeners} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\n\nexport interface SpinButtonProps extends InputBase, Validation<number>, ValueBase<number>, RangeInputBase<number> {\n textValue?: string,\n onIncrement?: () => void,\n onIncrementPage?: () => void,\n onDecrement?: () => void,\n onDecrementPage?: () => void,\n onDecrementToMin?: () => void,\n onIncrementToMax?: () => void\n}\n\nexport interface SpinbuttonAria {\n spinButtonProps: DOMAttributes,\n incrementButtonProps: AriaButtonProps,\n decrementButtonProps: AriaButtonProps\n}\n\nexport function useSpinButton(\n props: SpinButtonProps\n): SpinbuttonAria {\n const _async = useRef<number>();\n let {\n value,\n textValue,\n minValue,\n maxValue,\n isDisabled,\n isReadOnly,\n isRequired,\n onIncrement,\n onIncrementPage,\n onDecrement,\n onDecrementPage,\n onDecrementToMin,\n onIncrementToMax\n } = props;\n const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/spinbutton');\n\n const clearAsync = () => clearTimeout(_async.current);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => clearAsync();\n }, []);\n\n let onKeyDown = (e) => {\n if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || isReadOnly) {\n return;\n }\n\n switch (e.key) {\n case 'PageUp':\n if (onIncrementPage) {\n e.preventDefault();\n onIncrementPage?.();\n break;\n }\n // fallthrough!\n case 'ArrowUp':\n case 'Up':\n if (onIncrement) {\n e.preventDefault();\n onIncrement?.();\n }\n break;\n case 'PageDown':\n if (onDecrementPage) {\n e.preventDefault();\n onDecrementPage?.();\n break;\n }\n // fallthrough\n case 'ArrowDown':\n case 'Down':\n if (onDecrement) {\n e.preventDefault();\n onDecrement?.();\n }\n break;\n case 'Home':\n if (onDecrementToMin) {\n e.preventDefault();\n onDecrementToMin?.();\n }\n break;\n case 'End':\n if (onIncrementToMax) {\n e.preventDefault();\n onIncrementToMax?.();\n }\n break;\n }\n };\n\n let isFocused = useRef(false);\n let onFocus = () => {\n isFocused.current = true;\n };\n\n let onBlur = () => {\n isFocused.current = false;\n };\n\n // Replace Unicode hyphen-minus (U+002D) with minus sign (U+2212).\n // This ensures that macOS VoiceOver announces it as \"minus\" even with other characters between the minus sign\n // and the number (e.g. currency symbol). Otherwise it announces nothing because it assumes the character is a hyphen.\n // In addition, replace the empty string with the word \"Empty\" so that iOS VoiceOver does not read \"50%\" for an empty field.\n let ariaTextValue = textValue === '' ? stringFormatter.format('Empty') : (textValue || `${value}`).replace('-', '\\u2212');\n\n useEffect(() => {\n if (isFocused.current) {\n clearAnnouncer('assertive');\n announce(ariaTextValue, 'assertive');\n }\n }, [ariaTextValue]);\n\n const onIncrementPressStart = useEffectEvent(\n (initialStepDelay: number) => {\n clearAsync();\n onIncrement?.();\n // Start spinning after initial delay\n _async.current = window.setTimeout(\n () => {\n if ((maxValue === undefined || isNaN(maxValue)) || (value === undefined || isNaN(value)) || value < maxValue) {\n onIncrementPressStart(60);\n }\n },\n initialStepDelay\n );\n }\n );\n\n const onDecrementPressStart = useEffectEvent(\n (initialStepDelay: number) => {\n clearAsync();\n onDecrement?.();\n // Start spinning after initial delay\n _async.current = window.setTimeout(\n () => {\n if ((minValue === undefined || isNaN(minValue)) || (value === undefined || isNaN(value)) || value > minValue) {\n onDecrementPressStart(60);\n }\n },\n initialStepDelay\n );\n }\n );\n\n let cancelContextMenu = (e) => {\n e.preventDefault();\n };\n\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n return {\n spinButtonProps: {\n role: 'spinbutton',\n 'aria-valuenow': value !== undefined && !isNaN(value) ? value : undefined,\n 'aria-valuetext': ariaTextValue,\n 'aria-valuemin': minValue,\n 'aria-valuemax': maxValue,\n 'aria-disabled': isDisabled || undefined,\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n onKeyDown,\n onFocus,\n onBlur\n },\n incrementButtonProps: {\n onPressStart: () => {\n onIncrementPressStart(400);\n addGlobalListener(window, 'contextmenu', cancelContextMenu);\n },\n onPressEnd: () => {\n clearAsync();\n removeAllGlobalListeners();\n },\n onFocus,\n onBlur\n },\n decrementButtonProps: {\n onPressStart: () => {\n onDecrementPressStart(400);\n addGlobalListener(window, 'contextmenu', cancelContextMenu);\n },\n onPressEnd: () => {\n clearAsync();\n removeAllGlobalListeners();\n },\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useSpinButton.main.js.map"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import $5rwhf$intlStringsmodulejs from "./intlStrings.mjs";
|
|
2
|
+
import {clearAnnouncer as $5rwhf$clearAnnouncer, announce as $5rwhf$announce} from "@react-aria/live-announcer";
|
|
3
|
+
import {useRef as $5rwhf$useRef, useEffect as $5rwhf$useEffect} from "react";
|
|
4
|
+
import {useEffectEvent as $5rwhf$useEffectEvent, useGlobalListeners as $5rwhf$useGlobalListeners} from "@react-aria/utils";
|
|
5
|
+
import {useLocalizedStringFormatter as $5rwhf$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function $parcel$interopDefault(a) {
|
|
9
|
+
return a && a.__esModule ? a.default : a;
|
|
10
|
+
}
|
|
11
|
+
/*
|
|
12
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
13
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
+
* governing permissions and limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function $d2e8511e6f209edf$export$e908e06f4b8e3402(props) {
|
|
27
|
+
const _async = (0, $5rwhf$useRef)();
|
|
28
|
+
let { value: value, textValue: textValue, minValue: minValue, maxValue: maxValue, isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, onIncrement: onIncrement, onIncrementPage: onIncrementPage, onDecrement: onDecrement, onDecrementPage: onDecrementPage, onDecrementToMin: onDecrementToMin, onIncrementToMax: onIncrementToMax } = props;
|
|
29
|
+
const stringFormatter = (0, $5rwhf$useLocalizedStringFormatter)((0, ($parcel$interopDefault($5rwhf$intlStringsmodulejs))), '@react-aria/spinbutton');
|
|
30
|
+
const clearAsync = ()=>clearTimeout(_async.current);
|
|
31
|
+
// eslint-disable-next-line arrow-body-style
|
|
32
|
+
(0, $5rwhf$useEffect)(()=>{
|
|
33
|
+
return ()=>clearAsync();
|
|
34
|
+
}, []);
|
|
35
|
+
let onKeyDown = (e)=>{
|
|
36
|
+
if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || isReadOnly) return;
|
|
37
|
+
switch(e.key){
|
|
38
|
+
case 'PageUp':
|
|
39
|
+
if (onIncrementPage) {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
onIncrementPage === null || onIncrementPage === void 0 ? void 0 : onIncrementPage();
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
// fallthrough!
|
|
45
|
+
case 'ArrowUp':
|
|
46
|
+
case 'Up':
|
|
47
|
+
if (onIncrement) {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
case 'PageDown':
|
|
53
|
+
if (onDecrementPage) {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
onDecrementPage === null || onDecrementPage === void 0 ? void 0 : onDecrementPage();
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
// fallthrough
|
|
59
|
+
case 'ArrowDown':
|
|
60
|
+
case 'Down':
|
|
61
|
+
if (onDecrement) {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case 'Home':
|
|
67
|
+
if (onDecrementToMin) {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
onDecrementToMin === null || onDecrementToMin === void 0 ? void 0 : onDecrementToMin();
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
case 'End':
|
|
73
|
+
if (onIncrementToMax) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
onIncrementToMax === null || onIncrementToMax === void 0 ? void 0 : onIncrementToMax();
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
let isFocused = (0, $5rwhf$useRef)(false);
|
|
81
|
+
let onFocus = ()=>{
|
|
82
|
+
isFocused.current = true;
|
|
83
|
+
};
|
|
84
|
+
let onBlur = ()=>{
|
|
85
|
+
isFocused.current = false;
|
|
86
|
+
};
|
|
87
|
+
// Replace Unicode hyphen-minus (U+002D) with minus sign (U+2212).
|
|
88
|
+
// This ensures that macOS VoiceOver announces it as "minus" even with other characters between the minus sign
|
|
89
|
+
// and the number (e.g. currency symbol). Otherwise it announces nothing because it assumes the character is a hyphen.
|
|
90
|
+
// In addition, replace the empty string with the word "Empty" so that iOS VoiceOver does not read "50%" for an empty field.
|
|
91
|
+
let ariaTextValue = textValue === '' ? stringFormatter.format('Empty') : (textValue || `${value}`).replace('-', '\u2212');
|
|
92
|
+
(0, $5rwhf$useEffect)(()=>{
|
|
93
|
+
if (isFocused.current) {
|
|
94
|
+
(0, $5rwhf$clearAnnouncer)('assertive');
|
|
95
|
+
(0, $5rwhf$announce)(ariaTextValue, 'assertive');
|
|
96
|
+
}
|
|
97
|
+
}, [
|
|
98
|
+
ariaTextValue
|
|
99
|
+
]);
|
|
100
|
+
const onIncrementPressStart = (0, $5rwhf$useEffectEvent)((initialStepDelay)=>{
|
|
101
|
+
clearAsync();
|
|
102
|
+
onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
|
|
103
|
+
// Start spinning after initial delay
|
|
104
|
+
_async.current = window.setTimeout(()=>{
|
|
105
|
+
if (maxValue === undefined || isNaN(maxValue) || value === undefined || isNaN(value) || value < maxValue) onIncrementPressStart(60);
|
|
106
|
+
}, initialStepDelay);
|
|
107
|
+
});
|
|
108
|
+
const onDecrementPressStart = (0, $5rwhf$useEffectEvent)((initialStepDelay)=>{
|
|
109
|
+
clearAsync();
|
|
110
|
+
onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
|
|
111
|
+
// Start spinning after initial delay
|
|
112
|
+
_async.current = window.setTimeout(()=>{
|
|
113
|
+
if (minValue === undefined || isNaN(minValue) || value === undefined || isNaN(value) || value > minValue) onDecrementPressStart(60);
|
|
114
|
+
}, initialStepDelay);
|
|
115
|
+
});
|
|
116
|
+
let cancelContextMenu = (e)=>{
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
};
|
|
119
|
+
let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $5rwhf$useGlobalListeners)();
|
|
120
|
+
return {
|
|
121
|
+
spinButtonProps: {
|
|
122
|
+
role: 'spinbutton',
|
|
123
|
+
'aria-valuenow': value !== undefined && !isNaN(value) ? value : undefined,
|
|
124
|
+
'aria-valuetext': ariaTextValue,
|
|
125
|
+
'aria-valuemin': minValue,
|
|
126
|
+
'aria-valuemax': maxValue,
|
|
127
|
+
'aria-disabled': isDisabled || undefined,
|
|
128
|
+
'aria-readonly': isReadOnly || undefined,
|
|
129
|
+
'aria-required': isRequired || undefined,
|
|
130
|
+
onKeyDown: onKeyDown,
|
|
131
|
+
onFocus: onFocus,
|
|
132
|
+
onBlur: onBlur
|
|
133
|
+
},
|
|
134
|
+
incrementButtonProps: {
|
|
135
|
+
onPressStart: ()=>{
|
|
136
|
+
onIncrementPressStart(400);
|
|
137
|
+
addGlobalListener(window, 'contextmenu', cancelContextMenu);
|
|
138
|
+
},
|
|
139
|
+
onPressEnd: ()=>{
|
|
140
|
+
clearAsync();
|
|
141
|
+
removeAllGlobalListeners();
|
|
142
|
+
},
|
|
143
|
+
onFocus: onFocus,
|
|
144
|
+
onBlur: onBlur
|
|
145
|
+
},
|
|
146
|
+
decrementButtonProps: {
|
|
147
|
+
onPressStart: ()=>{
|
|
148
|
+
onDecrementPressStart(400);
|
|
149
|
+
addGlobalListener(window, 'contextmenu', cancelContextMenu);
|
|
150
|
+
},
|
|
151
|
+
onPressEnd: ()=>{
|
|
152
|
+
clearAsync();
|
|
153
|
+
removeAllGlobalListeners();
|
|
154
|
+
},
|
|
155
|
+
onFocus: onFocus,
|
|
156
|
+
onBlur: onBlur
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
export {$d2e8511e6f209edf$export$e908e06f4b8e3402 as useSpinButton};
|
|
163
|
+
//# sourceMappingURL=useSpinButton.module.js.map
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import $5rwhf$intlStringsmodulejs from "./intlStrings.module.js";
|
|
2
|
+
import {clearAnnouncer as $5rwhf$clearAnnouncer, announce as $5rwhf$announce} from "@react-aria/live-announcer";
|
|
3
|
+
import {useRef as $5rwhf$useRef, useEffect as $5rwhf$useEffect} from "react";
|
|
4
|
+
import {useEffectEvent as $5rwhf$useEffectEvent, useGlobalListeners as $5rwhf$useGlobalListeners} from "@react-aria/utils";
|
|
5
|
+
import {useLocalizedStringFormatter as $5rwhf$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function $parcel$interopDefault(a) {
|
|
9
|
+
return a && a.__esModule ? a.default : a;
|
|
10
|
+
}
|
|
11
|
+
/*
|
|
12
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
13
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
+
* governing permissions and limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function $d2e8511e6f209edf$export$e908e06f4b8e3402(props) {
|
|
27
|
+
const _async = (0, $5rwhf$useRef)();
|
|
28
|
+
let { value: value, textValue: textValue, minValue: minValue, maxValue: maxValue, isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, onIncrement: onIncrement, onIncrementPage: onIncrementPage, onDecrement: onDecrement, onDecrementPage: onDecrementPage, onDecrementToMin: onDecrementToMin, onIncrementToMax: onIncrementToMax } = props;
|
|
29
|
+
const stringFormatter = (0, $5rwhf$useLocalizedStringFormatter)((0, ($parcel$interopDefault($5rwhf$intlStringsmodulejs))), '@react-aria/spinbutton');
|
|
30
|
+
const clearAsync = ()=>clearTimeout(_async.current);
|
|
31
|
+
// eslint-disable-next-line arrow-body-style
|
|
32
|
+
(0, $5rwhf$useEffect)(()=>{
|
|
33
|
+
return ()=>clearAsync();
|
|
34
|
+
}, []);
|
|
35
|
+
let onKeyDown = (e)=>{
|
|
36
|
+
if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || isReadOnly) return;
|
|
37
|
+
switch(e.key){
|
|
38
|
+
case 'PageUp':
|
|
39
|
+
if (onIncrementPage) {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
onIncrementPage === null || onIncrementPage === void 0 ? void 0 : onIncrementPage();
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
// fallthrough!
|
|
45
|
+
case 'ArrowUp':
|
|
46
|
+
case 'Up':
|
|
47
|
+
if (onIncrement) {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
case 'PageDown':
|
|
53
|
+
if (onDecrementPage) {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
onDecrementPage === null || onDecrementPage === void 0 ? void 0 : onDecrementPage();
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
// fallthrough
|
|
59
|
+
case 'ArrowDown':
|
|
60
|
+
case 'Down':
|
|
61
|
+
if (onDecrement) {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case 'Home':
|
|
67
|
+
if (onDecrementToMin) {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
onDecrementToMin === null || onDecrementToMin === void 0 ? void 0 : onDecrementToMin();
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
case 'End':
|
|
73
|
+
if (onIncrementToMax) {
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
onIncrementToMax === null || onIncrementToMax === void 0 ? void 0 : onIncrementToMax();
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
let isFocused = (0, $5rwhf$useRef)(false);
|
|
81
|
+
let onFocus = ()=>{
|
|
82
|
+
isFocused.current = true;
|
|
83
|
+
};
|
|
84
|
+
let onBlur = ()=>{
|
|
85
|
+
isFocused.current = false;
|
|
86
|
+
};
|
|
87
|
+
// Replace Unicode hyphen-minus (U+002D) with minus sign (U+2212).
|
|
88
|
+
// This ensures that macOS VoiceOver announces it as "minus" even with other characters between the minus sign
|
|
89
|
+
// and the number (e.g. currency symbol). Otherwise it announces nothing because it assumes the character is a hyphen.
|
|
90
|
+
// In addition, replace the empty string with the word "Empty" so that iOS VoiceOver does not read "50%" for an empty field.
|
|
91
|
+
let ariaTextValue = textValue === '' ? stringFormatter.format('Empty') : (textValue || `${value}`).replace('-', '\u2212');
|
|
92
|
+
(0, $5rwhf$useEffect)(()=>{
|
|
93
|
+
if (isFocused.current) {
|
|
94
|
+
(0, $5rwhf$clearAnnouncer)('assertive');
|
|
95
|
+
(0, $5rwhf$announce)(ariaTextValue, 'assertive');
|
|
96
|
+
}
|
|
97
|
+
}, [
|
|
98
|
+
ariaTextValue
|
|
99
|
+
]);
|
|
100
|
+
const onIncrementPressStart = (0, $5rwhf$useEffectEvent)((initialStepDelay)=>{
|
|
101
|
+
clearAsync();
|
|
102
|
+
onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
|
|
103
|
+
// Start spinning after initial delay
|
|
104
|
+
_async.current = window.setTimeout(()=>{
|
|
105
|
+
if (maxValue === undefined || isNaN(maxValue) || value === undefined || isNaN(value) || value < maxValue) onIncrementPressStart(60);
|
|
106
|
+
}, initialStepDelay);
|
|
107
|
+
});
|
|
108
|
+
const onDecrementPressStart = (0, $5rwhf$useEffectEvent)((initialStepDelay)=>{
|
|
109
|
+
clearAsync();
|
|
110
|
+
onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
|
|
111
|
+
// Start spinning after initial delay
|
|
112
|
+
_async.current = window.setTimeout(()=>{
|
|
113
|
+
if (minValue === undefined || isNaN(minValue) || value === undefined || isNaN(value) || value > minValue) onDecrementPressStart(60);
|
|
114
|
+
}, initialStepDelay);
|
|
115
|
+
});
|
|
116
|
+
let cancelContextMenu = (e)=>{
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
};
|
|
119
|
+
let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $5rwhf$useGlobalListeners)();
|
|
120
|
+
return {
|
|
121
|
+
spinButtonProps: {
|
|
122
|
+
role: 'spinbutton',
|
|
123
|
+
'aria-valuenow': value !== undefined && !isNaN(value) ? value : undefined,
|
|
124
|
+
'aria-valuetext': ariaTextValue,
|
|
125
|
+
'aria-valuemin': minValue,
|
|
126
|
+
'aria-valuemax': maxValue,
|
|
127
|
+
'aria-disabled': isDisabled || undefined,
|
|
128
|
+
'aria-readonly': isReadOnly || undefined,
|
|
129
|
+
'aria-required': isRequired || undefined,
|
|
130
|
+
onKeyDown: onKeyDown,
|
|
131
|
+
onFocus: onFocus,
|
|
132
|
+
onBlur: onBlur
|
|
133
|
+
},
|
|
134
|
+
incrementButtonProps: {
|
|
135
|
+
onPressStart: ()=>{
|
|
136
|
+
onIncrementPressStart(400);
|
|
137
|
+
addGlobalListener(window, 'contextmenu', cancelContextMenu);
|
|
138
|
+
},
|
|
139
|
+
onPressEnd: ()=>{
|
|
140
|
+
clearAsync();
|
|
141
|
+
removeAllGlobalListeners();
|
|
142
|
+
},
|
|
143
|
+
onFocus: onFocus,
|
|
144
|
+
onBlur: onBlur
|
|
145
|
+
},
|
|
146
|
+
decrementButtonProps: {
|
|
147
|
+
onPressStart: ()=>{
|
|
148
|
+
onDecrementPressStart(400);
|
|
149
|
+
addGlobalListener(window, 'contextmenu', cancelContextMenu);
|
|
150
|
+
},
|
|
151
|
+
onPressEnd: ()=>{
|
|
152
|
+
clearAsync();
|
|
153
|
+
removeAllGlobalListeners();
|
|
154
|
+
},
|
|
155
|
+
onFocus: onFocus,
|
|
156
|
+
onBlur: onBlur
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
export {$d2e8511e6f209edf$export$e908e06f4b8e3402 as useSpinButton};
|
|
163
|
+
//# sourceMappingURL=useSpinButton.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA4BM,SAAS,0CACd,KAAsB;IAEtB,MAAM,SAAS,CAAA,GAAA,aAAK;IACpB,IAAI,SACF,KAAK,aACL,SAAS,YACT,QAAQ,YACR,QAAQ,cACR,UAAU,cACV,UAAU,cACV,UAAU,eACV,WAAW,mBACX,eAAe,eACf,WAAW,mBACX,eAAe,oBACf,gBAAgB,oBAChB,gBAAgB,EACjB,GAAG;IACJ,MAAM,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAElE,MAAM,aAAa,IAAM,aAAa,OAAO,OAAO;IAEpD,4CAA4C;IAC5C,CAAA,GAAA,gBAAQ,EAAE;QACR,OAAO,IAAM;IACf,GAAG,EAAE;IAEL,IAAI,YAAY,CAAC;QACf,IAAI,EAAE,OAAO,IAAI,EAAE,OAAO,IAAI,EAAE,QAAQ,IAAI,EAAE,MAAM,IAAI,YACtD;QAGF,OAAQ,EAAE,GAAG;YACX,KAAK;gBACH,IAAI,iBAAiB;oBACnB,EAAE,cAAc;oBAChB,4BAAA,sCAAA;oBACA;gBACF;YACF,eAAe;YACf,KAAK;YACL,KAAK;gBACH,IAAI,aAAa;oBACf,EAAE,cAAc;oBAChB,wBAAA,kCAAA;gBACF;gBACA;YACF,KAAK;gBACH,IAAI,iBAAiB;oBACnB,EAAE,cAAc;oBAChB,4BAAA,sCAAA;oBACA;gBACF;YACF,cAAc;YACd,KAAK;YACL,KAAK;gBACH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QACvB,EAAE,cAAc;IAClB;IAEA,IAAI,qBAAC,iBAAiB,4BAAE,wBAAwB,EAAC,GAAG,CAAA,GAAA,yBAAiB;IAErE,OAAO;QACL,iBAAiB;YACf,MAAM;YACN,iBAAiB,UAAU,aAAa,CAAC,MAAM,SAAS,QAAQ;YAChE,kBAAkB;YAClB,iBAAiB;YACjB,iBAAiB;YACjB,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;YAC/B,iBAAiB,cAAc;uBAC/B;qBACA;oBACA;QACF;QACA,sBAAsB;YACpB,cAAc;gBACZ,sBAAsB;gBACtB,kBAAkB,QAAQ,eAAe;YAC3C;YACA,YAAY;gBACV;gBACA;YACF;qBACA;oBACA;QACF;QACA,sBAAsB;YACpB,cAAc;gBACZ,sBAAsB;gBACtB,kBAAkB,QAAQ,eAAe;YAC3C;YACA,YAAY;gBACV;gBACA;YACF;qBACA;oBACA;QACF;IACF;AACF","sources":["packages/@react-aria/spinbutton/src/useSpinButton.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {announce, clearAnnouncer} from '@react-aria/live-announcer';\nimport {AriaButtonProps} from '@react-types/button';\nimport {DOMAttributes, InputBase, RangeInputBase, Validation, ValueBase} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useEffect, useRef} from 'react';\nimport {useEffectEvent, useGlobalListeners} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\n\nexport interface SpinButtonProps extends InputBase, Validation<number>, ValueBase<number>, RangeInputBase<number> {\n textValue?: string,\n onIncrement?: () => void,\n onIncrementPage?: () => void,\n onDecrement?: () => void,\n onDecrementPage?: () => void,\n onDecrementToMin?: () => void,\n onIncrementToMax?: () => void\n}\n\nexport interface SpinbuttonAria {\n spinButtonProps: DOMAttributes,\n incrementButtonProps: AriaButtonProps,\n decrementButtonProps: AriaButtonProps\n}\n\nexport function useSpinButton(\n props: SpinButtonProps\n): SpinbuttonAria {\n const _async = useRef<number>();\n let {\n value,\n textValue,\n minValue,\n maxValue,\n isDisabled,\n isReadOnly,\n isRequired,\n onIncrement,\n onIncrementPage,\n onDecrement,\n onDecrementPage,\n onDecrementToMin,\n onIncrementToMax\n } = props;\n const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/spinbutton');\n\n const clearAsync = () => clearTimeout(_async.current);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => clearAsync();\n }, []);\n\n let onKeyDown = (e) => {\n if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || isReadOnly) {\n return;\n }\n\n switch (e.key) {\n case 'PageUp':\n if (onIncrementPage) {\n e.preventDefault();\n onIncrementPage?.();\n break;\n }\n // fallthrough!\n case 'ArrowUp':\n case 'Up':\n if (onIncrement) {\n e.preventDefault();\n onIncrement?.();\n }\n break;\n case 'PageDown':\n if (onDecrementPage) {\n e.preventDefault();\n onDecrementPage?.();\n break;\n }\n // fallthrough\n case 'ArrowDown':\n case 'Down':\n if (onDecrement) {\n e.preventDefault();\n onDecrement?.();\n }\n break;\n case 'Home':\n if (onDecrementToMin) {\n e.preventDefault();\n onDecrementToMin?.();\n }\n break;\n case 'End':\n if (onIncrementToMax) {\n e.preventDefault();\n onIncrementToMax?.();\n }\n break;\n }\n };\n\n let isFocused = useRef(false);\n let onFocus = () => {\n isFocused.current = true;\n };\n\n let onBlur = () => {\n isFocused.current = false;\n };\n\n // Replace Unicode hyphen-minus (U+002D) with minus sign (U+2212).\n // This ensures that macOS VoiceOver announces it as \"minus\" even with other characters between the minus sign\n // and the number (e.g. currency symbol). Otherwise it announces nothing because it assumes the character is a hyphen.\n // In addition, replace the empty string with the word \"Empty\" so that iOS VoiceOver does not read \"50%\" for an empty field.\n let ariaTextValue = textValue === '' ? stringFormatter.format('Empty') : (textValue || `${value}`).replace('-', '\\u2212');\n\n useEffect(() => {\n if (isFocused.current) {\n clearAnnouncer('assertive');\n announce(ariaTextValue, 'assertive');\n }\n }, [ariaTextValue]);\n\n const onIncrementPressStart = useEffectEvent(\n (initialStepDelay: number) => {\n clearAsync();\n onIncrement?.();\n // Start spinning after initial delay\n _async.current = window.setTimeout(\n () => {\n if ((maxValue === undefined || isNaN(maxValue)) || (value === undefined || isNaN(value)) || value < maxValue) {\n onIncrementPressStart(60);\n }\n },\n initialStepDelay\n );\n }\n );\n\n const onDecrementPressStart = useEffectEvent(\n (initialStepDelay: number) => {\n clearAsync();\n onDecrement?.();\n // Start spinning after initial delay\n _async.current = window.setTimeout(\n () => {\n if ((minValue === undefined || isNaN(minValue)) || (value === undefined || isNaN(value)) || value > minValue) {\n onDecrementPressStart(60);\n }\n },\n initialStepDelay\n );\n }\n );\n\n let cancelContextMenu = (e) => {\n e.preventDefault();\n };\n\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n return {\n spinButtonProps: {\n role: 'spinbutton',\n 'aria-valuenow': value !== undefined && !isNaN(value) ? value : undefined,\n 'aria-valuetext': ariaTextValue,\n 'aria-valuemin': minValue,\n 'aria-valuemax': maxValue,\n 'aria-disabled': isDisabled || undefined,\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n onKeyDown,\n onFocus,\n onBlur\n },\n incrementButtonProps: {\n onPressStart: () => {\n onIncrementPressStart(400);\n addGlobalListener(window, 'contextmenu', cancelContextMenu);\n },\n onPressEnd: () => {\n clearAsync();\n removeAllGlobalListeners();\n },\n onFocus,\n onBlur\n },\n decrementButtonProps: {\n onPressStart: () => {\n onDecrementPressStart(400);\n addGlobalListener(window, 'contextmenu', cancelContextMenu);\n },\n onPressEnd: () => {\n clearAsync();\n removeAllGlobalListeners();\n },\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useSpinButton.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/spinbutton",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.5",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/i18n": "^3.
|
|
26
|
-
"@react-aria/live-announcer": "^3.3.
|
|
27
|
-
"@react-aria/utils": "^3.
|
|
28
|
-
"@react-types/button": "^3.9.
|
|
29
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/i18n": "^3.11.1",
|
|
26
|
+
"@react-aria/live-announcer": "^3.3.4",
|
|
27
|
+
"@react-aria/utils": "^3.24.1",
|
|
28
|
+
"@react-types/button": "^3.9.4",
|
|
29
|
+
"@react-types/shared": "^3.23.1",
|
|
30
30
|
"@swc/helpers": "^0.5.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
|
|
40
40
|
}
|