@react-spectrum/color 3.1.7 → 3.2.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 (290) hide show
  1. package/dist/import.mjs +9 -11
  2. package/dist/main.js +18 -20
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +9 -11
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +16 -0
  7. package/package.json +14 -41
  8. package/src/index.ts +17 -15
  9. package/dist/ColorArea.main.js +0 -95
  10. package/dist/ColorArea.main.js.map +0 -1
  11. package/dist/ColorArea.mjs +0 -90
  12. package/dist/ColorArea.module.js +0 -90
  13. package/dist/ColorArea.module.js.map +0 -1
  14. package/dist/ColorEditor.main.js +0 -113
  15. package/dist/ColorEditor.main.js.map +0 -1
  16. package/dist/ColorEditor.mjs +0 -108
  17. package/dist/ColorEditor.module.js +0 -108
  18. package/dist/ColorEditor.module.js.map +0 -1
  19. package/dist/ColorField.main.js +0 -105
  20. package/dist/ColorField.main.js.map +0 -1
  21. package/dist/ColorField.mjs +0 -100
  22. package/dist/ColorField.module.js +0 -100
  23. package/dist/ColorField.module.js.map +0 -1
  24. package/dist/ColorPicker.main.js +0 -123
  25. package/dist/ColorPicker.main.js.map +0 -1
  26. package/dist/ColorPicker.mjs +0 -114
  27. package/dist/ColorPicker.module.js +0 -114
  28. package/dist/ColorPicker.module.js.map +0 -1
  29. package/dist/ColorSlider.main.js +0 -126
  30. package/dist/ColorSlider.main.js.map +0 -1
  31. package/dist/ColorSlider.mjs +0 -121
  32. package/dist/ColorSlider.module.js +0 -121
  33. package/dist/ColorSlider.module.js.map +0 -1
  34. package/dist/ColorSwatch.main.js +0 -91
  35. package/dist/ColorSwatch.main.js.map +0 -1
  36. package/dist/ColorSwatch.mjs +0 -81
  37. package/dist/ColorSwatch.module.js +0 -81
  38. package/dist/ColorSwatch.module.js.map +0 -1
  39. package/dist/ColorSwatchPicker.main.js +0 -112
  40. package/dist/ColorSwatchPicker.main.js.map +0 -1
  41. package/dist/ColorSwatchPicker.mjs +0 -103
  42. package/dist/ColorSwatchPicker.module.js +0 -103
  43. package/dist/ColorSwatchPicker.module.js.map +0 -1
  44. package/dist/ColorThumb.main.js +0 -146
  45. package/dist/ColorThumb.main.js.map +0 -1
  46. package/dist/ColorThumb.mjs +0 -141
  47. package/dist/ColorThumb.module.js +0 -141
  48. package/dist/ColorThumb.module.js.map +0 -1
  49. package/dist/ColorWheel.main.js +0 -114
  50. package/dist/ColorWheel.main.js.map +0 -1
  51. package/dist/ColorWheel.mjs +0 -109
  52. package/dist/ColorWheel.module.js +0 -109
  53. package/dist/ColorWheel.module.js.map +0 -1
  54. package/dist/ar-AE.main.js +0 -10
  55. package/dist/ar-AE.main.js.map +0 -1
  56. package/dist/ar-AE.mjs +0 -12
  57. package/dist/ar-AE.module.js +0 -12
  58. package/dist/ar-AE.module.js.map +0 -1
  59. package/dist/bg-BG.main.js +0 -10
  60. package/dist/bg-BG.main.js.map +0 -1
  61. package/dist/bg-BG.mjs +0 -12
  62. package/dist/bg-BG.module.js +0 -12
  63. package/dist/bg-BG.module.js.map +0 -1
  64. package/dist/color.0da417e8.css +0 -93
  65. package/dist/color.0da417e8.css.map +0 -1
  66. package/dist/color.4034864f.css +0 -120
  67. package/dist/color.4034864f.css.map +0 -1
  68. package/dist/color.51750948.css +0 -356
  69. package/dist/color.51750948.css.map +0 -1
  70. package/dist/color.6dfdb0cd.css +0 -260
  71. package/dist/color.6dfdb0cd.css.map +0 -1
  72. package/dist/color.85d29c28.css +0 -12
  73. package/dist/color.85d29c28.css.map +0 -1
  74. package/dist/color.8e3b650f.css +0 -93
  75. package/dist/color.8e3b650f.css.map +0 -1
  76. package/dist/color.a5310285.css +0 -206
  77. package/dist/color.a5310285.css.map +0 -1
  78. package/dist/color.decac5a6.css +0 -20
  79. package/dist/color.decac5a6.css.map +0 -1
  80. package/dist/color.f801bfa3.css +0 -75
  81. package/dist/color.f801bfa3.css.map +0 -1
  82. package/dist/color.ff589589.css +0 -41
  83. package/dist/color.ff589589.css.map +0 -1
  84. package/dist/colorarea_vars_css.main.js +0 -29
  85. package/dist/colorarea_vars_css.main.js.map +0 -1
  86. package/dist/colorarea_vars_css.mjs +0 -31
  87. package/dist/colorarea_vars_css.module.js +0 -31
  88. package/dist/colorarea_vars_css.module.js.map +0 -1
  89. package/dist/colorfield_css.main.js +0 -11
  90. package/dist/colorfield_css.main.js.map +0 -1
  91. package/dist/colorfield_css.mjs +0 -13
  92. package/dist/colorfield_css.module.js +0 -13
  93. package/dist/colorfield_css.module.js.map +0 -1
  94. package/dist/colorhandle_vars_css.main.js +0 -26
  95. package/dist/colorhandle_vars_css.main.js.map +0 -1
  96. package/dist/colorhandle_vars_css.mjs +0 -28
  97. package/dist/colorhandle_vars_css.module.js +0 -28
  98. package/dist/colorhandle_vars_css.module.js.map +0 -1
  99. package/dist/colorloupe_vars_css.main.js +0 -23
  100. package/dist/colorloupe_vars_css.main.js.map +0 -1
  101. package/dist/colorloupe_vars_css.mjs +0 -25
  102. package/dist/colorloupe_vars_css.module.js +0 -25
  103. package/dist/colorloupe_vars_css.module.js.map +0 -1
  104. package/dist/colorslider_vars_css.main.js +0 -53
  105. package/dist/colorslider_vars_css.main.js.map +0 -1
  106. package/dist/colorslider_vars_css.mjs +0 -55
  107. package/dist/colorslider_vars_css.module.js +0 -55
  108. package/dist/colorslider_vars_css.module.js.map +0 -1
  109. package/dist/colorwheel_vars_css.main.js +0 -35
  110. package/dist/colorwheel_vars_css.main.js.map +0 -1
  111. package/dist/colorwheel_vars_css.mjs +0 -37
  112. package/dist/colorwheel_vars_css.module.js +0 -37
  113. package/dist/colorwheel_vars_css.module.js.map +0 -1
  114. package/dist/cs-CZ.main.js +0 -10
  115. package/dist/cs-CZ.main.js.map +0 -1
  116. package/dist/cs-CZ.mjs +0 -12
  117. package/dist/cs-CZ.module.js +0 -12
  118. package/dist/cs-CZ.module.js.map +0 -1
  119. package/dist/da-DK.main.js +0 -10
  120. package/dist/da-DK.main.js.map +0 -1
  121. package/dist/da-DK.mjs +0 -12
  122. package/dist/da-DK.module.js +0 -12
  123. package/dist/da-DK.module.js.map +0 -1
  124. package/dist/de-DE.main.js +0 -10
  125. package/dist/de-DE.main.js.map +0 -1
  126. package/dist/de-DE.mjs +0 -12
  127. package/dist/de-DE.module.js +0 -12
  128. package/dist/de-DE.module.js.map +0 -1
  129. package/dist/el-GR.main.js +0 -10
  130. package/dist/el-GR.main.js.map +0 -1
  131. package/dist/el-GR.mjs +0 -12
  132. package/dist/el-GR.module.js +0 -12
  133. package/dist/el-GR.module.js.map +0 -1
  134. package/dist/en-US.main.js +0 -10
  135. package/dist/en-US.main.js.map +0 -1
  136. package/dist/en-US.mjs +0 -12
  137. package/dist/en-US.module.js +0 -12
  138. package/dist/en-US.module.js.map +0 -1
  139. package/dist/es-ES.main.js +0 -10
  140. package/dist/es-ES.main.js.map +0 -1
  141. package/dist/es-ES.mjs +0 -12
  142. package/dist/es-ES.module.js +0 -12
  143. package/dist/es-ES.module.js.map +0 -1
  144. package/dist/et-EE.main.js +0 -10
  145. package/dist/et-EE.main.js.map +0 -1
  146. package/dist/et-EE.mjs +0 -12
  147. package/dist/et-EE.module.js +0 -12
  148. package/dist/et-EE.module.js.map +0 -1
  149. package/dist/fi-FI.main.js +0 -10
  150. package/dist/fi-FI.main.js.map +0 -1
  151. package/dist/fi-FI.mjs +0 -12
  152. package/dist/fi-FI.module.js +0 -12
  153. package/dist/fi-FI.module.js.map +0 -1
  154. package/dist/fr-FR.main.js +0 -10
  155. package/dist/fr-FR.main.js.map +0 -1
  156. package/dist/fr-FR.mjs +0 -12
  157. package/dist/fr-FR.module.js +0 -12
  158. package/dist/fr-FR.module.js.map +0 -1
  159. package/dist/he-IL.main.js +0 -10
  160. package/dist/he-IL.main.js.map +0 -1
  161. package/dist/he-IL.mjs +0 -12
  162. package/dist/he-IL.module.js +0 -12
  163. package/dist/he-IL.module.js.map +0 -1
  164. package/dist/hr-HR.main.js +0 -10
  165. package/dist/hr-HR.main.js.map +0 -1
  166. package/dist/hr-HR.mjs +0 -12
  167. package/dist/hr-HR.module.js +0 -12
  168. package/dist/hr-HR.module.js.map +0 -1
  169. package/dist/hu-HU.main.js +0 -10
  170. package/dist/hu-HU.main.js.map +0 -1
  171. package/dist/hu-HU.mjs +0 -12
  172. package/dist/hu-HU.module.js +0 -12
  173. package/dist/hu-HU.module.js.map +0 -1
  174. package/dist/intlStrings.main.js +0 -108
  175. package/dist/intlStrings.main.js.map +0 -1
  176. package/dist/intlStrings.mjs +0 -110
  177. package/dist/intlStrings.module.js +0 -110
  178. package/dist/intlStrings.module.js.map +0 -1
  179. package/dist/it-IT.main.js +0 -10
  180. package/dist/it-IT.main.js.map +0 -1
  181. package/dist/it-IT.mjs +0 -12
  182. package/dist/it-IT.module.js +0 -12
  183. package/dist/it-IT.module.js.map +0 -1
  184. package/dist/ja-JP.main.js +0 -10
  185. package/dist/ja-JP.main.js.map +0 -1
  186. package/dist/ja-JP.mjs +0 -12
  187. package/dist/ja-JP.module.js +0 -12
  188. package/dist/ja-JP.module.js.map +0 -1
  189. package/dist/ko-KR.main.js +0 -10
  190. package/dist/ko-KR.main.js.map +0 -1
  191. package/dist/ko-KR.mjs +0 -12
  192. package/dist/ko-KR.module.js +0 -12
  193. package/dist/ko-KR.module.js.map +0 -1
  194. package/dist/lt-LT.main.js +0 -10
  195. package/dist/lt-LT.main.js.map +0 -1
  196. package/dist/lt-LT.mjs +0 -12
  197. package/dist/lt-LT.module.js +0 -12
  198. package/dist/lt-LT.module.js.map +0 -1
  199. package/dist/lv-LV.main.js +0 -10
  200. package/dist/lv-LV.main.js.map +0 -1
  201. package/dist/lv-LV.mjs +0 -12
  202. package/dist/lv-LV.module.js +0 -12
  203. package/dist/lv-LV.module.js.map +0 -1
  204. package/dist/nb-NO.main.js +0 -10
  205. package/dist/nb-NO.main.js.map +0 -1
  206. package/dist/nb-NO.mjs +0 -12
  207. package/dist/nb-NO.module.js +0 -12
  208. package/dist/nb-NO.module.js.map +0 -1
  209. package/dist/nl-NL.main.js +0 -10
  210. package/dist/nl-NL.main.js.map +0 -1
  211. package/dist/nl-NL.mjs +0 -12
  212. package/dist/nl-NL.module.js +0 -12
  213. package/dist/nl-NL.module.js.map +0 -1
  214. package/dist/pl-PL.main.js +0 -10
  215. package/dist/pl-PL.main.js.map +0 -1
  216. package/dist/pl-PL.mjs +0 -12
  217. package/dist/pl-PL.module.js +0 -12
  218. package/dist/pl-PL.module.js.map +0 -1
  219. package/dist/pt-BR.main.js +0 -10
  220. package/dist/pt-BR.main.js.map +0 -1
  221. package/dist/pt-BR.mjs +0 -12
  222. package/dist/pt-BR.module.js +0 -12
  223. package/dist/pt-BR.module.js.map +0 -1
  224. package/dist/pt-PT.main.js +0 -10
  225. package/dist/pt-PT.main.js.map +0 -1
  226. package/dist/pt-PT.mjs +0 -12
  227. package/dist/pt-PT.module.js +0 -12
  228. package/dist/pt-PT.module.js.map +0 -1
  229. package/dist/ro-RO.main.js +0 -10
  230. package/dist/ro-RO.main.js.map +0 -1
  231. package/dist/ro-RO.mjs +0 -12
  232. package/dist/ro-RO.module.js +0 -12
  233. package/dist/ro-RO.module.js.map +0 -1
  234. package/dist/ru-RU.main.js +0 -10
  235. package/dist/ru-RU.main.js.map +0 -1
  236. package/dist/ru-RU.mjs +0 -12
  237. package/dist/ru-RU.module.js +0 -12
  238. package/dist/ru-RU.module.js.map +0 -1
  239. package/dist/sk-SK.main.js +0 -10
  240. package/dist/sk-SK.main.js.map +0 -1
  241. package/dist/sk-SK.mjs +0 -12
  242. package/dist/sk-SK.module.js +0 -12
  243. package/dist/sk-SK.module.js.map +0 -1
  244. package/dist/sl-SI.main.js +0 -10
  245. package/dist/sl-SI.main.js.map +0 -1
  246. package/dist/sl-SI.mjs +0 -12
  247. package/dist/sl-SI.module.js +0 -12
  248. package/dist/sl-SI.module.js.map +0 -1
  249. package/dist/sr-SP.main.js +0 -10
  250. package/dist/sr-SP.main.js.map +0 -1
  251. package/dist/sr-SP.mjs +0 -12
  252. package/dist/sr-SP.module.js +0 -12
  253. package/dist/sr-SP.module.js.map +0 -1
  254. package/dist/sv-SE.main.js +0 -10
  255. package/dist/sv-SE.main.js.map +0 -1
  256. package/dist/sv-SE.mjs +0 -12
  257. package/dist/sv-SE.module.js +0 -12
  258. package/dist/sv-SE.module.js.map +0 -1
  259. package/dist/tr-TR.main.js +0 -10
  260. package/dist/tr-TR.main.js.map +0 -1
  261. package/dist/tr-TR.mjs +0 -12
  262. package/dist/tr-TR.module.js +0 -12
  263. package/dist/tr-TR.module.js.map +0 -1
  264. package/dist/types.d.ts +0 -96
  265. package/dist/types.d.ts.map +0 -1
  266. package/dist/uk-UA.main.js +0 -10
  267. package/dist/uk-UA.main.js.map +0 -1
  268. package/dist/uk-UA.mjs +0 -12
  269. package/dist/uk-UA.module.js +0 -12
  270. package/dist/uk-UA.module.js.map +0 -1
  271. package/dist/zh-CN.main.js +0 -10
  272. package/dist/zh-CN.main.js.map +0 -1
  273. package/dist/zh-CN.mjs +0 -12
  274. package/dist/zh-CN.module.js +0 -12
  275. package/dist/zh-CN.module.js.map +0 -1
  276. package/dist/zh-TW.main.js +0 -10
  277. package/dist/zh-TW.main.js.map +0 -1
  278. package/dist/zh-TW.mjs +0 -12
  279. package/dist/zh-TW.module.js +0 -12
  280. package/dist/zh-TW.module.js.map +0 -1
  281. package/src/ColorArea.tsx +0 -87
  282. package/src/ColorEditor.tsx +0 -60
  283. package/src/ColorField.tsx +0 -111
  284. package/src/ColorPicker.tsx +0 -120
  285. package/src/ColorSlider.tsx +0 -142
  286. package/src/ColorSwatch.tsx +0 -99
  287. package/src/ColorSwatchPicker.tsx +0 -115
  288. package/src/ColorThumb.tsx +0 -114
  289. package/src/ColorWheel.tsx +0 -110
  290. package/src/colorfield.css +0 -18
