@react-aria/color 3.0.0-beta.30 → 3.0.0-beta.32

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 (226) hide show
  1. package/dist/ar-AE.main.js +11 -0
  2. package/dist/ar-AE.main.js.map +1 -0
  3. package/dist/ar-AE.mjs +13 -0
  4. package/dist/ar-AE.module.js +13 -0
  5. package/dist/ar-AE.module.js.map +1 -0
  6. package/dist/bg-BG.main.js +11 -0
  7. package/dist/bg-BG.main.js.map +1 -0
  8. package/dist/bg-BG.mjs +13 -0
  9. package/dist/bg-BG.module.js +13 -0
  10. package/dist/bg-BG.module.js.map +1 -0
  11. package/dist/cs-CZ.main.js +11 -0
  12. package/dist/cs-CZ.main.js.map +1 -0
  13. package/dist/cs-CZ.mjs +13 -0
  14. package/dist/cs-CZ.module.js +13 -0
  15. package/dist/cs-CZ.module.js.map +1 -0
  16. package/dist/da-DK.main.js +11 -0
  17. package/dist/da-DK.main.js.map +1 -0
  18. package/dist/da-DK.mjs +13 -0
  19. package/dist/da-DK.module.js +13 -0
  20. package/dist/da-DK.module.js.map +1 -0
  21. package/dist/de-DE.main.js +11 -0
  22. package/dist/de-DE.main.js.map +1 -0
  23. package/dist/de-DE.mjs +13 -0
  24. package/dist/de-DE.module.js +13 -0
  25. package/dist/de-DE.module.js.map +1 -0
  26. package/dist/el-GR.main.js +11 -0
  27. package/dist/el-GR.main.js.map +1 -0
  28. package/dist/el-GR.mjs +13 -0
  29. package/dist/el-GR.module.js +13 -0
  30. package/dist/el-GR.module.js.map +1 -0
  31. package/dist/en-US.main.js +11 -0
  32. package/dist/en-US.main.js.map +1 -0
  33. package/dist/en-US.mjs +13 -0
  34. package/dist/en-US.module.js +13 -0
  35. package/dist/en-US.module.js.map +1 -0
  36. package/dist/es-ES.main.js +11 -0
  37. package/dist/es-ES.main.js.map +1 -0
  38. package/dist/es-ES.mjs +13 -0
  39. package/dist/es-ES.module.js +13 -0
  40. package/dist/es-ES.module.js.map +1 -0
  41. package/dist/et-EE.main.js +11 -0
  42. package/dist/et-EE.main.js.map +1 -0
  43. package/dist/et-EE.mjs +13 -0
  44. package/dist/et-EE.module.js +13 -0
  45. package/dist/et-EE.module.js.map +1 -0
  46. package/dist/fi-FI.main.js +11 -0
  47. package/dist/fi-FI.main.js.map +1 -0
  48. package/dist/fi-FI.mjs +13 -0
  49. package/dist/fi-FI.module.js +13 -0
  50. package/dist/fi-FI.module.js.map +1 -0
  51. package/dist/fr-FR.main.js +11 -0
  52. package/dist/fr-FR.main.js.map +1 -0
  53. package/dist/fr-FR.mjs +13 -0
  54. package/dist/fr-FR.module.js +13 -0
  55. package/dist/fr-FR.module.js.map +1 -0
  56. package/dist/he-IL.main.js +11 -0
  57. package/dist/he-IL.main.js.map +1 -0
  58. package/dist/he-IL.mjs +13 -0
  59. package/dist/he-IL.module.js +13 -0
  60. package/dist/he-IL.module.js.map +1 -0
  61. package/dist/hr-HR.main.js +11 -0
  62. package/dist/hr-HR.main.js.map +1 -0
  63. package/dist/hr-HR.mjs +13 -0
  64. package/dist/hr-HR.module.js +13 -0
  65. package/dist/hr-HR.module.js.map +1 -0
  66. package/dist/hu-HU.main.js +11 -0
  67. package/dist/hu-HU.main.js.map +1 -0
  68. package/dist/hu-HU.mjs +13 -0
  69. package/dist/hu-HU.module.js +13 -0
  70. package/dist/hu-HU.module.js.map +1 -0
  71. package/dist/import.mjs +7 -1357
  72. package/dist/intlStrings.main.js +108 -0
  73. package/dist/intlStrings.main.js.map +1 -0
  74. package/dist/intlStrings.mjs +110 -0
  75. package/dist/intlStrings.module.js +110 -0
  76. package/dist/intlStrings.module.js.map +1 -0
  77. package/dist/it-IT.main.js +11 -0
  78. package/dist/it-IT.main.js.map +1 -0
  79. package/dist/it-IT.mjs +13 -0
  80. package/dist/it-IT.module.js +13 -0
  81. package/dist/it-IT.module.js.map +1 -0
  82. package/dist/ja-JP.main.js +11 -0
  83. package/dist/ja-JP.main.js.map +1 -0
  84. package/dist/ja-JP.mjs +13 -0
  85. package/dist/ja-JP.module.js +13 -0
  86. package/dist/ja-JP.module.js.map +1 -0
  87. package/dist/ko-KR.main.js +11 -0
  88. package/dist/ko-KR.main.js.map +1 -0
  89. package/dist/ko-KR.mjs +13 -0
  90. package/dist/ko-KR.module.js +13 -0
  91. package/dist/ko-KR.module.js.map +1 -0
  92. package/dist/lt-LT.main.js +11 -0
  93. package/dist/lt-LT.main.js.map +1 -0
  94. package/dist/lt-LT.mjs +13 -0
  95. package/dist/lt-LT.module.js +13 -0
  96. package/dist/lt-LT.module.js.map +1 -0
  97. package/dist/lv-LV.main.js +11 -0
  98. package/dist/lv-LV.main.js.map +1 -0
  99. package/dist/lv-LV.mjs +13 -0
  100. package/dist/lv-LV.module.js +13 -0
  101. package/dist/lv-LV.module.js.map +1 -0
  102. package/dist/main.js +12 -1360
  103. package/dist/main.js.map +1 -1
  104. package/dist/module.js +7 -1357
  105. package/dist/module.js.map +1 -1
  106. package/dist/nb-NO.main.js +11 -0
  107. package/dist/nb-NO.main.js.map +1 -0
  108. package/dist/nb-NO.mjs +13 -0
  109. package/dist/nb-NO.module.js +13 -0
  110. package/dist/nb-NO.module.js.map +1 -0
  111. package/dist/nl-NL.main.js +11 -0
  112. package/dist/nl-NL.main.js.map +1 -0
  113. package/dist/nl-NL.mjs +13 -0
  114. package/dist/nl-NL.module.js +13 -0
  115. package/dist/nl-NL.module.js.map +1 -0
  116. package/dist/pl-PL.main.js +11 -0
  117. package/dist/pl-PL.main.js.map +1 -0
  118. package/dist/pl-PL.mjs +13 -0
  119. package/dist/pl-PL.module.js +13 -0
  120. package/dist/pl-PL.module.js.map +1 -0
  121. package/dist/pt-BR.main.js +11 -0
  122. package/dist/pt-BR.main.js.map +1 -0
  123. package/dist/pt-BR.mjs +13 -0
  124. package/dist/pt-BR.module.js +13 -0
  125. package/dist/pt-BR.module.js.map +1 -0
  126. package/dist/pt-PT.main.js +11 -0
  127. package/dist/pt-PT.main.js.map +1 -0
  128. package/dist/pt-PT.mjs +13 -0
  129. package/dist/pt-PT.module.js +13 -0
  130. package/dist/pt-PT.module.js.map +1 -0
  131. package/dist/ro-RO.main.js +11 -0
  132. package/dist/ro-RO.main.js.map +1 -0
  133. package/dist/ro-RO.mjs +13 -0
  134. package/dist/ro-RO.module.js +13 -0
  135. package/dist/ro-RO.module.js.map +1 -0
  136. package/dist/ru-RU.main.js +11 -0
  137. package/dist/ru-RU.main.js.map +1 -0
  138. package/dist/ru-RU.mjs +13 -0
  139. package/dist/ru-RU.module.js +13 -0
  140. package/dist/ru-RU.module.js.map +1 -0
  141. package/dist/sk-SK.main.js +11 -0
  142. package/dist/sk-SK.main.js.map +1 -0
  143. package/dist/sk-SK.mjs +13 -0
  144. package/dist/sk-SK.module.js +13 -0
  145. package/dist/sk-SK.module.js.map +1 -0
  146. package/dist/sl-SI.main.js +11 -0
  147. package/dist/sl-SI.main.js.map +1 -0
  148. package/dist/sl-SI.mjs +13 -0
  149. package/dist/sl-SI.module.js +13 -0
  150. package/dist/sl-SI.module.js.map +1 -0
  151. package/dist/sr-SP.main.js +11 -0
  152. package/dist/sr-SP.main.js.map +1 -0
  153. package/dist/sr-SP.mjs +13 -0
  154. package/dist/sr-SP.module.js +13 -0
  155. package/dist/sr-SP.module.js.map +1 -0
  156. package/dist/sv-SE.main.js +11 -0
  157. package/dist/sv-SE.main.js.map +1 -0
  158. package/dist/sv-SE.mjs +13 -0
  159. package/dist/sv-SE.module.js +13 -0
  160. package/dist/sv-SE.module.js.map +1 -0
  161. package/dist/tr-TR.main.js +11 -0
  162. package/dist/tr-TR.main.js.map +1 -0
  163. package/dist/tr-TR.mjs +13 -0
  164. package/dist/tr-TR.module.js +13 -0
  165. package/dist/tr-TR.module.js.map +1 -0
  166. package/dist/types.d.ts +41 -7
  167. package/dist/types.d.ts.map +1 -1
  168. package/dist/uk-UA.main.js +11 -0
  169. package/dist/uk-UA.main.js.map +1 -0
  170. package/dist/uk-UA.mjs +13 -0
  171. package/dist/uk-UA.module.js +13 -0
  172. package/dist/uk-UA.module.js.map +1 -0
  173. package/dist/useColorArea.main.js +404 -0
  174. package/dist/useColorArea.main.js.map +1 -0
  175. package/dist/useColorArea.mjs +399 -0
  176. package/dist/useColorArea.module.js +399 -0
  177. package/dist/useColorArea.module.js.map +1 -0
  178. package/dist/useColorAreaGradient.main.js +123 -0
  179. package/dist/useColorAreaGradient.main.js.map +1 -0
  180. package/dist/useColorAreaGradient.mjs +118 -0
  181. package/dist/useColorAreaGradient.module.js +118 -0
  182. package/dist/useColorAreaGradient.module.js.map +1 -0
  183. package/dist/useColorChannelField.main.js +36 -0
  184. package/dist/useColorChannelField.main.js.map +1 -0
  185. package/dist/useColorChannelField.mjs +31 -0
  186. package/dist/useColorChannelField.module.js +31 -0
  187. package/dist/useColorChannelField.module.js.map +1 -0
  188. package/dist/useColorField.main.js +98 -0
  189. package/dist/useColorField.main.js.map +1 -0
  190. package/dist/useColorField.mjs +93 -0
  191. package/dist/useColorField.module.js +93 -0
  192. package/dist/useColorField.module.js.map +1 -0
  193. package/dist/useColorSlider.main.js +132 -0
  194. package/dist/useColorSlider.main.js.map +1 -0
  195. package/dist/useColorSlider.mjs +127 -0
  196. package/dist/useColorSlider.module.js +127 -0
  197. package/dist/useColorSlider.module.js.map +1 -0
  198. package/dist/useColorSwatch.main.js +67 -0
  199. package/dist/useColorSwatch.main.js.map +1 -0
  200. package/dist/useColorSwatch.mjs +62 -0
  201. package/dist/useColorSwatch.module.js +62 -0
  202. package/dist/useColorSwatch.module.js.map +1 -0
  203. package/dist/useColorWheel.main.js +274 -0
  204. package/dist/useColorWheel.main.js.map +1 -0
  205. package/dist/useColorWheel.mjs +269 -0
  206. package/dist/useColorWheel.module.js +269 -0
  207. package/dist/useColorWheel.module.js.map +1 -0
  208. package/dist/zh-CN.main.js +11 -0
  209. package/dist/zh-CN.main.js.map +1 -0
  210. package/dist/zh-CN.mjs +13 -0
  211. package/dist/zh-CN.module.js +13 -0
  212. package/dist/zh-CN.module.js.map +1 -0
  213. package/dist/zh-TW.main.js +11 -0
  214. package/dist/zh-TW.main.js.map +1 -0
  215. package/dist/zh-TW.mjs +13 -0
  216. package/dist/zh-TW.module.js +13 -0
  217. package/dist/zh-TW.module.js.map +1 -0
  218. package/package.json +14 -13
  219. package/src/index.ts +4 -0
  220. package/src/useColorArea.ts +32 -23
  221. package/src/useColorAreaGradient.ts +66 -189
  222. package/src/useColorChannelField.ts +37 -0
  223. package/src/useColorField.ts +18 -14
  224. package/src/useColorSlider.ts +28 -4
  225. package/src/useColorSwatch.ts +74 -0
  226. package/src/useColorWheel.ts +19 -5
