@react-spectrum/color 3.0.0-nightly.4567 → 3.0.0-nightly.4582

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 (96) hide show
  1. package/dist/ColorArea.main.js +11 -10
  2. package/dist/ColorArea.main.js.map +1 -1
  3. package/dist/ColorArea.mjs +12 -11
  4. package/dist/ColorArea.module.js +12 -11
  5. package/dist/ColorArea.module.js.map +1 -1
  6. package/dist/ColorEditor.32e497e8.css +20 -0
  7. package/dist/ColorEditor.32e497e8.css.map +1 -0
  8. package/dist/ColorEditor.main.js +116 -0
  9. package/dist/ColorEditor.main.js.map +1 -0
  10. package/dist/ColorEditor.mjs +111 -0
  11. package/dist/ColorEditor.module.js +111 -0
  12. package/dist/ColorEditor.module.js.map +1 -0
  13. package/dist/ColorField.main.js +44 -6
  14. package/dist/ColorField.main.js.map +1 -1
  15. package/dist/ColorField.mjs +46 -8
  16. package/dist/ColorField.module.js +46 -8
  17. package/dist/ColorField.module.js.map +1 -1
  18. package/dist/ColorPicker.ab9f47c0.css +204 -0
  19. package/dist/ColorPicker.ab9f47c0.css.map +1 -0
  20. package/dist/ColorPicker.main.js +125 -0
  21. package/dist/ColorPicker.main.js.map +1 -0
  22. package/dist/ColorPicker.mjs +116 -0
  23. package/dist/ColorPicker.module.js +116 -0
  24. package/dist/ColorPicker.module.js.map +1 -0
  25. package/dist/ColorSlider.main.js +8 -4
  26. package/dist/ColorSlider.main.js.map +1 -1
  27. package/dist/ColorSlider.mjs +9 -5
  28. package/dist/ColorSlider.module.js +9 -5
  29. package/dist/ColorSlider.module.js.map +1 -1
  30. package/dist/ColorSwatch.f6e6f811.css +260 -0
  31. package/dist/ColorSwatch.f6e6f811.css.map +1 -0
  32. package/dist/ColorSwatch.main.js +94 -0
  33. package/dist/ColorSwatch.main.js.map +1 -0
  34. package/dist/ColorSwatch.mjs +84 -0
  35. package/dist/ColorSwatch.module.js +84 -0
  36. package/dist/ColorSwatch.module.js.map +1 -0
  37. package/dist/ColorSwatchPicker.1575be06.css +356 -0
  38. package/dist/ColorSwatchPicker.1575be06.css.map +1 -0
  39. package/dist/ColorSwatchPicker.main.js +115 -0
  40. package/dist/ColorSwatchPicker.main.js.map +1 -0
  41. package/dist/ColorSwatchPicker.mjs +106 -0
  42. package/dist/ColorSwatchPicker.module.js +106 -0
  43. package/dist/ColorSwatchPicker.module.js.map +1 -0
  44. package/dist/ColorThumb.main.js +57 -7
  45. package/dist/ColorThumb.main.js.map +1 -1
  46. package/dist/ColorThumb.mjs +59 -9
  47. package/dist/ColorThumb.module.js +59 -9
  48. package/dist/ColorThumb.module.js.map +1 -1
  49. package/dist/ColorWheel.main.js +6 -2
  50. package/dist/ColorWheel.main.js.map +1 -1
  51. package/dist/ColorWheel.mjs +7 -3
  52. package/dist/ColorWheel.module.js +7 -3
  53. package/dist/ColorWheel.module.js.map +1 -1
  54. package/dist/colorarea_vars_css.main.js +0 -3
  55. package/dist/colorarea_vars_css.main.js.map +1 -1
  56. package/dist/colorarea_vars_css.mjs +0 -3
  57. package/dist/colorarea_vars_css.module.js +0 -3
  58. package/dist/colorarea_vars_css.module.js.map +1 -1
  59. package/dist/en-US.main.js +10 -0
  60. package/dist/en-US.main.js.map +1 -0
  61. package/dist/en-US.mjs +12 -0
  62. package/dist/en-US.module.js +12 -0
  63. package/dist/en-US.module.js.map +1 -0
  64. package/dist/import.mjs +11 -1
  65. package/dist/intlStrings.main.js +9 -0
  66. package/dist/intlStrings.main.js.map +1 -0
  67. package/dist/intlStrings.mjs +11 -0
  68. package/dist/intlStrings.module.js +11 -0
  69. package/dist/intlStrings.module.js.map +1 -0
  70. package/dist/main.js +16 -0
  71. package/dist/main.js.map +1 -1
  72. package/dist/module.js +11 -1
  73. package/dist/module.js.map +1 -1
  74. package/dist/types.d.ts +75 -4
  75. package/dist/types.d.ts.map +1 -1
  76. package/dist/{vars.08ba4b4c.css → vars.53b417c1.css} +2 -3
  77. package/dist/vars.53b417c1.css.map +1 -0
  78. package/dist/{vars.6f3d3943.css → vars.6fa9fa04.css} +6 -18
  79. package/dist/vars.6fa9fa04.css.map +1 -0
  80. package/dist/{vars.571f903e.css → vars.aa07b6d2.css} +2 -2
  81. package/dist/{vars.571f903e.css.map → vars.aa07b6d2.css.map} +1 -1
  82. package/dist/{vars.ef2c01b8.css → vars.cc682729.css} +4 -4
  83. package/dist/{vars.ef2c01b8.css.map → vars.cc682729.css.map} +1 -1
  84. package/package.json +23 -17
  85. package/src/ColorArea.tsx +7 -6
  86. package/src/ColorEditor.tsx +63 -0
  87. package/src/ColorField.tsx +67 -14
  88. package/src/ColorPicker.tsx +122 -0
  89. package/src/ColorSlider.tsx +6 -4
  90. package/src/ColorSwatch.tsx +102 -0
  91. package/src/ColorSwatchPicker.tsx +118 -0
  92. package/src/ColorThumb.tsx +72 -25
  93. package/src/ColorWheel.tsx +5 -2
  94. package/src/index.ts +10 -0
  95. package/dist/vars.08ba4b4c.css.map +0 -1
  96. package/dist/vars.6f3d3943.css.map +0 -1
