@react-spectrum/button 3.17.6 → 3.18.0

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 (228) hide show
  1. package/dist/import.mjs +7 -7
  2. package/dist/main.js +12 -12
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +7 -7
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +10 -0
  7. package/package.json +12 -35
  8. package/src/index.ts +11 -7
  9. package/dist/ActionButton.main.js +0 -93
  10. package/dist/ActionButton.main.js.map +0 -1
  11. package/dist/ActionButton.mjs +0 -88
  12. package/dist/ActionButton.module.js +0 -88
  13. package/dist/ActionButton.module.js.map +0 -1
  14. package/dist/Button.main.js +0 -181
  15. package/dist/Button.main.js.map +0 -1
  16. package/dist/Button.mjs +0 -176
  17. package/dist/Button.module.js +0 -176
  18. package/dist/Button.module.js.map +0 -1
  19. package/dist/ClearButton.main.js +0 -75
  20. package/dist/ClearButton.main.js.map +0 -1
  21. package/dist/ClearButton.mjs +0 -70
  22. package/dist/ClearButton.module.js +0 -70
  23. package/dist/ClearButton.module.js.map +0 -1
  24. package/dist/FieldButton.main.js +0 -70
  25. package/dist/FieldButton.main.js.map +0 -1
  26. package/dist/FieldButton.mjs +0 -65
  27. package/dist/FieldButton.module.js +0 -65
  28. package/dist/FieldButton.module.js.map +0 -1
  29. package/dist/LogicButton.main.js +0 -67
  30. package/dist/LogicButton.main.js.map +0 -1
  31. package/dist/LogicButton.mjs +0 -62
  32. package/dist/LogicButton.module.js +0 -62
  33. package/dist/LogicButton.module.js.map +0 -1
  34. package/dist/ToggleButton.main.js +0 -86
  35. package/dist/ToggleButton.main.js.map +0 -1
  36. package/dist/ToggleButton.mjs +0 -81
  37. package/dist/ToggleButton.module.js +0 -81
  38. package/dist/ToggleButton.module.js.map +0 -1
  39. package/dist/ar-AE.main.js +0 -6
  40. package/dist/ar-AE.main.js.map +0 -1
  41. package/dist/ar-AE.mjs +0 -8
  42. package/dist/ar-AE.module.js +0 -8
  43. package/dist/ar-AE.module.js.map +0 -1
  44. package/dist/bg-BG.main.js +0 -6
  45. package/dist/bg-BG.main.js.map +0 -1
  46. package/dist/bg-BG.mjs +0 -8
  47. package/dist/bg-BG.module.js +0 -8
  48. package/dist/bg-BG.module.js.map +0 -1
  49. package/dist/button.c18453ac.css +0 -1669
  50. package/dist/button.c18453ac.css.map +0 -1
  51. package/dist/button_vars_css.main.js +0 -125
  52. package/dist/button_vars_css.main.js.map +0 -1
  53. package/dist/button_vars_css.mjs +0 -127
  54. package/dist/button_vars_css.module.js +0 -127
  55. package/dist/button_vars_css.module.js.map +0 -1
  56. package/dist/cs-CZ.main.js +0 -6
  57. package/dist/cs-CZ.main.js.map +0 -1
  58. package/dist/cs-CZ.mjs +0 -8
  59. package/dist/cs-CZ.module.js +0 -8
  60. package/dist/cs-CZ.module.js.map +0 -1
  61. package/dist/da-DK.main.js +0 -6
  62. package/dist/da-DK.main.js.map +0 -1
  63. package/dist/da-DK.mjs +0 -8
  64. package/dist/da-DK.module.js +0 -8
  65. package/dist/da-DK.module.js.map +0 -1
  66. package/dist/de-DE.main.js +0 -6
  67. package/dist/de-DE.main.js.map +0 -1
  68. package/dist/de-DE.mjs +0 -8
  69. package/dist/de-DE.module.js +0 -8
  70. package/dist/de-DE.module.js.map +0 -1
  71. package/dist/el-GR.main.js +0 -6
  72. package/dist/el-GR.main.js.map +0 -1
  73. package/dist/el-GR.mjs +0 -8
  74. package/dist/el-GR.module.js +0 -8
  75. package/dist/el-GR.module.js.map +0 -1
  76. package/dist/en-US.main.js +0 -6
  77. package/dist/en-US.main.js.map +0 -1
  78. package/dist/en-US.mjs +0 -8
  79. package/dist/en-US.module.js +0 -8
  80. package/dist/en-US.module.js.map +0 -1
  81. package/dist/es-ES.main.js +0 -6
  82. package/dist/es-ES.main.js.map +0 -1
  83. package/dist/es-ES.mjs +0 -8
  84. package/dist/es-ES.module.js +0 -8
  85. package/dist/es-ES.module.js.map +0 -1
  86. package/dist/et-EE.main.js +0 -6
  87. package/dist/et-EE.main.js.map +0 -1
  88. package/dist/et-EE.mjs +0 -8
  89. package/dist/et-EE.module.js +0 -8
  90. package/dist/et-EE.module.js.map +0 -1
  91. package/dist/fi-FI.main.js +0 -6
  92. package/dist/fi-FI.main.js.map +0 -1
  93. package/dist/fi-FI.mjs +0 -8
  94. package/dist/fi-FI.module.js +0 -8
  95. package/dist/fi-FI.module.js.map +0 -1
  96. package/dist/fr-FR.main.js +0 -6
  97. package/dist/fr-FR.main.js.map +0 -1
  98. package/dist/fr-FR.mjs +0 -8
  99. package/dist/fr-FR.module.js +0 -8
  100. package/dist/fr-FR.module.js.map +0 -1
  101. package/dist/he-IL.main.js +0 -6
  102. package/dist/he-IL.main.js.map +0 -1
  103. package/dist/he-IL.mjs +0 -8
  104. package/dist/he-IL.module.js +0 -8
  105. package/dist/he-IL.module.js.map +0 -1
  106. package/dist/hr-HR.main.js +0 -6
  107. package/dist/hr-HR.main.js.map +0 -1
  108. package/dist/hr-HR.mjs +0 -8
  109. package/dist/hr-HR.module.js +0 -8
  110. package/dist/hr-HR.module.js.map +0 -1
  111. package/dist/hu-HU.main.js +0 -6
  112. package/dist/hu-HU.main.js.map +0 -1
  113. package/dist/hu-HU.mjs +0 -8
  114. package/dist/hu-HU.module.js +0 -8
  115. package/dist/hu-HU.module.js.map +0 -1
  116. package/dist/intlStrings.main.js +0 -108
  117. package/dist/intlStrings.main.js.map +0 -1
  118. package/dist/intlStrings.mjs +0 -110
  119. package/dist/intlStrings.module.js +0 -110
  120. package/dist/intlStrings.module.js.map +0 -1
  121. package/dist/it-IT.main.js +0 -6
  122. package/dist/it-IT.main.js.map +0 -1
  123. package/dist/it-IT.mjs +0 -8
  124. package/dist/it-IT.module.js +0 -8
  125. package/dist/it-IT.module.js.map +0 -1
  126. package/dist/ja-JP.main.js +0 -6
  127. package/dist/ja-JP.main.js.map +0 -1
  128. package/dist/ja-JP.mjs +0 -8
  129. package/dist/ja-JP.module.js +0 -8
  130. package/dist/ja-JP.module.js.map +0 -1
  131. package/dist/ko-KR.main.js +0 -6
  132. package/dist/ko-KR.main.js.map +0 -1
  133. package/dist/ko-KR.mjs +0 -8
  134. package/dist/ko-KR.module.js +0 -8
  135. package/dist/ko-KR.module.js.map +0 -1
  136. package/dist/lt-LT.main.js +0 -6
  137. package/dist/lt-LT.main.js.map +0 -1
  138. package/dist/lt-LT.mjs +0 -8
  139. package/dist/lt-LT.module.js +0 -8
  140. package/dist/lt-LT.module.js.map +0 -1
  141. package/dist/lv-LV.main.js +0 -6
  142. package/dist/lv-LV.main.js.map +0 -1
  143. package/dist/lv-LV.mjs +0 -8
  144. package/dist/lv-LV.module.js +0 -8
  145. package/dist/lv-LV.module.js.map +0 -1
  146. package/dist/nb-NO.main.js +0 -6
  147. package/dist/nb-NO.main.js.map +0 -1
  148. package/dist/nb-NO.mjs +0 -8
  149. package/dist/nb-NO.module.js +0 -8
  150. package/dist/nb-NO.module.js.map +0 -1
  151. package/dist/nl-NL.main.js +0 -6
  152. package/dist/nl-NL.main.js.map +0 -1
  153. package/dist/nl-NL.mjs +0 -8
  154. package/dist/nl-NL.module.js +0 -8
  155. package/dist/nl-NL.module.js.map +0 -1
  156. package/dist/pl-PL.main.js +0 -6
  157. package/dist/pl-PL.main.js.map +0 -1
  158. package/dist/pl-PL.mjs +0 -8
  159. package/dist/pl-PL.module.js +0 -8
  160. package/dist/pl-PL.module.js.map +0 -1
  161. package/dist/pt-BR.main.js +0 -6
  162. package/dist/pt-BR.main.js.map +0 -1
  163. package/dist/pt-BR.mjs +0 -8
  164. package/dist/pt-BR.module.js +0 -8
  165. package/dist/pt-BR.module.js.map +0 -1
  166. package/dist/pt-PT.main.js +0 -6
  167. package/dist/pt-PT.main.js.map +0 -1
  168. package/dist/pt-PT.mjs +0 -8
  169. package/dist/pt-PT.module.js +0 -8
  170. package/dist/pt-PT.module.js.map +0 -1
  171. package/dist/ro-RO.main.js +0 -6
  172. package/dist/ro-RO.main.js.map +0 -1
  173. package/dist/ro-RO.mjs +0 -8
  174. package/dist/ro-RO.module.js +0 -8
  175. package/dist/ro-RO.module.js.map +0 -1
  176. package/dist/ru-RU.main.js +0 -6
  177. package/dist/ru-RU.main.js.map +0 -1
  178. package/dist/ru-RU.mjs +0 -8
  179. package/dist/ru-RU.module.js +0 -8
  180. package/dist/ru-RU.module.js.map +0 -1
  181. package/dist/sk-SK.main.js +0 -6
  182. package/dist/sk-SK.main.js.map +0 -1
  183. package/dist/sk-SK.mjs +0 -8
  184. package/dist/sk-SK.module.js +0 -8
  185. package/dist/sk-SK.module.js.map +0 -1
  186. package/dist/sl-SI.main.js +0 -6
  187. package/dist/sl-SI.main.js.map +0 -1
  188. package/dist/sl-SI.mjs +0 -8
  189. package/dist/sl-SI.module.js +0 -8
  190. package/dist/sl-SI.module.js.map +0 -1
  191. package/dist/sr-SP.main.js +0 -6
  192. package/dist/sr-SP.main.js.map +0 -1
  193. package/dist/sr-SP.mjs +0 -8
  194. package/dist/sr-SP.module.js +0 -8
  195. package/dist/sr-SP.module.js.map +0 -1
  196. package/dist/sv-SE.main.js +0 -6
  197. package/dist/sv-SE.main.js.map +0 -1
  198. package/dist/sv-SE.mjs +0 -8
  199. package/dist/sv-SE.module.js +0 -8
  200. package/dist/sv-SE.module.js.map +0 -1
  201. package/dist/tr-TR.main.js +0 -6
  202. package/dist/tr-TR.main.js.map +0 -1
  203. package/dist/tr-TR.mjs +0 -8
  204. package/dist/tr-TR.module.js +0 -8
  205. package/dist/tr-TR.module.js.map +0 -1
  206. package/dist/types.d.ts +0 -44
  207. package/dist/types.d.ts.map +0 -1
  208. package/dist/uk-UA.main.js +0 -6
  209. package/dist/uk-UA.main.js.map +0 -1
  210. package/dist/uk-UA.mjs +0 -8
  211. package/dist/uk-UA.module.js +0 -8
  212. package/dist/uk-UA.module.js.map +0 -1
  213. package/dist/zh-CN.main.js +0 -6
  214. package/dist/zh-CN.main.js.map +0 -1
  215. package/dist/zh-CN.mjs +0 -8
  216. package/dist/zh-CN.module.js +0 -8
  217. package/dist/zh-CN.module.js.map +0 -1
  218. package/dist/zh-TW.main.js +0 -6
  219. package/dist/zh-TW.main.js.map +0 -1
  220. package/dist/zh-TW.mjs +0 -8
  221. package/dist/zh-TW.module.js +0 -8
  222. package/dist/zh-TW.module.js.map +0 -1
  223. package/src/ActionButton.tsx +0 -104
  224. package/src/Button.tsx +0 -207
  225. package/src/ClearButton.tsx +0 -81
  226. package/src/FieldButton.tsx +0 -81
  227. package/src/LogicButton.tsx +0 -64
  228. package/src/ToggleButton.tsx +0 -90