@@ -17,6 +17,7 @@ import {InputHTMLAttributes, RefObject} from 'react';
17
17
  import {mergeProps} from '@react-aria/utils';
18
18
  import {useLocale} from '@react-aria/i18n';
19
19
  import {useSlider, useSliderThumb} from '@react-aria/slider';
20
+ import {useVisuallyHidden} from '@react-aria/visually-hidden';
20
21
 
21
22
  export interface AriaColorSliderOptions extends AriaColorSliderProps {
22
23
  /** A ref for the track element. */
@@ -63,8 +64,8 @@ export function useColorSlider(props: AriaColorSliderOptions, state: ColorSlider
63
64
  inputRef
64
65
  }, state);
65
66
 
67
+ let value = state.getDisplayColor();
66
68
  let generateBackground = () => {
67
- let value = state.getDisplayColor();
68
69
  let to: string;
69
70
  if (orientation === 'vertical') {
70
71
  to = 'top';
@@ -74,8 +75,10 @@ export function useColorSlider(props: AriaColorSliderOptions, state: ColorSlider
74
75
  to = 'left';
75
76
  }
76
77
  switch (channel) {
77
- case 'hue':
78
- return `linear-gradient(to ${to}, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%)`;
78
+ case 'hue': {
79
+ let stops = [0, 60, 120, 180, 240, 300, 360].map(hue => value.withChannelValue('hue', hue).toString('css')).join(', ');
80
+ return `linear-gradient(to ${to}, ${stops})`;
81
+ }
79
82
  case 'lightness': {
80
83
  // We have to add an extra color stop in the middle so that the hue shows up at all.
81
84
  // Otherwise it will always just be black to white.
@@ -103,6 +106,21 @@ export function useColorSlider(props: AriaColorSliderOptions, state: ColorSlider
103
106
 
104
107
  let forcedColorAdjustNoneStyle = {forcedColorAdjust: 'none'};
105
108
 
109
+ if (channel === 'hue') {
110
+ inputProps['aria-valuetext'] += `, ${value.getHueName(locale)}`;
111
+ } else if (channel !== 'alpha') {
112
+ inputProps['aria-valuetext'] += `, ${value.getColorName(locale)}`;
113
+ }
114
+
115
+ let {visuallyHiddenProps} = useVisuallyHidden({
116
+ style: {
117
+ opacity: '0.0001',
118
+ width: '100%',
119
+ height: '100%',
120
+ pointerEvents: 'none'
121
+ }
122
+ });
123
+
106
124
  return {
107
125
  trackProps: {
108
126
  ...mergeProps(groupProps, trackProps),
@@ -112,7 +130,13 @@ export function useColorSlider(props: AriaColorSliderOptions, state: ColorSlider
112
130
  background: generateBackground()
113
131
  }
114
132
  },
115
- inputProps,
133
+ inputProps: {
134
+ ...inputProps,
135
+ style: {
136
+ ...inputProps.style,
137
+ ...visuallyHiddenProps.style
138
+ }
139
+ },
116
140
  thumbProps: {
117
141
  ...thumbProps,
118
142
  style: {
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright 2024 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 {AriaLabelingProps, DOMProps} from '@react-types/shared';
14
+ import {Color} from '@react-types/color';
15
+ import {filterDOMProps, useId} from '@react-aria/utils';
16
+ import {HTMLAttributes, useMemo} from 'react';
17
+ // @ts-ignore
18
+ import intlMessages from '../intl/*.json';
19
+ import {parseColor} from '@react-stately/color';
20
+ import {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
21
+
22
+ export interface AriaColorSwatchProps extends AriaLabelingProps, DOMProps {
23
+ /** The color value to display in the swatch. */
24
+ color?: string | Color | null,
25
+ /**
26
+ * A localized accessible name for the color.
27
+ * By default, a description is generated from the color value,
28
+ * but this can be overridden if you have a more specific color
29
+ * name (e.g. Pantone colors).
30
+ */
31
+ colorName?: string
32
+ }
33
+
34
+ export interface ColorSwatchAria {
35
+ /** Props for the color swatch element. */
36
+ colorSwatchProps: HTMLAttributes<HTMLElement>,
37
+ /** The parsed color value of the swatch. */
38
+ color: Color
39
+ }
40
+
41
+ /**
42
+ * Provides the accessibility implementation for a color swatch component.
43
+ * A color swatch displays a preview of a selected color.
44
+ */
45
+ export function useColorSwatch(props: AriaColorSwatchProps): ColorSwatchAria {
46
+ let {color: value, colorName} = props;
47
+ let nonNullValue = value || '#fff0';
48
+ let color = useMemo(() => typeof nonNullValue === 'string' ? parseColor(nonNullValue) : nonNullValue, [nonNullValue]);
49
+ let {locale} = useLocale();
50
+ let DOMProps = filterDOMProps(props, {labelable: true});
51
+ let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/color');
52
+ let id = useId(props.id);
53
+
54
+ if (!colorName) {
55
+ colorName = color.getChannelValue('alpha') === 0 ? stringFormatter.format('transparent') : color.getColorName(locale);
56
+ }
57
+
58
+ return {
59
+ colorSwatchProps: {
60
+ ...DOMProps,
61
+ role: 'img',
62
+ 'aria-roledescription': stringFormatter.format('colorSwatch'),
63
+ 'aria-label': [colorName, props['aria-label'] || ''].filter(Boolean).join(', '),
64
+ 'aria-labelledby': props['aria-labelledby'] ? `${id} ${props['aria-labelledby']}` : undefined,
65
+ id,
66
+ style: {
67
+ backgroundColor: color.toString('css'),
68
+ // @ts-ignore
69
+ forcedColorAdjust: 'none'
70
+ }
71
+ },
72
+ color: color || null
73
+ };
74
+ }
@@ -17,6 +17,7 @@ import {focusWithoutScrolling, mergeProps, useFormReset, useGlobalListeners, use
17
17
  import React, {ChangeEvent, InputHTMLAttributes, RefObject, useCallback, useRef} from 'react';
18
18
  import {useKeyboard, useMove} from '@react-aria/interactions';
19
19
  import {useLocale} from '@react-aria/i18n';
20
+ import {useVisuallyHidden} from '@react-aria/visually-hidden';
20
21
 
21
22
  export interface AriaColorWheelOptions extends AriaColorWheelProps {
22
23
  /** The outer radius of the color wheel. */
@@ -263,6 +264,15 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
263
264
  forcedColorAdjust: 'none'
264
265
  };
265
266
 
267
+ let {visuallyHiddenProps} = useVisuallyHidden({
268
+ style: {
269
+ opacity: '0.0001',
270
+ width: '100%',
271
+ height: '100%',
272
+ pointerEvents: 'none'
273
+ }
274
+ });
275
+
266
276
  return {
267
277
  trackProps: {
268
278
  ...trackInteractions,
@@ -297,9 +307,9 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
297
307
  ...thumbInteractions,
298
308
  style: {
299
309
  position: 'absolute',
300
- left: '50%',
301
- top: '50%',
302
- transform: `translate(calc(${x}px - 50%), calc(${y}px - 50%))`,
310
+ left: outerRadius + x,
311
+ top: outerRadius + y,
312
+ transform: 'translate(-50%, -50%)',
303
313
  touchAction: 'none',
304
314
  ...forcedColorAdjustNoneStyle
305
315
  }
@@ -311,13 +321,17 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
311
321
  min: String(minValue),
312
322
  max: String(maxValue),
313
323
  step: String(step),
314
- 'aria-valuetext': state.value.formatChannelValue('hue', locale),
324
+ 'aria-valuetext': `${state.value.formatChannelValue('hue', locale)}, ${state.value.getHueName(locale)}`,
315
325
  disabled: isDisabled,
316
326
  value: `${state.value.getChannelValue('hue')}`,
317
327
  name,
318
328
  onChange: (e: ChangeEvent<HTMLInputElement>) => {
319
329
  state.setHue(parseFloat(e.target.value));
320
- }
330
+ },
331
+ style: visuallyHiddenProps.style,
332
+ 'aria-errormessage': props['aria-errormessage'],
333
+ 'aria-describedby': props['aria-describedby'],
334
+ 'aria-details': props['aria-details']
321
335
  }
322
336
  )
323
337
  };