@@ -0,0 +1,118 @@
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 | null, 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
+ function ColorSwatchPicker(props: SpectrumColorSwatchPickerProps, ref: DOMRef<HTMLDivElement>) {
42
+ let {
43
+ density = 'regular',
44
+ size = 'M',
45
+ rounding = 'none',
46
+ ...otherProps
47
+ } = props;
48
+ let {styleProps} = useStyleProps(props);
49
+ let domRef = useDOMRef(ref);
50
+
51
+ return (
52
+ <AriaColorSwatchPicker
53
+ {...otherProps}
54
+ style={styleProps.style}
55
+ ref={domRef}
56
+ className={styleProps.className + style({
57
+ display: 'flex',
58
+ flexWrap: 'wrap',
59
+ gap: {
60
+ density: {
61
+ compact: 0.5,
62
+ regular: 1,
63
+ spacious: 2
64
+ }
65
+ }
66
+ })({density})}>
67
+ <SpectrumColorSwatchContext.Provider value={{useWrapper, size, rounding}}>
68
+ {props.children}
69
+ </SpectrumColorSwatchContext.Provider>
70
+ </AriaColorSwatchPicker>
71
+ );
72
+ }
73
+
74
+ /**
75
+ * A ColorSwatchPicker displays a list of color swatches and allows a user to select one of them.
76
+ */
77
+ let _ColorSwatchPicker = forwardRef(ColorSwatchPicker);
78
+ export {_ColorSwatchPicker as ColorSwatchPicker};
79
+
80
+ function useWrapper(swatch: ReactElement, color: Color, rounding: SpectrumColorSwatchProps['rounding']) {
81
+ return (
82
+ <AriaColorSwatchPickerItem
83
+ color={color}
84
+ className={renderProps => style({
85
+ outlineStyle: {
86
+ default: 'none',
87
+ isFocusVisible: 'solid'
88
+ },
89
+ outlineColor: 'focus-ring',
90
+ outlineWidth: 2,
91
+ outlineOffset: 2,
92
+ position: 'relative',
93
+ borderRadius: {
94
+ rounding: {
95
+ none: 'none',
96
+ default: 'default',
97
+ full: 'full'
98
+ }
99
+ }
100
+ })({...renderProps, rounding})}>
101
+ {({isSelected}) => (<>
102
+ {swatch}
103
+ {isSelected && (
104
+ <div
105
+ aria-hidden
106
+ className={style({
107
+ position: 'absolute',
108
+ pointerEvents: 'none',
109
+ inset: 0,
110
+ boxShadow: '[inset 0 0 0 2px var(--spectrum-gray-900), inset 0 0 0 4px var(--spectrum-gray-50)]',
111
+ forcedColorAdjust: 'none',
112
+ borderRadius: '[inherit]'
113
+ })()} />
114
+ )}
115
+ </>)}
116
+ </AriaColorSwatchPickerItem>
117
+ );
118
+ }
@@ -13,10 +13,12 @@
13
13
  import {classNames} from '@react-spectrum/utils';
