@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.
- package/dist/ar-AE.main.js +11 -0
- package/dist/ar-AE.main.js.map +1 -0
- package/dist/ar-AE.mjs +13 -0
- package/dist/ar-AE.module.js +13 -0
- package/dist/ar-AE.module.js.map +1 -0
- package/dist/bg-BG.main.js +11 -0
- package/dist/bg-BG.main.js.map +1 -0
- package/dist/bg-BG.mjs +13 -0
- package/dist/bg-BG.module.js +13 -0
- package/dist/bg-BG.module.js.map +1 -0
- package/dist/cs-CZ.main.js +11 -0
- package/dist/cs-CZ.main.js.map +1 -0
- package/dist/cs-CZ.mjs +13 -0
- package/dist/cs-CZ.module.js +13 -0
- package/dist/cs-CZ.module.js.map +1 -0
- package/dist/da-DK.main.js +11 -0
- package/dist/da-DK.main.js.map +1 -0
- package/dist/da-DK.mjs +13 -0
- package/dist/da-DK.module.js +13 -0
- package/dist/da-DK.module.js.map +1 -0
- package/dist/de-DE.main.js +11 -0
- package/dist/de-DE.main.js.map +1 -0
- package/dist/de-DE.mjs +13 -0
- package/dist/de-DE.module.js +13 -0
- package/dist/de-DE.module.js.map +1 -0
- package/dist/el-GR.main.js +11 -0
- package/dist/el-GR.main.js.map +1 -0
- package/dist/el-GR.mjs +13 -0
- package/dist/el-GR.module.js +13 -0
- package/dist/el-GR.module.js.map +1 -0
- package/dist/en-US.main.js +11 -0
- package/dist/en-US.main.js.map +1 -0
- package/dist/en-US.mjs +13 -0
- package/dist/en-US.module.js +13 -0
- package/dist/en-US.module.js.map +1 -0
- package/dist/es-ES.main.js +11 -0
- package/dist/es-ES.main.js.map +1 -0
- package/dist/es-ES.mjs +13 -0
- package/dist/es-ES.module.js +13 -0
- package/dist/es-ES.module.js.map +1 -0
- package/dist/et-EE.main.js +11 -0
- package/dist/et-EE.main.js.map +1 -0
- package/dist/et-EE.mjs +13 -0
- package/dist/et-EE.module.js +13 -0
- package/dist/et-EE.module.js.map +1 -0
- package/dist/fi-FI.main.js +11 -0
- package/dist/fi-FI.main.js.map +1 -0
- package/dist/fi-FI.mjs +13 -0
- package/dist/fi-FI.module.js +13 -0
- package/dist/fi-FI.module.js.map +1 -0
- package/dist/fr-FR.main.js +11 -0
- package/dist/fr-FR.main.js.map +1 -0
- package/dist/fr-FR.mjs +13 -0
- package/dist/fr-FR.module.js +13 -0
- package/dist/fr-FR.module.js.map +1 -0
- package/dist/he-IL.main.js +11 -0
- package/dist/he-IL.main.js.map +1 -0
- package/dist/he-IL.mjs +13 -0
- package/dist/he-IL.module.js +13 -0
- package/dist/he-IL.module.js.map +1 -0
- package/dist/hr-HR.main.js +11 -0
- package/dist/hr-HR.main.js.map +1 -0
- package/dist/hr-HR.mjs +13 -0
- package/dist/hr-HR.module.js +13 -0
- package/dist/hr-HR.module.js.map +1 -0
- package/dist/hu-HU.main.js +11 -0
- package/dist/hu-HU.main.js.map +1 -0
- package/dist/hu-HU.mjs +13 -0
- package/dist/hu-HU.module.js +13 -0
- package/dist/hu-HU.module.js.map +1 -0
- package/dist/import.mjs +7 -1357
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/it-IT.main.js +11 -0
- package/dist/it-IT.main.js.map +1 -0
- package/dist/it-IT.mjs +13 -0
- package/dist/it-IT.module.js +13 -0
- package/dist/it-IT.module.js.map +1 -0
- package/dist/ja-JP.main.js +11 -0
- package/dist/ja-JP.main.js.map +1 -0
- package/dist/ja-JP.mjs +13 -0
- package/dist/ja-JP.module.js +13 -0
- package/dist/ja-JP.module.js.map +1 -0
- package/dist/ko-KR.main.js +11 -0
- package/dist/ko-KR.main.js.map +1 -0
- package/dist/ko-KR.mjs +13 -0
- package/dist/ko-KR.module.js +13 -0
- package/dist/ko-KR.module.js.map +1 -0
- package/dist/lt-LT.main.js +11 -0
- package/dist/lt-LT.main.js.map +1 -0
- package/dist/lt-LT.mjs +13 -0
- package/dist/lt-LT.module.js +13 -0
- package/dist/lt-LT.module.js.map +1 -0
- package/dist/lv-LV.main.js +11 -0
- package/dist/lv-LV.main.js.map +1 -0
- package/dist/lv-LV.mjs +13 -0
- package/dist/lv-LV.module.js +13 -0
- package/dist/lv-LV.module.js.map +1 -0
- package/dist/main.js +12 -1360
- package/dist/main.js.map +1 -1
- package/dist/module.js +7 -1357
- package/dist/module.js.map +1 -1
- package/dist/nb-NO.main.js +11 -0
- package/dist/nb-NO.main.js.map +1 -0
- package/dist/nb-NO.mjs +13 -0
- package/dist/nb-NO.module.js +13 -0
- package/dist/nb-NO.module.js.map +1 -0
- package/dist/nl-NL.main.js +11 -0
- package/dist/nl-NL.main.js.map +1 -0
- package/dist/nl-NL.mjs +13 -0
- package/dist/nl-NL.module.js +13 -0
- package/dist/nl-NL.module.js.map +1 -0
- package/dist/pl-PL.main.js +11 -0
- package/dist/pl-PL.main.js.map +1 -0
- package/dist/pl-PL.mjs +13 -0
- package/dist/pl-PL.module.js +13 -0
- package/dist/pl-PL.module.js.map +1 -0
- package/dist/pt-BR.main.js +11 -0
- package/dist/pt-BR.main.js.map +1 -0
- package/dist/pt-BR.mjs +13 -0
- package/dist/pt-BR.module.js +13 -0
- package/dist/pt-BR.module.js.map +1 -0
- package/dist/pt-PT.main.js +11 -0
- package/dist/pt-PT.main.js.map +1 -0
- package/dist/pt-PT.mjs +13 -0
- package/dist/pt-PT.module.js +13 -0
- package/dist/pt-PT.module.js.map +1 -0
- package/dist/ro-RO.main.js +11 -0
- package/dist/ro-RO.main.js.map +1 -0
- package/dist/ro-RO.mjs +13 -0
- package/dist/ro-RO.module.js +13 -0
- package/dist/ro-RO.module.js.map +1 -0
- package/dist/ru-RU.main.js +11 -0
- package/dist/ru-RU.main.js.map +1 -0
- package/dist/ru-RU.mjs +13 -0
- package/dist/ru-RU.module.js +13 -0
- package/dist/ru-RU.module.js.map +1 -0
- package/dist/sk-SK.main.js +11 -0
- package/dist/sk-SK.main.js.map +1 -0
- package/dist/sk-SK.mjs +13 -0
- package/dist/sk-SK.module.js +13 -0
- package/dist/sk-SK.module.js.map +1 -0
- package/dist/sl-SI.main.js +11 -0
- package/dist/sl-SI.main.js.map +1 -0
- package/dist/sl-SI.mjs +13 -0
- package/dist/sl-SI.module.js +13 -0
- package/dist/sl-SI.module.js.map +1 -0
- package/dist/sr-SP.main.js +11 -0
- package/dist/sr-SP.main.js.map +1 -0
- package/dist/sr-SP.mjs +13 -0
- package/dist/sr-SP.module.js +13 -0
- package/dist/sr-SP.module.js.map +1 -0
- package/dist/sv-SE.main.js +11 -0
- package/dist/sv-SE.main.js.map +1 -0
- package/dist/sv-SE.mjs +13 -0
- package/dist/sv-SE.module.js +13 -0
- package/dist/sv-SE.module.js.map +1 -0
- package/dist/tr-TR.main.js +11 -0
- package/dist/tr-TR.main.js.map +1 -0
- package/dist/tr-TR.mjs +13 -0
- package/dist/tr-TR.module.js +13 -0
- package/dist/tr-TR.module.js.map +1 -0
- package/dist/types.d.ts +41 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.main.js +11 -0
- package/dist/uk-UA.main.js.map +1 -0
- package/dist/uk-UA.mjs +13 -0
- package/dist/uk-UA.module.js +13 -0
- package/dist/uk-UA.module.js.map +1 -0
- package/dist/useColorArea.main.js +404 -0
- package/dist/useColorArea.main.js.map +1 -0
- package/dist/useColorArea.mjs +399 -0
- package/dist/useColorArea.module.js +399 -0
- package/dist/useColorArea.module.js.map +1 -0
- package/dist/useColorAreaGradient.main.js +123 -0
- package/dist/useColorAreaGradient.main.js.map +1 -0
- package/dist/useColorAreaGradient.mjs +118 -0
- package/dist/useColorAreaGradient.module.js +118 -0
- package/dist/useColorAreaGradient.module.js.map +1 -0
- package/dist/useColorChannelField.main.js +36 -0
- package/dist/useColorChannelField.main.js.map +1 -0
- package/dist/useColorChannelField.mjs +31 -0
- package/dist/useColorChannelField.module.js +31 -0
- package/dist/useColorChannelField.module.js.map +1 -0
- package/dist/useColorField.main.js +98 -0
- package/dist/useColorField.main.js.map +1 -0
- package/dist/useColorField.mjs +93 -0
- package/dist/useColorField.module.js +93 -0
- package/dist/useColorField.module.js.map +1 -0
- package/dist/useColorSlider.main.js +132 -0
- package/dist/useColorSlider.main.js.map +1 -0
- package/dist/useColorSlider.mjs +127 -0
- package/dist/useColorSlider.module.js +127 -0
- package/dist/useColorSlider.module.js.map +1 -0
- package/dist/useColorSwatch.main.js +67 -0
- package/dist/useColorSwatch.main.js.map +1 -0
- package/dist/useColorSwatch.mjs +62 -0
- package/dist/useColorSwatch.module.js +62 -0
- package/dist/useColorSwatch.module.js.map +1 -0
- package/dist/useColorWheel.main.js +274 -0
- package/dist/useColorWheel.main.js.map +1 -0
- package/dist/useColorWheel.mjs +269 -0
- package/dist/useColorWheel.module.js +269 -0
- package/dist/useColorWheel.module.js.map +1 -0
- package/dist/zh-CN.main.js +11 -0
- package/dist/zh-CN.main.js.map +1 -0
- package/dist/zh-CN.mjs +13 -0
- package/dist/zh-CN.module.js +13 -0
- package/dist/zh-CN.module.js.map +1 -0
- package/dist/zh-TW.main.js +11 -0
- package/dist/zh-TW.main.js.map +1 -0
- package/dist/zh-TW.mjs +13 -0
- package/dist/zh-TW.module.js +13 -0
- package/dist/zh-TW.module.js.map +1 -0
- package/package.json +14 -13
- package/src/index.ts +4 -0
- package/src/useColorArea.ts +32 -23
- package/src/useColorAreaGradient.ts +66 -189
- package/src/useColorChannelField.ts +37 -0
- package/src/useColorField.ts +18 -14
- package/src/useColorSlider.ts +28 -4
- package/src/useColorSwatch.ts +74 -0
- package/src/useColorWheel.ts +19 -5
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var $b0fef28529309aa6$exports = {};
|
|
2
|
+
$b0fef28529309aa6$exports = {
|
|
3
|
+
"colorInputLabel": (args)=>`${args.label}\u{FF0C}${args.channelLabel}`,
|
|
4
|
+
"colorNameAndValue": (args)=>`${args.name}\u{FF1A}${args.value}`,
|
|
5
|
+
"colorPicker": `\u{6AA2}\u{8272}\u{5668}`,
|
|
6
|
+
"twoDimensionalSlider": `2D \u{6ED1}\u{687F}`,
|
|
7
|
+
"colorSwatch": `color swatch`,
|
|
8
|
+
"transparent": `transparent`
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export {$b0fef28529309aa6$exports as default};
|
|
13
|
+
//# sourceMappingURL=zh-TW.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAAA,4BAAiB;IAAG,mBAAmB,CAAC,OAAS,CAAC,EAAE,KAAK,KAAK,CAAC,QAAC,EAAE,KAAK,YAAY,CAAC,CAAC;IACnF,qBAAqB,CAAC,OAAS,CAAC,EAAE,KAAK,IAAI,CAAC,QAAC,EAAE,KAAK,KAAK,CAAC,CAAC;IAC3D,eAAe,CAAC,wBAAG,CAAC;IACpB,wBAAwB,CAAC,mBAAK,CAAC;IAC/B,eAAe,CAAC,YAAY,CAAC;IAC7B,eAAe,CAAC,WAAW,CAAC;AAC9B","sources":["packages/@react-aria/color/intl/zh-TW.json"],"sourcesContent":["{\n \"colorInputLabel\": \"{label},{channelLabel}\",\n \"colorNameAndValue\": \"{name}:{value}\",\n \"colorPicker\": \"檢色器\",\n \"twoDimensionalSlider\": \"2D 滑桿\",\n \"colorSwatch\": \"color swatch\",\n \"transparent\": \"transparent\"\n}\n"],"names":[],"version":3,"file":"zh-TW.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/color",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.32",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,17 +22,18 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/i18n": "^3.
|
|
26
|
-
"@react-aria/interactions": "^3.21.
|
|
27
|
-
"@react-aria/
|
|
28
|
-
"@react-aria/
|
|
29
|
-
"@react-aria/
|
|
30
|
-
"@react-aria/
|
|
31
|
-
"@react-aria/
|
|
32
|
-
"@react-
|
|
33
|
-
"@react-stately/
|
|
34
|
-
"@react-
|
|
35
|
-
"@react-types/
|
|
25
|
+
"@react-aria/i18n": "^3.11.0",
|
|
26
|
+
"@react-aria/interactions": "^3.21.2",
|
|
27
|
+
"@react-aria/numberfield": "^3.11.2",
|
|
28
|
+
"@react-aria/slider": "^3.7.7",
|
|
29
|
+
"@react-aria/spinbutton": "^3.6.4",
|
|
30
|
+
"@react-aria/textfield": "^3.14.4",
|
|
31
|
+
"@react-aria/utils": "^3.24.0",
|
|
32
|
+
"@react-aria/visually-hidden": "^3.8.11",
|
|
33
|
+
"@react-stately/color": "^3.6.0",
|
|
34
|
+
"@react-stately/form": "^3.0.2",
|
|
35
|
+
"@react-types/color": "3.0.0-beta.24",
|
|
36
|
+
"@react-types/shared": "^3.23.0",
|
|
36
37
|
"@swc/helpers": "^0.5.0"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
@@ -42,5 +43,5 @@
|
|
|
42
43
|
"publishConfig": {
|
|
43
44
|
"access": "public"
|
|
44
45
|
},
|
|
45
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
|
|
46
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -13,8 +13,12 @@ export {useColorArea} from './useColorArea';
|
|
|
13
13
|
export {useColorSlider} from './useColorSlider';
|
|
14
14
|
export {useColorWheel} from './useColorWheel';
|
|
15
15
|
export {useColorField} from './useColorField';
|
|
16
|
+
export {useColorSwatch} from './useColorSwatch';
|
|
17
|
+
export {useColorChannelField} from './useColorChannelField';
|
|
16
18
|
export type {AriaColorAreaOptions, ColorAreaAria} from './useColorArea';
|
|
17
19
|
export type {AriaColorSliderOptions, ColorSliderAria} from './useColorSlider';
|
|
18
20
|
export type {AriaColorWheelOptions, ColorWheelAria} from './useColorWheel';
|
|
19
21
|
export type {AriaColorFieldProps} from '@react-types/color';
|
|
20
22
|
export type {ColorFieldAria} from './useColorField';
|
|
23
|
+
export type {AriaColorSwatchProps, ColorSwatchAria} from './useColorSwatch';
|
|
24
|
+
export type {AriaColorChannelFieldProps, ColorChannelFieldAria} from './useColorChannelField';
|
package/src/useColorArea.ts
CHANGED
|
@@ -25,8 +25,6 @@ import {useVisuallyHidden} from '@react-aria/visually-hidden';
|
|
|
25
25
|
export interface ColorAreaAria {
|
|
26
26
|
/** Props for the color area container element. */
|
|
27
27
|
colorAreaProps: DOMAttributes,
|
|
28
|
-
/** Props for the color area gradient foreground element. */
|
|
29
|
-
gradientProps: DOMAttributes,
|
|
30
28
|
/** Props for the thumb element. */
|
|
31
29
|
thumbProps: DOMAttributes,
|
|
32
30
|
/** Props for the visually hidden horizontal range input element. */
|
|
@@ -79,6 +77,7 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
|
|
|
79
77
|
});
|
|
80
78
|
|
|
81
79
|
let [valueChangedViaKeyboard, setValueChangedViaKeyboard] = useState(false);
|
|
80
|
+
let [valueChangedViaInputChangeEvent, setValueChangedViaInputChangeEvent] = useState(false);
|
|
82
81
|
let {xChannel, yChannel, zChannel} = state.channels;
|
|
83
82
|
let xChannelStep = state.xChannelStep;
|
|
84
83
|
let yChannelStep = state.yChannelStep;
|
|
@@ -183,6 +182,7 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
|
|
|
183
182
|
onFocusWithinChange: (focusWithin:boolean) => {
|
|
184
183
|
if (!focusWithin) {
|
|
185
184
|
setValueChangedViaKeyboard(false);
|
|
185
|
+
setValueChangedViaInputChangeEvent(false);
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
});
|
|
@@ -336,19 +336,32 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
|
|
|
336
336
|
}
|
|
337
337
|
});
|
|
338
338
|
|
|
339
|
+
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
340
|
+
const {target} = e;
|
|
341
|
+
setValueChangedViaInputChangeEvent(true);
|
|
342
|
+
if (target === inputXRef.current) {
|
|
343
|
+
state.setXValue(parseFloat(target.value));
|
|
344
|
+
} else if (target === inputYRef.current) {
|
|
345
|
+
state.setYValue(parseFloat(target.value));
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
339
349
|
let isMobile = isIOS() || isAndroid();
|
|
340
350
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
351
|
+
let value = state.getDisplayColor();
|
|
352
|
+
const getAriaValueTextForChannel = useCallback((channel:ColorChannel) => {
|
|
353
|
+
const isAfterInput = valueChangedViaInputChangeEvent || valueChangedViaKeyboard;
|
|
354
|
+
return `${
|
|
355
|
+
isAfterInput ?
|
|
356
|
+
stringFormatter.format('colorNameAndValue', {name: value.getChannelName(channel, locale), value: value.formatChannelValue(channel, locale)})
|
|
345
357
|
:
|
|
346
358
|
[
|
|
347
|
-
stringFormatter.format('colorNameAndValue', {name:
|
|
348
|
-
stringFormatter.format('colorNameAndValue', {name:
|
|
359
|
+
stringFormatter.format('colorNameAndValue', {name: value.getChannelName(channel, locale), value: value.formatChannelValue(channel, locale)}),
|
|
360
|
+
stringFormatter.format('colorNameAndValue', {name: value.getChannelName(channel === yChannel ? xChannel : yChannel, locale), value: value.formatChannelValue(channel === yChannel ? xChannel : yChannel, locale)}),
|
|
361
|
+
stringFormatter.format('colorNameAndValue', {name: value.getChannelName(zChannel, locale), value: value.formatChannelValue(zChannel, locale)})
|
|
349
362
|
].join(', ')
|
|
350
|
-
)
|
|
351
|
-
}
|
|
363
|
+
}, ${value.getColorName(locale)}`;
|
|
364
|
+
}, [locale, value, stringFormatter, valueChangedViaInputChangeEvent, valueChangedViaKeyboard, xChannel, yChannel, zChannel]);
|
|
352
365
|
|
|
353
366
|
let colorPickerLabel = stringFormatter.format('colorPicker');
|
|
354
367
|
|
|
@@ -381,14 +394,13 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
|
|
|
381
394
|
|
|
382
395
|
let {
|
|
383
396
|
colorAreaStyleProps,
|
|
384
|
-
gradientStyleProps,
|
|
385
397
|
thumbStyleProps
|
|
386
398
|
} = useColorAreaGradient({
|
|
387
399
|
direction,
|
|
388
400
|
state,
|
|
389
401
|
xChannel,
|
|
390
|
-
|
|
391
|
-
|
|
402
|
+
yChannel,
|
|
403
|
+
zChannel
|
|
392
404
|
});
|
|
393
405
|
|
|
394
406
|
return {
|
|
@@ -398,10 +410,6 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
|
|
|
398
410
|
...colorAreaStyleProps,
|
|
399
411
|
role: 'group'
|
|
400
412
|
},
|
|
401
|
-
gradientProps: {
|
|
402
|
-
...gradientStyleProps,
|
|
403
|
-
role: 'presentation'
|
|
404
|
-
},
|
|
405
413
|
thumbProps: {
|
|
406
414
|
...thumbInteractions,
|
|
407
415
|
...thumbStyleProps,
|
|
@@ -417,6 +425,9 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
|
|
|
417
425
|
step: xChannelStep,
|
|
418
426
|
'aria-roledescription': ariaRoleDescription,
|
|
419
427
|
'aria-valuetext': getAriaValueTextForChannel(xChannel),
|
|
428
|
+
'aria-orientation': 'horizontal',
|
|
429
|
+
'aria-describedby': props['aria-describedby'],
|
|
430
|
+
'aria-details': props['aria-details'],
|
|
420
431
|
disabled: isDisabled,
|
|
421
432
|
value: state.value.getChannelValue(xChannel),
|
|
422
433
|
name: xName,
|
|
@@ -427,9 +438,7 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
|
|
|
427
438
|
but remove aria-hidden to reveal the input for each channel when the value has changed with the keyboard.
|
|
428
439
|
*/
|
|
429
440
|
'aria-hidden': (isMobile || !focusedInput || focusedInput === 'x' || valueChangedViaKeyboard ? undefined : 'true'),
|
|
430
|
-
onChange
|
|
431
|
-
state.setXValue(parseFloat(e.target.value));
|
|
432
|
-
}
|
|
441
|
+
onChange
|
|
433
442
|
},
|
|
434
443
|
yInputProps: {
|
|
435
444
|
...yInputLabellingProps,
|
|
@@ -442,6 +451,8 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
|
|
|
442
451
|
'aria-roledescription': ariaRoleDescription,
|
|
443
452
|
'aria-valuetext': getAriaValueTextForChannel(yChannel),
|
|
444
453
|
'aria-orientation': 'vertical',
|
|
454
|
+
'aria-describedby': props['aria-describedby'],
|
|
455
|
+
'aria-details': props['aria-details'],
|
|
445
456
|
disabled: isDisabled,
|
|
446
457
|
value: state.value.getChannelValue(yChannel),
|
|
447
458
|
name: yName,
|
|
@@ -452,9 +463,7 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
|
|
|
452
463
|
but remove aria-hidden to reveal the input for each channel when the value has changed with the keyboard.
|
|
453
464
|
*/
|
|
454
465
|
'aria-hidden': (isMobile || focusedInput === 'y' || valueChangedViaKeyboard ? undefined : 'true'),
|
|
455
|
-
onChange
|
|
456
|
-
state.setYValue(parseFloat(e.target.value));
|
|
457
|
-
}
|
|
466
|
+
onChange
|
|
458
467
|
}
|
|
459
468
|
};
|
|
460
469
|
}
|
|
@@ -10,205 +10,89 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import {Color} from '@react-types/color';
|
|
13
14
|
import {CSSProperties, useMemo} from 'react';
|
|
15
|
+
import {parseColor} from '@react-stately/color';
|
|
14
16
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
let result = {
|
|
18
|
-
colorAreaStyles: {
|
|
19
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,0),rgb(${zValue},255,0))`
|
|
20
|
-
},
|
|
21
|
-
gradientStyles: {
|
|
22
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(${zValue},0,255),rgb(${zValue},255,255))`,
|
|
23
|
-
'WebkitMaskImage': maskImage,
|
|
24
|
-
maskImage
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
return result;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const generateRGB_G = (orientation, dir: boolean, zValue: number) => {
|
|
31
|
-
let maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
32
|
-
let result = {
|
|
33
|
-
colorAreaStyles: {
|
|
34
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},0),rgb(255,${zValue},0))`
|
|
35
|
-
},
|
|
36
|
-
gradientStyles: {
|
|
37
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,${zValue},255),rgb(255,${zValue},255))`,
|
|
38
|
-
'WebkitMaskImage': maskImage,
|
|
39
|
-
maskImage
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
return result;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const generateRGB_B = (orientation, dir: boolean, zValue: number) => {
|
|
46
|
-
let maskImage = `linear-gradient(to ${orientation[Number(!dir)]}, transparent, #000)`;
|
|
47
|
-
let result = {
|
|
48
|
-
colorAreaStyles: {
|
|
49
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,0,${zValue}),rgb(255,0,${zValue}))`
|
|
50
|
-
},
|
|
51
|
-
gradientStyles: {
|
|
52
|
-
backgroundImage: `linear-gradient(to ${orientation[Number(dir)]},rgb(0,255,${zValue}),rgb(255,255,${zValue}))`,
|
|
53
|
-
'WebkitMaskImage': maskImage,
|
|
54
|
-
maskImage
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
return result;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const generateHSL_H = (orientation, dir: boolean, zValue: number) => {
|
|
62
|
-
let result = {
|
|
63
|
-
colorAreaStyles: {},
|
|
64
|
-
gradientStyles: {
|
|
65
|
-
background: [
|
|
66
|
-
`linear-gradient(to ${orientation[Number(dir)]}, hsla(0,0%,0%,1) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,1) 100%)`,
|
|
67
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,50%),hsla(0,0%,50%,0))`,
|
|
68
|
-
`hsl(${zValue}, 100%, 50%)`
|
|
69
|
-
].join(',')
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
return result;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const generateHSL_S = (orientation, dir: boolean, alphaValue: number) => {
|
|
76
|
-
let result = {
|
|
77
|
-
colorAreaStyles: {},
|
|
78
|
-
gradientStyles: {
|
|
79
|
-
background: [
|
|
80
|
-
`linear-gradient(to ${orientation[Number(!dir)]}, hsla(0,0%,0%,${alphaValue}) 0%, hsla(0,0%,0%,0) 50%, hsla(0,0%,100%,0) 50%, hsla(0,0%,100%,${alphaValue}) 100%)`,
|
|
81
|
-
`linear-gradient(to ${orientation[Number(dir)]},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
|
|
82
|
-
'hsl(0, 0%, 50%)'
|
|
83
|
-
].join(',')
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
return result;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const generateHSL_L = (orientation, dir: boolean, zValue: number) => {
|
|
90
|
-
let result = {
|
|
91
|
-
colorAreaStyles: {},
|
|
92
|
-
gradientStyles: {
|
|
93
|
-
backgroundImage: [
|
|
94
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,${zValue}%),hsla(0,0%,${zValue}%,0))`,
|
|
95
|
-
`linear-gradient(to ${orientation[Number(dir)]},hsl(0,100%,${zValue}%),hsl(60,100%,${zValue}%),hsl(120,100%,${zValue}%),hsl(180,100%,${zValue}%),hsl(240,100%,${zValue}%),hsl(300,100%,${zValue}%),hsl(360,100%,${zValue}%))`
|
|
96
|
-
].join(',')
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const generateHSB_H = (orientation, dir: boolean, zValue: number) => {
|
|
104
|
-
let result = {
|
|
105
|
-
colorAreaStyles: {},
|
|
106
|
-
gradientStyles: {
|
|
107
|
-
background: [
|
|
108
|
-
`linear-gradient(to ${orientation[Number(dir)]},hsl(0,0%,0%),hsla(0,0%,0%,0))`,
|
|
109
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,100%),hsla(0,0%,100%,0))`,
|
|
110
|
-
`hsl(${zValue}, 100%, 50%)`
|
|
111
|
-
].join(',')
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
return result;
|
|
115
|
-
};
|
|
17
|
+
const hue = (color: Color) => [0, 60, 120, 180, 240, 300, 360].map(hue => color.withChannelValue('hue', hue).toString('css')).join(', ');
|
|
18
|
+
const saturation = (color: Color) => `${color.withChannelValue('saturation', 0)}, transparent`;
|
|
116
19
|
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
background: [
|
|
122
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,0%,${alphaValue}),hsla(0,0%,0%,0))`,
|
|
123
|
-
`linear-gradient(to ${orientation[Number(dir)]},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
|
|
124
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsl(0,0%,0%),hsl(0,0%,100%))`
|
|
125
|
-
].join(',')
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
return result;
|
|
20
|
+
const hslChannels = {
|
|
21
|
+
hue,
|
|
22
|
+
saturation,
|
|
23
|
+
lightness: () => 'black, transparent, white'
|
|
129
24
|
};
|
|
130
25
|
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
background: [
|
|
136
|
-
`linear-gradient(to ${orientation[Number(!dir)]},hsla(0,0%,100%,${alphaValue}),hsla(0,0%,100%,0))`,
|
|
137
|
-
`linear-gradient(to ${orientation[Number(dir)]},hsla(0,100%,50%,${alphaValue}),hsla(60,100%,50%,${alphaValue}),hsla(120,100%,50%,${alphaValue}),hsla(180,100%,50%,${alphaValue}),hsla(240,100%,50%,${alphaValue}),hsla(300,100%,50%,${alphaValue}),hsla(359,100%,50%,${alphaValue}))`,
|
|
138
|
-
'#000'
|
|
139
|
-
].join(',')
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
return result;
|
|
26
|
+
const hsbChannels = {
|
|
27
|
+
hue,
|
|
28
|
+
saturation,
|
|
29
|
+
brightness: () => 'black, transparent'
|
|
143
30
|
};
|
|
144
31
|
|
|
145
|
-
|
|
146
32
|
interface Gradients {
|
|
147
33
|
colorAreaStyleProps: {
|
|
148
34
|
style: CSSProperties
|
|
149
35
|
},
|
|
150
|
-
gradientStyleProps: {
|
|
151
|
-
style: CSSProperties
|
|
152
|
-
},
|
|
153
36
|
thumbStyleProps: {
|
|
154
37
|
style: CSSProperties
|
|
155
38
|
}
|
|
156
39
|
}
|
|
157
40
|
|
|
158
|
-
export function useColorAreaGradient({direction, state, zChannel, xChannel,
|
|
41
|
+
export function useColorAreaGradient({direction, state, zChannel, xChannel, yChannel}): Gradients {
|
|
159
42
|
let returnVal = useMemo<Gradients>(() => {
|
|
160
|
-
let
|
|
161
|
-
let
|
|
162
|
-
let background = {colorAreaStyles: {}, gradientStyles: {}};
|
|
43
|
+
let end = direction === 'rtl' ? 'left' : 'right';
|
|
44
|
+
let colorAreaStyles = {};
|
|
163
45
|
let zValue = state.value.getChannelValue(zChannel);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
case 'saturation': {
|
|
194
|
-
dir = xChannel === 'hue';
|
|
195
|
-
if (isHSL) {
|
|
196
|
-
background = generateHSL_S(orientation, dir, alphaValue);
|
|
197
|
-
} else {
|
|
198
|
-
background = generateHSB_S(orientation, dir, alphaValue);
|
|
199
|
-
}
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
case 'brightness': {
|
|
203
|
-
dir = xChannel === 'hue';
|
|
204
|
-
background = generateHSB_B(orientation, dir, alphaValue);
|
|
205
|
-
break;
|
|
46
|
+
|
|
47
|
+
switch (state.value.getColorSpace()) {
|
|
48
|
+
case 'rgb': {
|
|
49
|
+
let rgb = parseColor('rgb(0, 0, 0)');
|
|
50
|
+
colorAreaStyles = {
|
|
51
|
+
background: [
|
|
52
|
+
// The screen blend mode multiplies the inverse of each channel, e.g. 1 - (1 - a) * (1 - b).
|
|
53
|
+
// Create a layer for each channel, with the other channels as 0. After blending, this should
|
|
54
|
+
// result in the gradients being combined channel by channel.
|
|
55
|
+
`linear-gradient(to ${end}, ${rgb.withChannelValue(xChannel, 0)}, ${rgb.withChannelValue(xChannel, 255)})`,
|
|
56
|
+
`linear-gradient(to top, ${rgb.withChannelValue(yChannel, 0)}, ${rgb.withChannelValue(yChannel, 255)})`,
|
|
57
|
+
rgb.withChannelValue(zChannel, zValue)
|
|
58
|
+
].join(','),
|
|
59
|
+
backgroundBlendMode: 'screen'
|
|
60
|
+
};
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'hsl': {
|
|
64
|
+
let channels = state.value.getColorChannels();
|
|
65
|
+
let value = parseColor('hsl(0, 100%, 50%)').withChannelValue(zChannel, zValue);
|
|
66
|
+
|
|
67
|
+
let bg = channels
|
|
68
|
+
.filter(c => c !== zChannel)
|
|
69
|
+
.map(c => `linear-gradient(to ${c === xChannel ? end : 'top'}, ${hslChannels[c](value)})`)
|
|
70
|
+
.reverse();
|
|
71
|
+
if (zChannel === 'hue') {
|
|
72
|
+
bg.push(value.toString('css'));
|
|
206
73
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
background
|
|
210
|
-
|
|
74
|
+
|
|
75
|
+
colorAreaStyles = {
|
|
76
|
+
background: bg.join(', ')
|
|
77
|
+
};
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case 'hsb': {
|
|
81
|
+
let channels = state.value.getColorChannels();
|
|
82
|
+
let value = parseColor('hsb(0, 100%, 100%)').withChannelValue(zChannel, zValue);
|
|
83
|
+
|
|
84
|
+
let bg = channels
|
|
85
|
+
.filter(c => c !== zChannel)
|
|
86
|
+
.map(c => `linear-gradient(to ${c === xChannel ? end : 'top'}, ${hsbChannels[c](value)})`)
|
|
87
|
+
.reverse();
|
|
88
|
+
if (zChannel === 'hue') {
|
|
89
|
+
bg.push(value.toString('css'));
|
|
211
90
|
}
|
|
91
|
+
|
|
92
|
+
colorAreaStyles = {
|
|
93
|
+
background: bg.join(', ')
|
|
94
|
+
};
|
|
95
|
+
break;
|
|
212
96
|
}
|
|
213
97
|
}
|
|
214
98
|
|
|
@@ -226,14 +110,7 @@ export function useColorAreaGradient({direction, state, zChannel, xChannel, isDi
|
|
|
226
110
|
position: 'relative',
|
|
227
111
|
touchAction: 'none',
|
|
228
112
|
...forcedColorAdjustNoneStyle,
|
|
229
|
-
...
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
gradientStyleProps: {
|
|
233
|
-
style: {
|
|
234
|
-
touchAction: 'none',
|
|
235
|
-
...forcedColorAdjustNoneStyle,
|
|
236
|
-
...background.gradientStyles
|
|
113
|
+
...colorAreaStyles
|
|
237
114
|
}
|
|
238
115
|
},
|
|
239
116
|
thumbStyleProps: {
|
|
@@ -241,13 +118,13 @@ export function useColorAreaGradient({direction, state, zChannel, xChannel, isDi
|
|
|
241
118
|
position: 'absolute',
|
|
242
119
|
left: `${x * 100}%`,
|
|
243
120
|
top: `${y * 100}%`,
|
|
244
|
-
transform: 'translate(
|
|
121
|
+
transform: 'translate(-50%, -50%)',
|
|
245
122
|
touchAction: 'none',
|
|
246
123
|
...forcedColorAdjustNoneStyle
|
|
247
124
|
}
|
|
248
125
|
}
|
|
249
126
|
};
|
|
250
|
-
}, [direction, state, zChannel, xChannel,
|
|
127
|
+
}, [direction, state, zChannel, xChannel, yChannel]);
|
|
251
128
|
|
|
252
129
|
return returnVal;
|
|
253
130
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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} from '@react-types/shared';
|
|
14
|
+
import {ColorChannelFieldProps, ColorChannelFieldState} from '@react-stately/color';
|
|
15
|
+
import {NumberFieldAria, useNumberField} from '@react-aria/numberfield';
|
|
16
|
+
import {RefObject} from 'react';
|
|
17
|
+
import {useLocale} from '@react-aria/i18n';
|
|
18
|
+
|
|
19
|
+
export interface AriaColorChannelFieldProps extends ColorChannelFieldProps, AriaLabelingProps {}
|
|
20
|
+
export interface ColorChannelFieldAria extends NumberFieldAria {}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Provides the behavior and accessibility implementation for a color channel field, allowing users to edit the
|
|
24
|
+
* value of an individual color channel.
|
|
25
|
+
*/
|
|
26
|
+
export function useColorChannelField(props: AriaColorChannelFieldProps, state: ColorChannelFieldState, inputRef: RefObject<HTMLInputElement>): ColorChannelFieldAria {
|
|
27
|
+
let {locale} = useLocale();
|
|
28
|
+
return useNumberField({
|
|
29
|
+
...props,
|
|
30
|
+
value: undefined,
|
|
31
|
+
defaultValue: undefined,
|
|
32
|
+
onChange: undefined,
|
|
33
|
+
validate: undefined,
|
|
34
|
+
// Provide a default aria-label if no other label is provided.
|
|
35
|
+
'aria-label': props['aria-label'] || (props.label || props['aria-labelledby'] ? undefined : state.colorValue.getChannelName(props.channel, locale))
|
|
36
|
+
}, state, inputRef);
|
|
37
|
+
}
|
package/src/useColorField.ts
CHANGED
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|
import {AriaColorFieldProps} from '@react-types/color';
|
|
14
14
|
import {ColorFieldState} from '@react-stately/color';
|
|
15
|
+
import {DOMAttributes, ValidationResult} from '@react-types/shared';
|
|
15
16
|
import {
|
|
16
|
-
|
|
17
|
+
InputHTMLAttributes,
|
|
17
18
|
LabelHTMLAttributes,
|
|
18
19
|
RefObject,
|
|
19
20
|
useCallback,
|
|
@@ -24,13 +25,16 @@ import {privateValidationStateProp} from '@react-stately/form';
|
|
|
24
25
|
import {useFocusWithin, useScrollWheel} from '@react-aria/interactions';
|
|
25
26
|
import {useFormattedTextField} from '@react-aria/textfield';
|
|
26
27
|
import {useSpinButton} from '@react-aria/spinbutton';
|
|
27
|
-
import {ValidationResult} from '@react-types/shared';
|
|
28
28
|
|
|
29
29
|
export interface ColorFieldAria extends ValidationResult {
|
|
30
30
|
/** Props for the label element. */
|
|
31
31
|
labelProps: LabelHTMLAttributes<HTMLLabelElement>,
|
|
32
32
|
/** Props for the input element. */
|
|
33
|
-
inputProps:
|
|
33
|
+
inputProps: InputHTMLAttributes<HTMLInputElement>,
|
|
34
|
+
/** Props for the text field's description element, if any. */
|
|
35
|
+
descriptionProps: DOMAttributes,
|
|
36
|
+
/** Props for the text field's error message element, if any. */
|
|
37
|
+
errorMessageProps: DOMAttributes
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
/**
|
|
@@ -100,17 +104,17 @@ export function useColorField(
|
|
|
100
104
|
}
|
|
101
105
|
};
|
|
102
106
|
|
|
103
|
-
let {inputProps, ...otherProps} = useFormattedTextField(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
let {inputProps, ...otherProps} = useFormattedTextField({
|
|
108
|
+
...props,
|
|
109
|
+
id: inputId,
|
|
110
|
+
value: inputValue,
|
|
111
|
+
defaultValue: undefined,
|
|
112
|
+
validate: undefined,
|
|
113
|
+
[privateValidationStateProp]: state,
|
|
114
|
+
type: 'text',
|
|
115
|
+
autoComplete: 'off',
|
|
116
|
+
onChange
|
|
117
|
+
}, state, ref);
|
|
114
118
|
|
|
115
119
|
inputProps = mergeProps(inputProps, spinButtonProps, focusWithinProps, {
|
|
116
120
|
role: 'textbox',
|