@@ -1 +0,0 @@
1
- {"mappings":";AAAA,4BAAiB;IAAG,WAAW,CAAC,8EAAY,CAAC;AAC7C","sources":["packages/@react-spectrum/button/intl/uk-UA.json"],"sourcesContent":["{\n \"pending\": \"в очікуванні\"\n}\n"],"names":[],"version":3,"file":"uk-UA.module.js.map"}
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- "pending": `\u{5F85}\u{5904}\u{7406}`
3
- };
4
-
5
-
6
- //# sourceMappingURL=zh-CN.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":"AAAA,iBAAiB;IAAG,WAAW,CAAC,wBAAG,CAAC;AACpC","sources":["packages/@react-spectrum/button/intl/zh-CN.json"],"sourcesContent":["{\n \"pending\": \"待处理\"\n}\n"],"names":[],"version":3,"file":"zh-CN.main.js.map"}
package/dist/zh-CN.mjs DELETED
@@ -1,8 +0,0 @@
1
- var $6e4b63af77288b7a$exports = {};
2
- $6e4b63af77288b7a$exports = {
3
- "pending": `\u{5F85}\u{5904}\u{7406}`
4
- };
5
-
6
-
7
- export {$6e4b63af77288b7a$exports as default};
8
- //# sourceMappingURL=zh-CN.module.js.map
@@ -1,8 +0,0 @@
1
- var $6e4b63af77288b7a$exports = {};
2
- $6e4b63af77288b7a$exports = {
3
- "pending": `\u{5F85}\u{5904}\u{7406}`
4
- };
5
-
6
-
7
- export {$6e4b63af77288b7a$exports as default};
8
- //# sourceMappingURL=zh-CN.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";AAAA,4BAAiB;IAAG,WAAW,CAAC,wBAAG,CAAC;AACpC","sources":["packages/@react-spectrum/button/intl/zh-CN.json"],"sourcesContent":["{\n \"pending\": \"待处理\"\n}\n"],"names":[],"version":3,"file":"zh-CN.module.js.map"}
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- "pending": `\u{5F85}\u{8655}\u{7406}`
3
- };
4
-
5
-
6
- //# sourceMappingURL=zh-TW.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":"AAAA,iBAAiB;IAAG,WAAW,CAAC,wBAAG,CAAC;AACpC","sources":["packages/@react-spectrum/button/intl/zh-TW.json"],"sourcesContent":["{\n \"pending\": \"待處理\"\n}\n"],"names":[],"version":3,"file":"zh-TW.main.js.map"}
package/dist/zh-TW.mjs DELETED
@@ -1,8 +0,0 @@
1
- var $be993a68bccef72a$exports = {};
2
- $be993a68bccef72a$exports = {
3
- "pending": `\u{5F85}\u{8655}\u{7406}`
4
- };
5
-
6
-
7
- export {$be993a68bccef72a$exports as default};
8
- //# sourceMappingURL=zh-TW.module.js.map
@@ -1,8 +0,0 @@
1
- var $be993a68bccef72a$exports = {};
2
- $be993a68bccef72a$exports = {
3
- "pending": `\u{5F85}\u{8655}\u{7406}`
4
- };
5
-
6
-
7
- export {$be993a68bccef72a$exports as default};
8
- //# sourceMappingURL=zh-TW.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";AAAA,4BAAiB;IAAG,WAAW,CAAC,wBAAG,CAAC;AACpC","sources":["packages/@react-spectrum/button/intl/zh-TW.json"],"sourcesContent":["{\n \"pending\": \"待處理\"\n}\n"],"names":[],"version":3,"file":"zh-TW.module.js.map"}
@@ -1,104 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {classNames, ClearSlots, SlotProvider, useFocusableRef, useSlotProps, useStyleProps} from '@react-spectrum/utils';
14
- import CornerTriangle from '@spectrum-icons/ui/CornerTriangle';
15
- import {FocusableRef} from '@react-types/shared';
16
- import {FocusRing} from '@react-aria/focus';
17
- import {mergeProps} from '@react-aria/utils';
18
- import React from 'react';
19
- import {SpectrumActionButtonProps} from '@react-types/button';
20
- import styles from '@adobe/spectrum-css-temp/components/button/vars.css';
21
- import {Text} from '@react-spectrum/text';
22
- import {useButton} from '@react-aria/button';
23
- import {useHover} from '@react-aria/interactions';
24
- import {useProviderProps} from '@react-spectrum/provider';
25
-
26
- /**
27
- * ActionButtons allow users to perform an action.
28
- * They’re used for similar, task-based options within a workflow, and are ideal for interfaces where buttons aren’t meant to draw a lot of attention.
29
- */
30
- export const ActionButton = React.forwardRef(function ActionButton(props: SpectrumActionButtonProps, ref: FocusableRef<HTMLButtonElement>) {
31
- props = useProviderProps(props);
32
- props = useSlotProps(props, 'actionButton');
33
- let textProps = useSlotProps({UNSAFE_className: classNames(styles, 'spectrum-ActionButton-label')}, 'text');
34
-
35
- let {
36
- isQuiet,
37
- isDisabled,
38
- staticColor,
39
- children,
40
- autoFocus,
41
- // @ts-ignore (private)
42
- holdAffordance,
43
- // @ts-ignore (private)
44
- hideButtonText,
45
- ...otherProps
46
- } = props;
47
-
48
- let domRef = useFocusableRef(ref);
49
- let {buttonProps, isPressed} = useButton(props, domRef);
50
- let {hoverProps, isHovered} = useHover({isDisabled});
51
- let {styleProps} = useStyleProps(otherProps);
52
- let isTextOnly = React.Children.toArray(props.children).every(c => !React.isValidElement(c));
53
-
54
- return (
55
- <FocusRing focusRingClass={classNames(styles, 'focus-ring')} autoFocus={autoFocus}>
56
- <button
57
- {...styleProps}
58
- {...mergeProps(buttonProps, hoverProps)}
59
- ref={domRef}
60
- className={
61
- classNames(
62
- styles,
63
- 'spectrum-ActionButton',
64
- {
65
- 'spectrum-ActionButton--quiet': isQuiet,
66
- 'spectrum-ActionButton--staticColor': !!staticColor,
67
- 'spectrum-ActionButton--staticWhite': staticColor === 'white',
68
- 'spectrum-ActionButton--staticBlack': staticColor === 'black',
69
- 'is-active': isPressed,
70
- 'is-disabled': isDisabled,
71
- 'is-hovered': isHovered
72
- },
73
- styleProps.className
74
- )
75
- }>
76
- {holdAffordance &&
77
- <CornerTriangle UNSAFE_className={classNames(styles, 'spectrum-ActionButton-hold')} />
78
- }
79
- <ClearSlots>
80
- <SlotProvider
81
- slots={{
82
- icon: {
83
- size: 'S',
84
- UNSAFE_className: classNames(
85
- styles,
86
- 'spectrum-Icon',
87
- {
88
- 'spectrum-ActionGroup-itemIcon': hideButtonText
89
- }
90
- )
91
- },
92
- text: {
93
- ...textProps
94
- }
95
- }}>
96
- {typeof children === 'string' || isTextOnly
97
- ? <Text>{children}</Text>
98
- : children}
99
- </SlotProvider>
100
- </ClearSlots>
101
- </button>
102
- </FocusRing>
103
- );
104
- });
package/src/Button.tsx DELETED
@@ -1,207 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {
14
- classNames,
15
- SlotProvider,
16
- useFocusableRef,
17
- useHasChild,
18
- useSlotProps,
19
- useStyleProps
20
- } from '@react-spectrum/utils';
21
- import {FocusableRef} from '@react-types/shared';
22
- import {FocusRing} from '@react-aria/focus';
23
- // @ts-ignore
24
- import intlMessages from '../intl/*.json';
25
- import {isAppleDevice, isFirefox, mergeProps, useId} from '@react-aria/utils';
26
- import {ProgressCircle} from '@react-spectrum/progress';
27
- import React, {ElementType, ReactElement, useEffect, useState} from 'react';
28
- import {SpectrumButtonProps} from '@react-types/button';
29
- import styles from '@adobe/spectrum-css-temp/components/button/vars.css';
30
- import {Text} from '@react-spectrum/text';
31
- import {useButton} from '@react-aria/button';
32
- import {useFocus, useHover} from '@react-aria/interactions';
33
- import {useLocalizedStringFormatter} from '@react-aria/i18n';
34
- import {useProviderProps} from '@react-spectrum/provider';
35
-
36
- function disablePendingProps(props) {
37
- // Don't allow interaction while isPending is true
38
- if (props.isPending) {
39
- props.onPress = undefined;
40
- props.onPressStart = undefined;
41
- props.onPressEnd = undefined;
42
- props.onPressChange = undefined;
43
- props.onPressUp = undefined;
44
- props.onKeyDown = undefined;
45
- props.onKeyUp = undefined;
46
- props.onClick = undefined;
47
- props.href = undefined;
48
- }
49
- return props;
50
- }
51
-
52
- /**
53
- * Buttons allow users to perform an action or to navigate to another page.
54
- * They have multiple styles for various needs, and are ideal for calling attention to
55
- * where a user needs to do something in order to move forward in a flow.
56
- */
57
- export const Button = React.forwardRef(function Button<T extends ElementType = 'button'>(props: SpectrumButtonProps<T>, ref: FocusableRef<HTMLElement>) {
58
- props = useProviderProps(props);
59
- props = useSlotProps(props, 'button');
60
- props = disablePendingProps(props);
61
- let {
62
- elementType: Element = 'button',
63
- children,
64
- variant,
65
- style = variant === 'accent' || variant === 'cta' ? 'fill' : 'outline',
66
- staticColor,
67
- isDisabled,
68
- isPending,
69
- autoFocus,
70
- ...otherProps
71
- } = props;
72
- let domRef = useFocusableRef(ref);
73
- let {buttonProps, isPressed} = useButton(props, domRef);
74
- let {hoverProps, isHovered} = useHover({isDisabled});
75
- let [isFocused, onFocusChange] = useState(false);
76
- let {focusProps} = useFocus({onFocusChange, isDisabled});
77
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/button');
78
- let {styleProps} = useStyleProps(otherProps);
79
- let hasLabel = useHasChild(`.${styles['spectrum-Button-label']}`, domRef);
80
- let hasIcon = useHasChild(`.${styles['spectrum-Icon']}`, domRef);
81
- // an aria label will block children and their labels from being read, this is undesirable for pending state
82
- let hasAriaLabel = !!buttonProps['aria-label'] || !!buttonProps['aria-labelledby'];
83
- let [isProgressVisible, setIsProgressVisible] = useState(false);
84
- let backupButtonId = useId();
85
- let buttonId = buttonProps.id || backupButtonId;
86
- let iconId = useId();
87
- let textId = useId();
88
- let spinnerId = useId();
89
-
90
- useEffect(() => {
91
- let timeout: ReturnType<typeof setTimeout>;
92
-
93
- if (isPending) {
94
- // Start timer when isPending is set to true.
95
- timeout = setTimeout(() => {
96
- setIsProgressVisible(true);
97
- }, 1000);
98
- } else {
99
- // Exit loading state when isPending is set to false. */
100
- setIsProgressVisible(false);
101
- }
102
- return () => {
103
- // Clean up on unmount or when user removes isPending prop before entering loading state.
104
- clearTimeout(timeout);
105
- };
106
- }, [isPending]);
107
-
108
- if (variant === 'cta') {
109
- variant = 'accent';
110
- } else if (variant === 'overBackground') {
111
- variant = 'primary';
112
- staticColor = 'white';
113
- }
114
-
115
- const isPendingAriaLiveLabel = `${hasAriaLabel ? buttonProps['aria-label'] : ''} ${stringFormatter.format('pending')}`.trim();
116
- const isPendingAriaLiveLabelledby = hasAriaLabel ? (buttonProps['aria-labelledby']?.replace(buttonId, spinnerId) ?? spinnerId) : `${hasIcon ? iconId : ''} ${hasLabel ? textId : ''} ${spinnerId}`.trim();
117
-
118
- let ariaLive: 'off' | 'polite' | 'assertive' = 'polite';
119
- if (isAppleDevice() && (!hasAriaLabel || isFirefox())) {
120
- ariaLive = 'off';
121
- }
122
-
123
- let isPendingProps = isPending ? {
124
- onClick: (e) => {
125
- if (e.currentTarget instanceof HTMLButtonElement) {
126
- e.preventDefault();
127
- }
128
- }
129
- } : {
130
- // no-op.
131
- // Not sure why, but TypeScript wouldn't allow to have an empty object `{}`.
132
- onClick: () => {}
133
- };
134
-
135
- return (
136
- <FocusRing focusRingClass={classNames(styles, 'focus-ring')} autoFocus={autoFocus}>
137
- <Element
138
- {...styleProps}
139
- {...mergeProps(buttonProps, hoverProps, focusProps, isPendingProps)}
140
- id={buttonId}
141
- ref={domRef}
142
- data-variant={variant}
143
- data-style={style}
144
- data-static-color={staticColor || undefined}
145
- aria-disabled={isPending ? 'true' : undefined}
146
- aria-label={isPending ? isPendingAriaLiveLabel : buttonProps['aria-label']}
147
- aria-labelledby={isPending ? isPendingAriaLiveLabelledby : buttonProps['aria-labelledby']}
148
- className={
149
- classNames(
150
- styles,
151
- 'spectrum-Button',
152
- {
153
- 'spectrum-Button--iconOnly': hasIcon && !hasLabel,
154
- 'is-disabled': isDisabled || isProgressVisible,
155
- 'is-active': isPressed,
156
- 'is-hovered': isHovered,
157
- 'spectrum-Button--pending': isProgressVisible
158
- },
159
- styleProps.className
160
- )
161
- }>
162
- <SlotProvider
163
- slots={{
164
- icon: {
165
- id: iconId,
166
- size: 'S',
167
- UNSAFE_className: classNames(styles, 'spectrum-Icon')
168
- },
169
- text: {
170
- id: textId,
171
- UNSAFE_className: classNames(styles, 'spectrum-Button-label')
172
- }
173
- }}>
174
- {typeof children === 'string'
175
- ? <Text>{children}</Text>
176
- : children}
177
- {isPending && (
178
- <div
179
- aria-hidden="true"
180
- style={{visibility: isProgressVisible ? 'visible' : 'hidden'}}
181
- className={classNames(styles, 'spectrum-Button-circleLoader')}>
182
- <ProgressCircle
183
- aria-label={isPendingAriaLiveLabel}
184
- isIndeterminate
185
- size="S"
186
- staticColor={staticColor} />
187
- </div>
188
- )}
189
- {isPending &&
190
- <>
191
- <div aria-live={isFocused ? ariaLive : 'off'}>
192
- {isProgressVisible &&
193
- <div role="img" aria-labelledby={isPendingAriaLiveLabelledby} />
194
- }
195
- </div>
196
- {/* Adding the element here with the same labels as the button itself causes aria-live to pick up the change in Safari.
197
- Safari with VO unfortunately doesn't announce changes to *all* of its labels specifically for button
198
- https://a11ysupport.io/tests/tech__html__button-name-change#assertion-aria-aria-label_attribute-convey_name_change-html-button_element-vo_macos-safari
199
- The aria-live may cause extra announcements in other browsers. */}
200
- <div id={spinnerId} role="img" aria-label={isPendingAriaLiveLabel} />
201
- </>
202
- }
203
- </SlotProvider>
204
- </Element>
205
- </FocusRing>
206
- );
207
- }) as <T extends ElementType = 'button'>(props: SpectrumButtonProps<T> & {ref?: FocusableRef<HTMLElement>}) => ReactElement;
@@ -1,81 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {AriaButtonElementTypeProps, ButtonProps} from '@react-types/button';
14
- import {classNames, useFocusableRef, useStyleProps} from '@react-spectrum/utils';
15
- import CrossSmall from '@spectrum-icons/ui/CrossSmall';
16
- import {DOMProps, FocusableRef, StyleProps} from '@react-types/shared';
17
- import {FocusRing} from '@react-aria/focus';
18
- import {mergeProps} from '@react-aria/utils';
19
- import React, {ElementType} from 'react';
20
- import styles from '@adobe/spectrum-css-temp/components/button/vars.css';
21
- import {useButton} from '@react-aria/button';
22
- import {useHover} from '@react-aria/interactions';
23
-
24
- interface ClearButtonProps<T extends ElementType = 'button'> extends ButtonProps, AriaButtonElementTypeProps<T>, DOMProps, StyleProps {
25
- focusClassName?: string,
26
- variant?: 'overBackground',
27
- excludeFromTabOrder?: boolean,
28
- preventFocus?: boolean,
29
- inset?: boolean
30
- }
31
-
32
- export const ClearButton = React.forwardRef(function ClearButton(props: ClearButtonProps, ref: FocusableRef<HTMLButtonElement>) {
33
- let {
34
- children = <CrossSmall UNSAFE_className={styles['spectrum-Icon']} />,
35
- focusClassName,
36
- variant,
37
- autoFocus,
38
- isDisabled,
39
- preventFocus,
40
- elementType = preventFocus ? 'div' : 'button' as ElementType,
41
- inset = false,
42
- ...otherProps
43
- } = props;
44
- let domRef = useFocusableRef(ref);
45
- let {buttonProps, isPressed} = useButton({...props, elementType}, domRef);
46
- let {hoverProps, isHovered} = useHover({isDisabled});
47
- let {styleProps} = useStyleProps(otherProps);
48
-
49
- // For cases like the clear button in a search field, remove the tabIndex so
50
- // iOS 14 with VoiceOver doesn't focus the button and hide the keyboard when
51
- // moving the cursor over the clear button.
52
- if (preventFocus) {
53
- delete buttonProps.tabIndex;
54
- }
55
-
56
- let ElementType = elementType;
57
- return (
58
- <FocusRing focusRingClass={classNames(styles, 'focus-ring', focusClassName)} autoFocus={autoFocus}>
59
- <ElementType
60
- {...styleProps}
61
- {...mergeProps(buttonProps, hoverProps)}
62
- ref={domRef}
63
- className={
64
- classNames(
65
- styles,
66
- 'spectrum-ClearButton',
67
- {
68
- [`spectrum-ClearButton--${variant}`]: variant,
69
- 'is-disabled': isDisabled,
70
- 'is-active': isPressed,
71
- 'is-hovered': isHovered,
72
- 'spectrum-ClearButton--inset': inset
73
- },
74
- styleProps.className
75
- )
76
- }>
77
- {children}
78
- </ElementType>
79
- </FocusRing>
80
- );
81
- });
@@ -1,81 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {ButtonProps} from '@react-types/button';
14
- import {classNames, SlotProvider, useFocusableRef, useSlotProps, useStyleProps} from '@react-spectrum/utils';
15
- import {DOMProps, FocusableRef, RefObject, StyleProps} from '@react-types/shared';
16
- import {FocusRing} from '@react-aria/focus';
17
- import {mergeProps} from '@react-aria/utils';
18
- import React from 'react';
19
- import styles from '@adobe/spectrum-css-temp/components/button/vars.css';
20
- import {useButton} from '@react-aria/button';
21
- import {useHover} from '@react-aria/interactions';
22
-
23
- interface FieldButtonProps extends ButtonProps, DOMProps, StyleProps {
24
- isQuiet?: boolean,
25
- isActive?: boolean,
26
- validationState?: 'valid' | 'invalid',
27
- isInvalid?: boolean,
28
- focusRingClass?: string
29
- }
30
-
31
- // @private
32
- export const FieldButton = React.forwardRef(function FieldButton(props: FieldButtonProps, ref: FocusableRef) {
33
- props = useSlotProps(props, 'button');
34
- let {
35
- isQuiet,
36
- isDisabled,
37
- validationState,
38
- isInvalid,
39
- children,
40
- autoFocus,
41
- isActive,
42
- focusRingClass,
43
- ...otherProps
44
- } = props;
45
- let domRef = useFocusableRef(ref) as RefObject<HTMLButtonElement | null>;
46
- let {buttonProps, isPressed} = useButton(props, domRef);
47
- let {hoverProps, isHovered} = useHover({isDisabled});
48
- let {styleProps} = useStyleProps(otherProps);
49
-
50
- return (
51
- <FocusRing focusRingClass={classNames(styles, 'focus-ring', focusRingClass)} autoFocus={autoFocus}>
52
- <button
53
- {...mergeProps(buttonProps, hoverProps)}
54
- ref={domRef}
55
- className={
56
- classNames(
57
- styles,
58
- 'spectrum-FieldButton',
59
- {
60
- 'spectrum-FieldButton--quiet': isQuiet,
61
- 'is-active': isActive || isPressed,
62
- 'is-disabled': isDisabled,
63
- 'spectrum-FieldButton--invalid': isInvalid || validationState === 'invalid',
64
- 'is-hovered': isHovered
65
- },
66
- styleProps.className
67
- )
68
- }>
69
- <SlotProvider
70
- slots={{
71
- icon: {
72
- size: 'S',
73
- UNSAFE_className: classNames(styles, 'spectrum-Icon')
74
- }
75
- }}>
76
- {children}
77
- </SlotProvider>
78
- </button>
79
- </FocusRing>
80
- );
81
- });
@@ -1,64 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {classNames, useFocusableRef, useStyleProps} from '@react-spectrum/utils';
14
- import {FocusableRef} from '@react-types/shared';
15
- import {FocusRing} from '@react-aria/focus';
16
- import {mergeProps} from '@react-aria/utils';
17
- import React from 'react';
18
- import {SpectrumLogicButtonProps} from '@react-types/button';
19
- import styles from '@adobe/spectrum-css-temp/components/button/vars.css';
20
- import {useButton} from '@react-aria/button';
21
- import {useHover} from '@react-aria/interactions';
22
- import {useProviderProps} from '@react-spectrum/provider';
23
-
24
- /**
25
- * A LogicButton displays an operator within a boolean logic sequence.
26
- */
27
- export const LogicButton = React.forwardRef(function LogicButton(props: SpectrumLogicButtonProps, ref: FocusableRef<HTMLButtonElement>) {
28
- props = useProviderProps(props);
29
- let {
30
- variant,
31
- children,
32
- isDisabled,
33
- autoFocus,
34
- ...otherProps
35
- } = props;
36
- let domRef = useFocusableRef(ref);
37
- let {buttonProps, isPressed} = useButton(props, domRef);
38
- let {hoverProps, isHovered} = useHover({isDisabled});
39
- let {styleProps} = useStyleProps(otherProps);
40
-
41
- return (
42
- <FocusRing focusRingClass={classNames(styles, 'focus-ring')} autoFocus={autoFocus}>
43
- <button
44
- {...styleProps}
45
- {...mergeProps(buttonProps, hoverProps)}
46
- ref={domRef}
47
- className={
48
- classNames(
49
- styles,
50
- 'spectrum-LogicButton',
51
- {
52
- [`spectrum-LogicButton--${variant}`]: variant,
53
- 'is-disabled': isDisabled,
54
- 'is-active': isPressed,
55
- 'is-hovered': isHovered
56
- },
57
- styleProps.className
58
- )
59
- }>
60
- <span className={classNames(styles, 'spectrum-Button-label')}>{children}</span>
61
- </button>
62
- </FocusRing>
63
- );
64
- });