14
14
  import {Color} from '@react-types/color';
15
15
  import {DOMProps} from '@react-types/shared';
16
- import React, {ReactElement} from 'react';
16
+ import {Overlay} from '@react-spectrum/overlays';
17
+ import React, {CSSProperties, ReactElement, RefObject, useRef, useState} from 'react';
17
18
  import stylesHandle from '@adobe/spectrum-css-temp/components/colorhandle/vars.css';
18
19
  import stylesLoupe from '@adobe/spectrum-css-temp/components/colorloupe/vars.css';
19
- import {useId} from '@react-aria/utils';
20
+ import {useId, useLayoutEffect} from '@react-aria/utils';
21
+ import {useProvider} from '@react-spectrum/provider';
20
22
 
21
23
  interface ColorThumbProps extends DOMProps {
22
24
  value: Color,
@@ -24,40 +26,85 @@ interface ColorThumbProps extends DOMProps {
24
26
  isDragging?: boolean, // shows the color loupe
25
27
  isFocused?: boolean, // makes the circle larger
26
28
  className?: string,
27
- children?: ReactElement
29
+ children?: ReactElement,
30
+ style?: CSSProperties,
31
+ containerRef?: RefObject<HTMLElement>
28
32
  }
29
33
 
30
34
  function ColorThumb(props: ColorThumbProps) {
31
- let {value, isDisabled, isDragging, isFocused, children, className = '', ...otherProps} = props;
32
-
33
- let patternId = useId();
35
+ let {value, isDisabled, isDragging, isFocused, children, className = '', style, containerRef, ...otherProps} = props;
34
36
 
35
37
  let valueCSS = value.toString('css');
38
+ let loupeRef = useRef<HTMLElement | null>(null);
39
+ let provider = useProvider();
36
40
 
37
41
  return (
38
- <div className={classNames(stylesHandle, 'spectrum-ColorHandle', {'is-focused': isFocused, 'is-disabled': isDisabled}) + ' ' + className} {...otherProps}>
42
+ <div className={classNames(stylesHandle, 'spectrum-ColorHandle', {'is-focused': isFocused, 'is-disabled': isDisabled}) + ' ' + className} style={style} {...otherProps}>
39
43
  <div className={classNames(stylesHandle, 'spectrum-ColorHandle-color')} style={{backgroundColor: valueCSS}} />
40
- <svg className={classNames(stylesLoupe, 'spectrum-ColorLoupe', {'is-open': isDragging})} aria-hidden="true">
41
- <pattern id={patternId} x="0" y="0" width="16" height="16" patternUnits="userSpaceOnUse">
42
- <rect className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner-background')} x="0" y="0" width="16" height="16" />
43
- <rect className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner-checker')} x="0" y="0" width="8" height="8" />
44
- <rect className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner-checker')} x="8" y="8" width="8" height="8" />
45
- </pattern>
46
- <path
47
- className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner')}
48
- d="M25 1a24 24 0 0124 24c0 16.255-24 40-24 40S1 41.255 1 25A24 24 0 0125 1z"
49
- fill={`url(#${patternId})`} />
50
- <path
51
- className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner')}
52
- d="M25 1a24 24 0 0124 24c0 16.255-24 40-24 40S1 41.255 1 25A24 24 0 0125 1z"
53
- fill={valueCSS} />
54
- <path
55
- className={classNames(stylesLoupe, 'spectrum-ColorLoupe-outer')}
56
- 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" />
57
- </svg>
44
+ <Overlay isOpen={isDragging && provider != null} nodeRef={loupeRef}>
45
+ <ColorLoupe valueCSS={valueCSS} containerRef={containerRef} loupeRef={loupeRef} style={style} />
46
+ </Overlay>
58
47
  {children}
59
48
  </div>
60
49
  );
61
50
  }
62
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
+ }
73
+
74
+ let thumbLeft = style.left || '50%';
75
+ if (typeof thumbLeft === 'string' && thumbLeft.endsWith('%')) {
76
+ thumbLeft = parseFloat(thumbLeft || '50%') / 100 * containerRect.width;
77
+ }
78
+
79
+ return (
80
+ <svg
81
+ className={classNames(stylesLoupe, 'spectrum-ColorLoupe', {'is-open': isOpen})}
82
+ style={{
83
+ // Position relative to the viewport.
84
+ position: 'fixed',
85
+ top: containerRect.top + thumbTop,
86
+ left: containerRect.left + thumbLeft
87
+ }}
88
+ ref={loupeRef}
89
+ aria-hidden="true">
90
+ <pattern id={patternId} x="0" y="0" width="16" height="16" patternUnits="userSpaceOnUse">
91
+ <rect className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner-background')} x="0" y="0" width="16" height="16" />
92
+ <rect className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner-checker')} x="0" y="0" width="8" height="8" />
93
+ <rect className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner-checker')} x="8" y="8" width="8" height="8" />
94
+ </pattern>
95
+ <path
96
+ className={classNames(stylesLoupe, 'spectrum-ColorLoupe-inner')}
97
+ d="M25 1a24 24 0 0124 24c0 16.255-24 40-24 40S1 41.255 1 25A24 24 0 0125 1z"
98
+ fill={`url(#${patternId})`} />
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={valueCSS} />
103
+ <path
104
+ className={classNames(stylesLoupe, 'spectrum-ColorLoupe-outer')}
105
+ 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" />
106
+ </svg>
107
+ );
108
+ }
109
+
63
110
  export {ColorThumb};