@@ -1,115 +0,0 @@
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 {ColorSwatchPicker as AriaColorSwatchPicker, ColorSwatchPickerItem as AriaColorSwatchPickerItem} from 'react-aria-components';
14
- import {Color} from '@react-types/color';
15
- import {DOMRef, StyleProps, ValueBase} from '@react-types/shared';
16
- import React, {forwardRef, ReactElement, ReactNode} from 'react';
17
- import {SpectrumColorSwatchContext, SpectrumColorSwatchProps} from './ColorSwatch';
18
- import {style} from '@react-spectrum/style-macro-s1' with {type: 'macro'};
19
- import {useDOMRef, useStyleProps} from '@react-spectrum/utils';
20
-
21
- export interface SpectrumColorSwatchPickerProps extends ValueBase<string | Color, Color>, StyleProps {
22
- /** The ColorSwatches within the ColorSwatchPicker. */
23
- children: ReactNode,
24
- /**
25
- * The amount of padding between the swatches.
26
- * @default "regular"
27
- */
28
- density?: 'compact' | 'regular' | 'spacious',
29
- /**
30
- * The size of the color swatches.
31
- * @default "M"
32
- */
33
- size?: 'XS' | 'S' | 'M' | 'L',
34
- /**
35
- * The corner rounding of the color swatches.
36
- * @default "none"
37
- */
38
- rounding?: 'none' | 'default' | 'full'
39
- }
40
-
41
- /**
42
- * A ColorSwatchPicker displays a list of color swatches and allows a user to select one of them.
43
- */
44
- export const ColorSwatchPicker = forwardRef(function ColorSwatchPicker(props: SpectrumColorSwatchPickerProps, ref: DOMRef<HTMLDivElement>) {
45
- let {
46
- density = 'regular',
47
- size = 'M',
48
- rounding = 'none',
49
- ...otherProps
50
- } = props;
51
- let {styleProps} = useStyleProps(props);
52
- let domRef = useDOMRef(ref);
53
-
54
- return (
55
- <AriaColorSwatchPicker
56
- {...otherProps}
57
- style={styleProps.style}
58
- ref={domRef}
59
- className={styleProps.className + style({
60
- display: 'flex',
61
- flexWrap: 'wrap',
62
- gap: {
63
- density: {
64
- compact: 0.5,
65
- regular: 1,
66
- spacious: 2
67
- }
68
- }
69
- })({density})}>
70
- <SpectrumColorSwatchContext.Provider value={{useWrapper, size, rounding}}>
71
- {props.children}
72
- </SpectrumColorSwatchContext.Provider>
73
- </AriaColorSwatchPicker>
74
- );
75
- });
76
-
77
- function useWrapper(swatch: ReactElement, color: Color, rounding: SpectrumColorSwatchProps['rounding']) {
78
- return (
79
- <AriaColorSwatchPickerItem
80
- color={color}
81
- className={renderProps => style({
82
- outlineStyle: {
83
- default: 'none',
84
- isFocusVisible: 'solid'
85
- },
86
- outlineColor: 'focus-ring',
87
- outlineWidth: 2,
88
- outlineOffset: 2,
89
- position: 'relative',
90
- borderRadius: {
91
- rounding: {
92
- none: 'none',
93
- default: 'default',
94
- full: 'full'
95
- }
96
- }
97
- })({...renderProps, rounding})}>
98
- {({isSelected}) => (<>
99
- {swatch}
100
- {isSelected && (
101
- <div
102
- aria-hidden
103
- className={style({
104
- position: 'absolute',
105
- pointerEvents: 'none',
106
- inset: 0,
107
- boxShadow: '[inset 0 0 0 2px var(--spectrum-gray-900), inset 0 0 0 4px var(--spectrum-gray-50)]',
108
- forcedColorAdjust: 'none',
109
- borderRadius: '[inherit]'
110
- })()} />
111
- )}
112
- </>)}
113
- </AriaColorSwatchPickerItem>
114
- );
115
- }
@@ -1,114 +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} from '@react-spectrum/utils';
14
- import {Color} from '@react-types/color';
15
- import {DOMProps, RefObject} from '@react-types/shared';
16
- import {Overlay} from '@react-spectrum/overlays';
17
- import React, {CSSProperties, JSX, ReactElement, useRef, useState} from 'react';
18
- import stylesHandle from '@adobe/spectrum-css-temp/components/colorhandle/vars.css';
19
- import stylesLoupe from '@adobe/spectrum-css-temp/components/colorloupe/vars.css';
20
- import {useId, useLayoutEffect} from '@react-aria/utils';
21
- import {useProvider} from '@react-spectrum/provider';
22
-
23
- interface ColorThumbProps extends DOMProps {
24
- value: Color,
25
- isDisabled?: boolean,
26
- isDragging?: boolean, // shows the color loupe
27
- isFocused?: boolean, // makes the circle larger
28
- className?: string,
29
- children?: ReactElement,
30
- style?: CSSProperties,
31
- containerRef?: RefObject<HTMLElement | null>
32
- }
33
-
34
- function ColorThumb(props: ColorThumbProps): JSX.Element {
35
- let {value, isDisabled, isDragging, isFocused, children, className = '', style, containerRef, ...otherProps} = props;
36
-
37
- let valueCSS = value.toString('css');
38
- let loupeRef = useRef<HTMLElement | null>(null);
39
- let provider = useProvider();
40
-
41
- return (
42
- <div className={classNames(stylesHandle, 'spectrum-ColorHandle', {'is-focused': isFocused, 'is-disabled': isDisabled}) + ' ' + className} style={style} {...otherProps}>
43
- <div className={classNames(stylesHandle, 'spectrum-ColorHandle-color')} style={{backgroundColor: valueCSS}} />
44
- <Overlay isOpen={isDragging && provider != null} nodeRef={loupeRef}>
45
- <ColorLoupe valueCSS={valueCSS} containerRef={containerRef} loupeRef={loupeRef} style={style} />
46
- </Overlay>
47
- {children}
48
- </div>
49
- );
50
- }
51
-
52
- // ColorLoupe is rendered in a portal so that it breaks out of clipped/scrolling containers (e.g. popovers).
53
- function ColorLoupe({isOpen, valueCSS, containerRef, loupeRef, style}: any) {
54
- let patternId = useId();
55
-
56
- // Get the bounding rectangle of the container (e.g. ColorArea/ColorSlider).
57
- let [containerRect, setContainerRect] = useState({top: 0, left: 0, width: 0, height: 0});
58
- useLayoutEffect(() => {
59
- let rect = containerRef.current?.getBoundingClientRect();
60
- setContainerRect({
61
- top: rect?.top || 0,
62
- left: rect?.left || 0,
63
- width: rect?.width || 0,
64
- height: rect?.height || 0
65
- });
66
- }, [containerRef]);
67
-
68
- // Compute the pixel position of the thumb.
69
- let thumbTop = style.top || '50%';
70
- if (typeof thumbTop === 'string' && thumbTop.endsWith('%')) {
71
- thumbTop = parseFloat(style.top || '50%') / 100 * containerRect.height;
72
- } else if (typeof thumbTop === 'string' && thumbTop.endsWith('px')) {
73
- thumbTop = parseFloat(thumbTop);
74
- }
75
-
76
- let thumbLeft = style.left || '50%';
77
- if (typeof thumbLeft === 'string' && thumbLeft.endsWith('%')) {
78
- thumbLeft = parseFloat(thumbLeft || '50%') / 100 * containerRect.width;
79
- } else if (typeof thumbLeft === 'string' && thumbLeft.endsWith('px')) {
80
- thumbLeft = parseFloat(thumbLeft);
81
- }
82
-
83
- return (
84
- <svg
85
- className={classNames(stylesLoupe, 'spectrum-ColorLoupe', {'is-open': isOpen})}
86
- style={{
87
- // Position relative to the viewport.
88
- position: 'fixed',
89
- top: containerRect.top + thumbTop,
90
- left: containerRect.left + thumbLeft
91
- }}
92
- ref={loupeRef}
93
- aria-hidden="true">
94
- <pattern id={patternId} x="0" y="0" width="16" height="16" patternUnits="userSpaceOnUse">
95
- <rect className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner-background')} x="0" y="0" width="16" height="16" />
96
- <rect className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner-checker')} x="0" y="0" width="8" height="8" />
97
- <rect className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner-checker')} x="8" y="8" width="8" height="8" />
98
- </pattern>
99
- <path
100
- className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner')}
101
- d="M25 1a24 24 0 0124 24c0 16.255-24 40-24 40S1 41.255 1 25A24 24 0 0125 1z"
102
- fill={`url(#${patternId})`} />
103
- <path
104
- className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner')}
105
- d="M25 1a24 24 0 0124 24c0 16.255-24 40-24 40S1 41.255 1 25A24 24 0 0125 1z"
106
- fill={valueCSS} />
107
- <path
108
- className={classNames(stylesLoupe, 'spectrum-ColorLoupe-outer')}
109
- d="M25 3A21.98 21.98 0 003 25c0 6.2 4 14.794 11.568 24.853A144.233 144.233 0 0025 62.132a144.085 144.085 0 0010.4-12.239C42.99 39.816 47 31.209 47 25A21.98 21.98 0 0025 3m0-2a24 24 0 0124 24c0 16.255-24 40-24 40S1 41.255 1 25A24 24 0 0125 1z" />
110
- </svg>
111
- );
112
- }
113
-
114
- export {ColorThumb};
@@ -1,110 +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, dimensionValue, useFocusableRef, useStyleProps} from '@react-spectrum/utils';
14
- import {ColorThumb} from './ColorThumb';
15
- import {ColorWheelContext, useContextProps} from 'react-aria-components';
16
- import {FocusableRef} from '@react-types/shared';
17
- import React, {useCallback, useRef, useState} from 'react';
18
- import {SpectrumColorWheelProps} from '@react-types/color';
19
- import styles from '@adobe/spectrum-css-temp/components/colorwheel/vars.css';
20
- import {useColorWheel} from '@react-aria/color';
21
- import {useColorWheelState} from '@react-stately/color';
22
- import {useFocusRing} from '@react-aria/focus';
23
- import {useLayoutEffect, useResizeObserver} from '@react-aria/utils';
24
- import {useProviderProps} from '@react-spectrum/provider';
25
-
26
- const WHEEL_THICKNESS = 24;
27
-
28
- /**
29
- * ColorWheels allow users to adjust the hue of an HSL or HSB color value on a circular track.
30
- */
31
- export const ColorWheel = React.forwardRef(function ColorWheel(props: SpectrumColorWheelProps, ref: FocusableRef<HTMLDivElement>) {
32
- props = useProviderProps(props);
33
- let inputRef = useRef(null);
34
- let containerRef = useFocusableRef(ref, inputRef);
35
- [props, containerRef] = useContextProps(props, containerRef, ColorWheelContext);
36
-
37
- let {isDisabled} = props;
38
- let size = props.size && dimensionValue(props.size);
39
- let {styleProps} = useStyleProps(props);
40
-
41
-
42
- let [wheelRadius, setWheelRadius] = useState<number>(0);
43
- let [wheelThickness, setWheelThickness] = useState(WHEEL_THICKNESS);
44
-
45
- let resizeHandler = useCallback(() => {
46
- if (containerRef.current) {
47
- setWheelRadius(containerRef.current.offsetWidth / 2);
48
- let thickness = window.getComputedStyle(containerRef.current)
49
- .getPropertyValue('--spectrum-colorwheel-track-thickness');
50
- if (thickness) {
51
- setWheelThickness(parseInt(thickness, 10));
52
- }
53
- }
54
- }, [containerRef, setWheelRadius, setWheelThickness]);
55
-
56
- useLayoutEffect(() => {
57
- // the size observer's fallback to the window resize event doesn't fire on mount
58
- if (wheelRadius === 0) {
59
- resizeHandler();
60
- }
61
- }, [wheelRadius, resizeHandler]);
62
-
63
- useResizeObserver({
64
- ref: containerRef,
65
- onResize: resizeHandler
66
- });
67
-
68
- let state = useColorWheelState(props);
69
-
70
- let {trackProps, inputProps, thumbProps} = useColorWheel({
71
- ...props,
72
- innerRadius: wheelRadius - wheelThickness,
73
- outerRadius: wheelRadius
74
- }, state, inputRef);
75
-
76
- let {focusProps, isFocusVisible} = useFocusRing();
77
-
78
- return (
79
- <div
80
- className={
81
- classNames(
82
- styles,
83
- 'spectrum-ColorWheel',
84
- {
85
- 'is-disabled': isDisabled
86
- },
87
- styleProps.className
88
- )
89
- }
90
- ref={containerRef}
91
- style={{
92
- ...styleProps.style,
93
- // Workaround around https://github.com/adobe/spectrum-css/issues/1032
94
- 'width': size,
95
- 'height': size
96
- }}>
97
- <div {...trackProps} className={classNames(styles, 'spectrum-ColorWheel-gradient')} />
98
- <ColorThumb
99
- value={state.getDisplayColor()}
100
- isFocused={isFocusVisible}
101
- isDisabled={isDisabled}
102
- isDragging={state.isDragging}
103
- containerRef={containerRef}
104
- className={classNames(styles, 'spectrum-ColorWheel-handle')}
105
- {...thumbProps}>
106
- <input {...focusProps} className={classNames(styles, 'spectrum-ColorWheel-slider')} {...inputProps} ref={inputRef} />
107
- </ColorThumb>
108
- </div>
109
- );
110
- });
@@ -1,18 +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
- .react-spectrum-ColorField-input:not(:placeholder-shown) {
14
- unicode-bidi: plaintext;
15
- &:dir(rtl) {
16
- text-align: end;
17
- }
18
- }