@@ -12,6 +12,7 @@
12
12
 
13
13
  import {classNames, dimensionValue, useFocusableRef, useStyleProps} from '@react-spectrum/utils';
14
14
  import {ColorThumb} from './ColorThumb';
15
+ import {ColorWheelContext, useContextProps} from 'react-aria-components';
15
16
  import {FocusableRef} from '@react-types/shared';
16
17
  import React, {useCallback, useEffect, useRef, useState} from 'react';
17
18
  import {SpectrumColorWheelProps} from '@react-types/color';
@@ -26,13 +27,14 @@ const WHEEL_THICKNESS = 24;
26
27
 
27
28
  function ColorWheel(props: SpectrumColorWheelProps, ref: FocusableRef<HTMLDivElement>) {
28
29
  props = useProviderProps(props);
30
+ let inputRef = useRef(null);
31
+ let containerRef = useFocusableRef(ref, inputRef);
32
+ [props, containerRef] = useContextProps(props, containerRef, ColorWheelContext);
29
33
 
30
34
  let {isDisabled} = props;
31
35
  let size = props.size && dimensionValue(props.size);
32
36
  let {styleProps} = useStyleProps(props);
33
37
 
34
- let inputRef = useRef(null);
35
- let containerRef = useFocusableRef(ref, inputRef);
36
38
 
37
39
  let [wheelRadius, setWheelRadius] = useState<number>(0);
38
40
  let [wheelThickness, setWheelThickness] = useState(WHEEL_THICKNESS);
@@ -96,6 +98,7 @@ function ColorWheel(props: SpectrumColorWheelProps, ref: FocusableRef<HTMLDivEle
96
98
  isFocused={isFocusVisible}
97
99
  isDisabled={isDisabled}
98
100
  isDragging={state.isDragging}
101
+ containerRef={containerRef}
99
102
  className={classNames(styles, 'spectrum-ColorWheel-handle')}
100
103
  {...thumbProps}>
101
104
  <input {...focusProps} className={classNames(styles, 'spectrum-ColorWheel-slider')} {...inputProps} ref={inputRef} />
package/src/index.ts CHANGED
@@ -15,4 +15,14 @@ export {ColorArea} from './ColorArea';
15
15
  export {ColorWheel} from './ColorWheel';
16
16
  export {ColorSlider} from './ColorSlider';
17
17
  export {ColorField} from './ColorField';
18
+ export {ColorSwatch} from './ColorSwatch';
19
+ export {ColorPicker} from './ColorPicker';
20
+ export {ColorEditor} from './ColorEditor';
21
+ export {ColorSwatchPicker} from './ColorSwatchPicker';
22
+ export {parseColor, getColorChannels} from '@react-stately/color';
18
23
  export type {SpectrumColorAreaProps, SpectrumColorFieldProps, SpectrumColorSliderProps, SpectrumColorWheelProps} from '@react-types/color';
24
+ export type {SpectrumColorSwatchProps} from './ColorSwatch';
25
+ export type {SpectrumColorPickerProps} from './ColorPicker';
26
+ export type {SpectrumColorEditorProps} from './ColorEditor';
27
+ export type {SpectrumColorSwatchPickerProps} from './ColorSwatchPicker';
28
+ export type {Color, ColorSpace, ColorFormat} from '@react-types/color';
@@ -1 +0,0 @@
1
- {"mappings":"AAYA;;;;;;;;;;;;;;;;;AA8BE;;;;;;;;;;;AAeA;;;;AAKF;;;;;;;AAcA;;;;;;AAMA;;;;;;;AAaE;;;;;;AAKE;;;;AAMJ;;;;AAIA;EACE","sources":["packages/@adobe/spectrum-css-temp/components/colorhandle/vars.css"],"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\n@import './index.css';\n@import './skin.css';\n"],"names":[],"version":3,"file":"vars.08ba4b4c.css.map"}
@@ -1 +0,0 @@
1
- {"mappings":"AAYA;;;;;;;;;;;;;AAcE;;;;AAIE;;;;;;;AAJF;;;;AAIE;;;;;;;AAUF;;;;AAKA;;;;;;;;AAYF;;;;;AAIE;;;;AAKF;;;;;;AAMA;;;;;;;;;;;;AAaI;;;;AAKJ;;;;AASI;;;;AAGE;;;;AAIA;;;;AAMN;EACI;;;;;EAKE","sources":["packages/@adobe/spectrum-css-temp/components/colorarea/vars.css"],"sourcesContent":["/*\n * Copyright 2021 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\n@import './index.css';\n@import './skin.css';\n"],"names":[],"version":3,"file":"vars.6f3d3943.css.map"}