@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,93 @@
|
|
|
1
|
+
import {useState as $f8mV7$useState, useCallback as $f8mV7$useCallback} from "react";
|
|
2
|
+
import {useId as $f8mV7$useId, mergeProps as $f8mV7$mergeProps} from "@react-aria/utils";
|
|
3
|
+
import {privateValidationStateProp as $f8mV7$privateValidationStateProp} from "@react-stately/form";
|
|
4
|
+
import {useFocusWithin as $f8mV7$useFocusWithin, useScrollWheel as $f8mV7$useScrollWheel} from "@react-aria/interactions";
|
|
5
|
+
import {useFormattedTextField as $f8mV7$useFormattedTextField} from "@react-aria/textfield";
|
|
6
|
+
import {useSpinButton as $f8mV7$useSpinButton} from "@react-aria/spinbutton";
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
10
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
12
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
15
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
16
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
17
|
+
* governing permissions and limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function $f6896b05b2ecad12$export$77e32ca575a28fdf(props, state, ref) {
|
|
25
|
+
let { isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, isWheelDisabled: isWheelDisabled, validationBehavior: validationBehavior = "aria" } = props;
|
|
26
|
+
let { colorValue: colorValue, inputValue: inputValue, increment: increment, decrement: decrement, incrementToMax: incrementToMax, decrementToMin: decrementToMin, commit: commit } = state;
|
|
27
|
+
let inputId = (0, $f8mV7$useId)();
|
|
28
|
+
let { spinButtonProps: spinButtonProps } = (0, $f8mV7$useSpinButton)({
|
|
29
|
+
isDisabled: isDisabled,
|
|
30
|
+
isReadOnly: isReadOnly,
|
|
31
|
+
isRequired: isRequired,
|
|
32
|
+
maxValue: 0xFFFFFF,
|
|
33
|
+
minValue: 0,
|
|
34
|
+
onIncrement: increment,
|
|
35
|
+
onIncrementToMax: incrementToMax,
|
|
36
|
+
onDecrement: decrement,
|
|
37
|
+
onDecrementToMin: decrementToMin,
|
|
38
|
+
value: colorValue ? colorValue.toHexInt() : undefined,
|
|
39
|
+
textValue: colorValue ? colorValue.toString("hex") : undefined
|
|
40
|
+
});
|
|
41
|
+
let [focusWithin, setFocusWithin] = (0, $f8mV7$useState)(false);
|
|
42
|
+
let { focusWithinProps: focusWithinProps } = (0, $f8mV7$useFocusWithin)({
|
|
43
|
+
isDisabled: isDisabled,
|
|
44
|
+
onFocusWithinChange: setFocusWithin
|
|
45
|
+
});
|
|
46
|
+
let onWheel = (0, $f8mV7$useCallback)((e)=>{
|
|
47
|
+
if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) return;
|
|
48
|
+
if (e.deltaY > 0) increment();
|
|
49
|
+
else if (e.deltaY < 0) decrement();
|
|
50
|
+
}, [
|
|
51
|
+
decrement,
|
|
52
|
+
increment
|
|
53
|
+
]);
|
|
54
|
+
// If the input isn't supposed to receive input, disable scrolling.
|
|
55
|
+
let scrollingDisabled = isWheelDisabled || isDisabled || isReadOnly || !focusWithin;
|
|
56
|
+
(0, $f8mV7$useScrollWheel)({
|
|
57
|
+
onScroll: onWheel,
|
|
58
|
+
isDisabled: scrollingDisabled
|
|
59
|
+
}, ref);
|
|
60
|
+
let onChange = (value)=>{
|
|
61
|
+
if (state.validate(value)) state.setInputValue(value);
|
|
62
|
+
};
|
|
63
|
+
let { inputProps: inputProps, ...otherProps } = (0, $f8mV7$useFormattedTextField)({
|
|
64
|
+
...props,
|
|
65
|
+
id: inputId,
|
|
66
|
+
value: inputValue,
|
|
67
|
+
defaultValue: undefined,
|
|
68
|
+
validate: undefined,
|
|
69
|
+
[(0, $f8mV7$privateValidationStateProp)]: state,
|
|
70
|
+
type: "text",
|
|
71
|
+
autoComplete: "off",
|
|
72
|
+
onChange: onChange
|
|
73
|
+
}, state, ref);
|
|
74
|
+
inputProps = (0, $f8mV7$mergeProps)(inputProps, spinButtonProps, focusWithinProps, {
|
|
75
|
+
role: "textbox",
|
|
76
|
+
"aria-valuemax": null,
|
|
77
|
+
"aria-valuemin": null,
|
|
78
|
+
"aria-valuenow": null,
|
|
79
|
+
"aria-valuetext": null,
|
|
80
|
+
autoCorrect: "off",
|
|
81
|
+
spellCheck: "false",
|
|
82
|
+
onBlur: commit
|
|
83
|
+
});
|
|
84
|
+
if (validationBehavior === "native") inputProps["aria-required"] = undefined;
|
|
85
|
+
return {
|
|
86
|
+
inputProps: inputProps,
|
|
87
|
+
...otherProps
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
export {$f6896b05b2ecad12$export$77e32ca575a28fdf as useColorField};
|
|
93
|
+
//# sourceMappingURL=useColorField.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAiCM,SAAS,0CACd,KAA0B,EAC1B,KAAsB,EACtB,GAAgC;IAEhC,IAAI,cACF,UAAU,cACV,UAAU,cACV,UAAU,mBACV,eAAe,sBACf,qBAAqB,QACtB,GAAG;IAEJ,IAAI,cACF,UAAU,cACV,UAAU,aACV,SAAS,aACT,SAAS,kBACT,cAAc,kBACd,cAAc,UACd,MAAM,EACP,GAAG;IAEJ,IAAI,UAAU,CAAA,GAAA,YAAI;IAClB,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,oBAAY,EAClC;oBACE;oBACA;oBACA;QACA,UAAU;QACV,UAAU;QACV,aAAa;QACb,kBAAkB;QAClB,aAAa;QACb,kBAAkB;QAClB,OAAO,aAAa,WAAW,QAAQ,KAAK;QAC5C,WAAW,aAAa,WAAW,QAAQ,CAAC,SAAS;IACvD;IAGF,IAAI,CAAC,aAAa,eAAe,GAAG,CAAA,GAAA,eAAO,EAAE;IAC7C,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;oBAAC;QAAY,qBAAqB;IAAc;IAExF,IAAI,UAAU,CAAA,GAAA,kBAAU,EAAE,CAAC;QACzB,IAAI,KAAK,GAAG,CAAC,EAAE,MAAM,KAAK,KAAK,GAAG,CAAC,EAAE,MAAM,GACzC;QAEF,IAAI,EAAE,MAAM,GAAG,GACb;aACK,IAAI,EAAE,MAAM,GAAG,GACpB;IAEJ,GAAG;QAAC;QAAW;KAAU;IACzB,mEAAmE;IACnE,IAAI,oBAAoB,mBAAmB,cAAc,cAAc,CAAC;IACxE,CAAA,GAAA,qBAAa,EAAE;QAAC,UAAU;QAAS,YAAY;IAAiB,GAAG;IAEnE,IAAI,WAAW,CAAA;QACb,IAAI,MAAM,QAAQ,CAAC,QACjB,MAAM,aAAa,CAAC;IAExB;IAEA,IAAI,cAAC,UAAU,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,4BAAoB,EAAE;QACtD,GAAG,KAAK;QACR,IAAI;QACJ,OAAO;QACP,cAAc;QACd,UAAU;QACV,CAAC,CAAA,GAAA,iCAAyB,EAAE,EAAE;QAC9B,MAAM;QACN,cAAc;kBACd;IACF,GAAG,OAAO;IAEV,aAAa,CAAA,GAAA,iBAAS,EAAE,YAAY,iBAAiB,kBAAkB;QACrE,MAAM;QACN,iBAAiB;QACjB,iBAAiB;QACjB,iBAAiB;QACjB,kBAAkB;QAClB,aAAa;QACb,YAAY;QACZ,QAAQ;IACV;IAEA,IAAI,uBAAuB,UACzB,UAAU,CAAC,gBAAgB,GAAG;IAGhC,OAAO;oBACL;QACA,GAAG,UAAU;IACf;AACF","sources":["packages/@react-aria/color/src/useColorField.ts"],"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\nimport {AriaColorFieldProps} from '@react-types/color';\nimport {ColorFieldState} from '@react-stately/color';\nimport {DOMAttributes, ValidationResult} from '@react-types/shared';\nimport {\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useState\n} from 'react';\nimport {mergeProps, useId} from '@react-aria/utils';\nimport {privateValidationStateProp} from '@react-stately/form';\nimport {useFocusWithin, useScrollWheel} from '@react-aria/interactions';\nimport {useFormattedTextField} from '@react-aria/textfield';\nimport {useSpinButton} from '@react-aria/spinbutton';\n\nexport interface ColorFieldAria extends ValidationResult {\n /** Props for the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>,\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Props for the text field's description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the text field's error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a color field component.\n * Color fields allow users to enter and adjust a hex color value.\n */\nexport function useColorField(\n props: AriaColorFieldProps,\n state: ColorFieldState,\n ref: RefObject<HTMLInputElement>\n): ColorFieldAria {\n let {\n isDisabled,\n isReadOnly,\n isRequired,\n isWheelDisabled,\n validationBehavior = 'aria'\n } = props;\n\n let {\n colorValue,\n inputValue,\n increment,\n decrement,\n incrementToMax,\n decrementToMin,\n commit\n } = state;\n\n let inputId = useId();\n let {spinButtonProps} = useSpinButton(\n {\n isDisabled,\n isReadOnly,\n isRequired,\n maxValue: 0xFFFFFF,\n minValue: 0,\n onIncrement: increment,\n onIncrementToMax: incrementToMax,\n onDecrement: decrement,\n onDecrementToMin: decrementToMin,\n value: colorValue ? colorValue.toHexInt() : undefined,\n textValue: colorValue ? colorValue.toString('hex') : undefined\n }\n );\n\n let [focusWithin, setFocusWithin] = useState(false);\n let {focusWithinProps} = useFocusWithin({isDisabled, onFocusWithinChange: setFocusWithin});\n\n let onWheel = useCallback((e) => {\n if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {\n return;\n }\n if (e.deltaY > 0) {\n increment();\n } else if (e.deltaY < 0) {\n decrement();\n }\n }, [decrement, increment]);\n // If the input isn't supposed to receive input, disable scrolling.\n let scrollingDisabled = isWheelDisabled || isDisabled || isReadOnly || !focusWithin;\n useScrollWheel({onScroll: onWheel, isDisabled: scrollingDisabled}, ref);\n\n let onChange = value => {\n if (state.validate(value)) {\n state.setInputValue(value);\n }\n };\n\n let {inputProps, ...otherProps} = useFormattedTextField({\n ...props,\n id: inputId,\n value: inputValue,\n defaultValue: undefined,\n validate: undefined,\n [privateValidationStateProp]: state,\n type: 'text',\n autoComplete: 'off',\n onChange\n }, state, ref);\n\n inputProps = mergeProps(inputProps, spinButtonProps, focusWithinProps, {\n role: 'textbox',\n 'aria-valuemax': null,\n 'aria-valuemin': null,\n 'aria-valuenow': null,\n 'aria-valuetext': null,\n autoCorrect: 'off',\n spellCheck: 'false',\n onBlur: commit\n });\n\n if (validationBehavior === 'native') {\n inputProps['aria-required'] = undefined;\n }\n\n return {\n inputProps,\n ...otherProps\n };\n}\n"],"names":[],"version":3,"file":"useColorField.module.js.map"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var $edxco$reactariautils = require("@react-aria/utils");
|
|
2
|
+
var $edxco$reactariai18n = require("@react-aria/i18n");
|
|
3
|
+
var $edxco$reactariaslider = require("@react-aria/slider");
|
|
4
|
+
var $edxco$reactariavisuallyhidden = require("@react-aria/visually-hidden");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function $parcel$export(e, n, v, s) {
|
|
8
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
$parcel$export(module.exports, "useColorSlider", () => $afbb9647440a7f5b$export$106b7a4e66508f66);
|
|
12
|
+
/*
|
|
13
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
14
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
+
* governing permissions and limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function $afbb9647440a7f5b$export$106b7a4e66508f66(props, state) {
|
|
27
|
+
let { trackRef: trackRef, inputRef: inputRef, orientation: orientation, channel: channel, "aria-label": ariaLabel, name: name } = props;
|
|
28
|
+
let { locale: locale, direction: direction } = (0, $edxco$reactariai18n.useLocale)();
|
|
29
|
+
// Provide a default aria-label if there is no other label provided.
|
|
30
|
+
if (!props.label && !ariaLabel && !props["aria-labelledby"]) ariaLabel = state.value.getChannelName(channel, locale);
|
|
31
|
+
// @ts-ignore - ignore unused incompatible props
|
|
32
|
+
let { groupProps: groupProps, trackProps: trackProps, labelProps: labelProps, outputProps: outputProps } = (0, $edxco$reactariaslider.useSlider)({
|
|
33
|
+
...props,
|
|
34
|
+
"aria-label": ariaLabel
|
|
35
|
+
}, state, trackRef);
|
|
36
|
+
let { inputProps: inputProps, thumbProps: thumbProps } = (0, $edxco$reactariaslider.useSliderThumb)({
|
|
37
|
+
index: 0,
|
|
38
|
+
orientation: orientation,
|
|
39
|
+
isDisabled: props.isDisabled,
|
|
40
|
+
name: name,
|
|
41
|
+
trackRef: trackRef,
|
|
42
|
+
inputRef: inputRef
|
|
43
|
+
}, state);
|
|
44
|
+
let value = state.getDisplayColor();
|
|
45
|
+
let generateBackground = ()=>{
|
|
46
|
+
let to;
|
|
47
|
+
if (orientation === "vertical") to = "top";
|
|
48
|
+
else if (direction === "ltr") to = "right";
|
|
49
|
+
else to = "left";
|
|
50
|
+
switch(channel){
|
|
51
|
+
case "hue":
|
|
52
|
+
{
|
|
53
|
+
let stops = [
|
|
54
|
+
0,
|
|
55
|
+
60,
|
|
56
|
+
120,
|
|
57
|
+
180,
|
|
58
|
+
240,
|
|
59
|
+
300,
|
|
60
|
+
360
|
|
61
|
+
].map((hue)=>value.withChannelValue("hue", hue).toString("css")).join(", ");
|
|
62
|
+
return `linear-gradient(to ${to}, ${stops})`;
|
|
63
|
+
}
|
|
64
|
+
case "lightness":
|
|
65
|
+
{
|
|
66
|
+
// We have to add an extra color stop in the middle so that the hue shows up at all.
|
|
67
|
+
// Otherwise it will always just be black to white.
|
|
68
|
+
let min = state.getThumbMinValue(0);
|
|
69
|
+
let max = state.getThumbMaxValue(0);
|
|
70
|
+
let start = value.withChannelValue(channel, min).toString("css");
|
|
71
|
+
let middle = value.withChannelValue(channel, (max - min) / 2).toString("css");
|
|
72
|
+
let end = value.withChannelValue(channel, max).toString("css");
|
|
73
|
+
return `linear-gradient(to ${to}, ${start}, ${middle}, ${end})`;
|
|
74
|
+
}
|
|
75
|
+
case "saturation":
|
|
76
|
+
case "brightness":
|
|
77
|
+
case "red":
|
|
78
|
+
case "green":
|
|
79
|
+
case "blue":
|
|
80
|
+
case "alpha":
|
|
81
|
+
{
|
|
82
|
+
let start = value.withChannelValue(channel, state.getThumbMinValue(0)).toString("css");
|
|
83
|
+
let end = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString("css");
|
|
84
|
+
return `linear-gradient(to ${to}, ${start}, ${end})`;
|
|
85
|
+
}
|
|
86
|
+
default:
|
|
87
|
+
throw new Error("Unknown color channel: " + channel);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
let forcedColorAdjustNoneStyle = {
|
|
91
|
+
forcedColorAdjust: "none"
|
|
92
|
+
};
|
|
93
|
+
if (channel === "hue") inputProps["aria-valuetext"] += `, ${value.getHueName(locale)}`;
|
|
94
|
+
else if (channel !== "alpha") inputProps["aria-valuetext"] += `, ${value.getColorName(locale)}`;
|
|
95
|
+
let { visuallyHiddenProps: visuallyHiddenProps } = (0, $edxco$reactariavisuallyhidden.useVisuallyHidden)({
|
|
96
|
+
style: {
|
|
97
|
+
opacity: "0.0001",
|
|
98
|
+
width: "100%",
|
|
99
|
+
height: "100%",
|
|
100
|
+
pointerEvents: "none"
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
trackProps: {
|
|
105
|
+
...(0, $edxco$reactariautils.mergeProps)(groupProps, trackProps),
|
|
106
|
+
style: {
|
|
107
|
+
...trackProps.style,
|
|
108
|
+
...forcedColorAdjustNoneStyle,
|
|
109
|
+
background: generateBackground()
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
inputProps: {
|
|
113
|
+
...inputProps,
|
|
114
|
+
style: {
|
|
115
|
+
...inputProps.style,
|
|
116
|
+
...visuallyHiddenProps.style
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
thumbProps: {
|
|
120
|
+
...thumbProps,
|
|
121
|
+
style: {
|
|
122
|
+
...thumbProps.style,
|
|
123
|
+
...forcedColorAdjustNoneStyle
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
labelProps: labelProps,
|
|
127
|
+
outputProps: outputProps
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
//# sourceMappingURL=useColorSlider.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"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","sources":["packages/@react-aria/color/src/useColorSlider.ts"],"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\nimport {AriaColorSliderProps} from '@react-types/color';\nimport {ColorSliderState} from '@react-stately/color';\nimport {DOMAttributes} from '@react-types/shared';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSlider, useSliderThumb} from '@react-aria/slider';\nimport {useVisuallyHidden} from '@react-aria/visually-hidden';\n\nexport interface AriaColorSliderOptions extends AriaColorSliderProps {\n /** A ref for the track element. */\n trackRef: RefObject<Element>,\n /** A ref for the input element. */\n inputRef: RefObject<HTMLInputElement>\n}\n\nexport interface ColorSliderAria {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n /** Props for the track element. */\n trackProps: DOMAttributes,\n /** Props for the thumb element. */\n thumbProps: DOMAttributes,\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Props for the output element, displaying the value of the color slider. */\n outputProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a color slider component.\n * Color sliders allow users to adjust an individual channel of a color value.\n */\nexport function useColorSlider(props: AriaColorSliderOptions, state: ColorSliderState): ColorSliderAria {\n let {trackRef, inputRef, orientation, channel, 'aria-label': ariaLabel, name} = props;\n\n let {locale, direction} = useLocale();\n\n // Provide a default aria-label if there is no other label provided.\n if (!props.label && !ariaLabel && !props['aria-labelledby']) {\n ariaLabel = state.value.getChannelName(channel, locale);\n }\n\n // @ts-ignore - ignore unused incompatible props\n let {groupProps, trackProps, labelProps, outputProps} = useSlider({...props, 'aria-label': ariaLabel}, state, trackRef);\n let {inputProps, thumbProps} = useSliderThumb({\n index: 0,\n orientation,\n isDisabled: props.isDisabled,\n name,\n trackRef,\n inputRef\n }, state);\n\n let value = state.getDisplayColor();\n let generateBackground = () => {\n let to: string;\n if (orientation === 'vertical') {\n to = 'top';\n } else if (direction === 'ltr') {\n to = 'right';\n } else {\n to = 'left';\n }\n switch (channel) {\n case 'hue': {\n let stops = [0, 60, 120, 180, 240, 300, 360].map(hue => value.withChannelValue('hue', hue).toString('css')).join(', ');\n return `linear-gradient(to ${to}, ${stops})`;\n }\n case 'lightness': {\n // We have to add an extra color stop in the middle so that the hue shows up at all.\n // Otherwise it will always just be black to white.\n let min = state.getThumbMinValue(0);\n let max = state.getThumbMaxValue(0);\n let start = value.withChannelValue(channel, min).toString('css');\n let middle = value.withChannelValue(channel, (max - min) / 2).toString('css');\n let end = value.withChannelValue(channel, max).toString('css');\n return `linear-gradient(to ${to}, ${start}, ${middle}, ${end})`;\n }\n case 'saturation':\n case 'brightness':\n case 'red':\n case 'green':\n case 'blue':\n case 'alpha': {\n let start = value.withChannelValue(channel, state.getThumbMinValue(0)).toString('css');\n let end = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString('css');\n return `linear-gradient(to ${to}, ${start}, ${end})`;\n }\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n };\n\n let forcedColorAdjustNoneStyle = {forcedColorAdjust: 'none'};\n\n if (channel === 'hue') {\n inputProps['aria-valuetext'] += `, ${value.getHueName(locale)}`;\n } else if (channel !== 'alpha') {\n inputProps['aria-valuetext'] += `, ${value.getColorName(locale)}`;\n }\n\n let {visuallyHiddenProps} = useVisuallyHidden({\n style: {\n opacity: '0.0001',\n width: '100%',\n height: '100%',\n pointerEvents: 'none'\n }\n });\n\n return {\n trackProps: {\n ...mergeProps(groupProps, trackProps),\n style: {\n ...trackProps.style,\n ...forcedColorAdjustNoneStyle,\n background: generateBackground()\n }\n },\n inputProps: {\n ...inputProps,\n style: {\n ...inputProps.style,\n ...visuallyHiddenProps.style\n }\n },\n thumbProps: {\n ...thumbProps,\n style: {\n ...thumbProps.style,\n ...forcedColorAdjustNoneStyle\n }\n },\n labelProps,\n outputProps\n };\n}\n"],"names":[],"version":3,"file":"useColorSlider.main.js.map"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {mergeProps as $6WsjB$mergeProps} from "@react-aria/utils";
|
|
2
|
+
import {useLocale as $6WsjB$useLocale} from "@react-aria/i18n";
|
|
3
|
+
import {useSlider as $6WsjB$useSlider, useSliderThumb as $6WsjB$useSliderThumb} from "@react-aria/slider";
|
|
4
|
+
import {useVisuallyHidden as $6WsjB$useVisuallyHidden} from "@react-aria/visually-hidden";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
* governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function $40af666d6c251e36$export$106b7a4e66508f66(props, state) {
|
|
21
|
+
let { trackRef: trackRef, inputRef: inputRef, orientation: orientation, channel: channel, "aria-label": ariaLabel, name: name } = props;
|
|
22
|
+
let { locale: locale, direction: direction } = (0, $6WsjB$useLocale)();
|
|
23
|
+
// Provide a default aria-label if there is no other label provided.
|
|
24
|
+
if (!props.label && !ariaLabel && !props["aria-labelledby"]) ariaLabel = state.value.getChannelName(channel, locale);
|
|
25
|
+
// @ts-ignore - ignore unused incompatible props
|
|
26
|
+
let { groupProps: groupProps, trackProps: trackProps, labelProps: labelProps, outputProps: outputProps } = (0, $6WsjB$useSlider)({
|
|
27
|
+
...props,
|
|
28
|
+
"aria-label": ariaLabel
|
|
29
|
+
}, state, trackRef);
|
|
30
|
+
let { inputProps: inputProps, thumbProps: thumbProps } = (0, $6WsjB$useSliderThumb)({
|
|
31
|
+
index: 0,
|
|
32
|
+
orientation: orientation,
|
|
33
|
+
isDisabled: props.isDisabled,
|
|
34
|
+
name: name,
|
|
35
|
+
trackRef: trackRef,
|
|
36
|
+
inputRef: inputRef
|
|
37
|
+
}, state);
|
|
38
|
+
let value = state.getDisplayColor();
|
|
39
|
+
let generateBackground = ()=>{
|
|
40
|
+
let to;
|
|
41
|
+
if (orientation === "vertical") to = "top";
|
|
42
|
+
else if (direction === "ltr") to = "right";
|
|
43
|
+
else to = "left";
|
|
44
|
+
switch(channel){
|
|
45
|
+
case "hue":
|
|
46
|
+
{
|
|
47
|
+
let stops = [
|
|
48
|
+
0,
|
|
49
|
+
60,
|
|
50
|
+
120,
|
|
51
|
+
180,
|
|
52
|
+
240,
|
|
53
|
+
300,
|
|
54
|
+
360
|
|
55
|
+
].map((hue)=>value.withChannelValue("hue", hue).toString("css")).join(", ");
|
|
56
|
+
return `linear-gradient(to ${to}, ${stops})`;
|
|
57
|
+
}
|
|
58
|
+
case "lightness":
|
|
59
|
+
{
|
|
60
|
+
// We have to add an extra color stop in the middle so that the hue shows up at all.
|
|
61
|
+
// Otherwise it will always just be black to white.
|
|
62
|
+
let min = state.getThumbMinValue(0);
|
|
63
|
+
let max = state.getThumbMaxValue(0);
|
|
64
|
+
let start = value.withChannelValue(channel, min).toString("css");
|
|
65
|
+
let middle = value.withChannelValue(channel, (max - min) / 2).toString("css");
|
|
66
|
+
let end = value.withChannelValue(channel, max).toString("css");
|
|
67
|
+
return `linear-gradient(to ${to}, ${start}, ${middle}, ${end})`;
|
|
68
|
+
}
|
|
69
|
+
case "saturation":
|
|
70
|
+
case "brightness":
|
|
71
|
+
case "red":
|
|
72
|
+
case "green":
|
|
73
|
+
case "blue":
|
|
74
|
+
case "alpha":
|
|
75
|
+
{
|
|
76
|
+
let start = value.withChannelValue(channel, state.getThumbMinValue(0)).toString("css");
|
|
77
|
+
let end = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString("css");
|
|
78
|
+
return `linear-gradient(to ${to}, ${start}, ${end})`;
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
throw new Error("Unknown color channel: " + channel);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
let forcedColorAdjustNoneStyle = {
|
|
85
|
+
forcedColorAdjust: "none"
|
|
86
|
+
};
|
|
87
|
+
if (channel === "hue") inputProps["aria-valuetext"] += `, ${value.getHueName(locale)}`;
|
|
88
|
+
else if (channel !== "alpha") inputProps["aria-valuetext"] += `, ${value.getColorName(locale)}`;
|
|
89
|
+
let { visuallyHiddenProps: visuallyHiddenProps } = (0, $6WsjB$useVisuallyHidden)({
|
|
90
|
+
style: {
|
|
91
|
+
opacity: "0.0001",
|
|
92
|
+
width: "100%",
|
|
93
|
+
height: "100%",
|
|
94
|
+
pointerEvents: "none"
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
trackProps: {
|
|
99
|
+
...(0, $6WsjB$mergeProps)(groupProps, trackProps),
|
|
100
|
+
style: {
|
|
101
|
+
...trackProps.style,
|
|
102
|
+
...forcedColorAdjustNoneStyle,
|
|
103
|
+
background: generateBackground()
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
inputProps: {
|
|
107
|
+
...inputProps,
|
|
108
|
+
style: {
|
|
109
|
+
...inputProps.style,
|
|
110
|
+
...visuallyHiddenProps.style
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
thumbProps: {
|
|
114
|
+
...thumbProps,
|
|
115
|
+
style: {
|
|
116
|
+
...thumbProps.style,
|
|
117
|
+
...forcedColorAdjustNoneStyle
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
labelProps: labelProps,
|
|
121
|
+
outputProps: outputProps
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
export {$40af666d6c251e36$export$106b7a4e66508f66 as useColorSlider};
|
|
127
|
+
//# sourceMappingURL=useColorSlider.mjs.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {mergeProps as $6WsjB$mergeProps} from "@react-aria/utils";
|
|
2
|
+
import {useLocale as $6WsjB$useLocale} from "@react-aria/i18n";
|
|
3
|
+
import {useSlider as $6WsjB$useSlider, useSliderThumb as $6WsjB$useSliderThumb} from "@react-aria/slider";
|
|
4
|
+
import {useVisuallyHidden as $6WsjB$useVisuallyHidden} from "@react-aria/visually-hidden";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
* governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function $40af666d6c251e36$export$106b7a4e66508f66(props, state) {
|
|
21
|
+
let { trackRef: trackRef, inputRef: inputRef, orientation: orientation, channel: channel, "aria-label": ariaLabel, name: name } = props;
|
|
22
|
+
let { locale: locale, direction: direction } = (0, $6WsjB$useLocale)();
|
|
23
|
+
// Provide a default aria-label if there is no other label provided.
|
|
24
|
+
if (!props.label && !ariaLabel && !props["aria-labelledby"]) ariaLabel = state.value.getChannelName(channel, locale);
|
|
25
|
+
// @ts-ignore - ignore unused incompatible props
|
|
26
|
+
let { groupProps: groupProps, trackProps: trackProps, labelProps: labelProps, outputProps: outputProps } = (0, $6WsjB$useSlider)({
|
|
27
|
+
...props,
|
|
28
|
+
"aria-label": ariaLabel
|
|
29
|
+
}, state, trackRef);
|
|
30
|
+
let { inputProps: inputProps, thumbProps: thumbProps } = (0, $6WsjB$useSliderThumb)({
|
|
31
|
+
index: 0,
|
|
32
|
+
orientation: orientation,
|
|
33
|
+
isDisabled: props.isDisabled,
|
|
34
|
+
name: name,
|
|
35
|
+
trackRef: trackRef,
|
|
36
|
+
inputRef: inputRef
|
|
37
|
+
}, state);
|
|
38
|
+
let value = state.getDisplayColor();
|
|
39
|
+
let generateBackground = ()=>{
|
|
40
|
+
let to;
|
|
41
|
+
if (orientation === "vertical") to = "top";
|
|
42
|
+
else if (direction === "ltr") to = "right";
|
|
43
|
+
else to = "left";
|
|
44
|
+
switch(channel){
|
|
45
|
+
case "hue":
|
|
46
|
+
{
|
|
47
|
+
let stops = [
|
|
48
|
+
0,
|
|
49
|
+
60,
|
|
50
|
+
120,
|
|
51
|
+
180,
|
|
52
|
+
240,
|
|
53
|
+
300,
|
|
54
|
+
360
|
|
55
|
+
].map((hue)=>value.withChannelValue("hue", hue).toString("css")).join(", ");
|
|
56
|
+
return `linear-gradient(to ${to}, ${stops})`;
|
|
57
|
+
}
|
|
58
|
+
case "lightness":
|
|
59
|
+
{
|
|
60
|
+
// We have to add an extra color stop in the middle so that the hue shows up at all.
|
|
61
|
+
// Otherwise it will always just be black to white.
|
|
62
|
+
let min = state.getThumbMinValue(0);
|
|
63
|
+
let max = state.getThumbMaxValue(0);
|
|
64
|
+
let start = value.withChannelValue(channel, min).toString("css");
|
|
65
|
+
let middle = value.withChannelValue(channel, (max - min) / 2).toString("css");
|
|
66
|
+
let end = value.withChannelValue(channel, max).toString("css");
|
|
67
|
+
return `linear-gradient(to ${to}, ${start}, ${middle}, ${end})`;
|
|
68
|
+
}
|
|
69
|
+
case "saturation":
|
|
70
|
+
case "brightness":
|
|
71
|
+
case "red":
|
|
72
|
+
case "green":
|
|
73
|
+
case "blue":
|
|
74
|
+
case "alpha":
|
|
75
|
+
{
|
|
76
|
+
let start = value.withChannelValue(channel, state.getThumbMinValue(0)).toString("css");
|
|
77
|
+
let end = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString("css");
|
|
78
|
+
return `linear-gradient(to ${to}, ${start}, ${end})`;
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
throw new Error("Unknown color channel: " + channel);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
let forcedColorAdjustNoneStyle = {
|
|
85
|
+
forcedColorAdjust: "none"
|
|
86
|
+
};
|
|
87
|
+
if (channel === "hue") inputProps["aria-valuetext"] += `, ${value.getHueName(locale)}`;
|
|
88
|
+
else if (channel !== "alpha") inputProps["aria-valuetext"] += `, ${value.getColorName(locale)}`;
|
|
89
|
+
let { visuallyHiddenProps: visuallyHiddenProps } = (0, $6WsjB$useVisuallyHidden)({
|
|
90
|
+
style: {
|
|
91
|
+
opacity: "0.0001",
|
|
92
|
+
width: "100%",
|
|
93
|
+
height: "100%",
|
|
94
|
+
pointerEvents: "none"
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
trackProps: {
|
|
99
|
+
...(0, $6WsjB$mergeProps)(groupProps, trackProps),
|
|
100
|
+
style: {
|
|
101
|
+
...trackProps.style,
|
|
102
|
+
...forcedColorAdjustNoneStyle,
|
|
103
|
+
background: generateBackground()
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
inputProps: {
|
|
107
|
+
...inputProps,
|
|
108
|
+
style: {
|
|
109
|
+
...inputProps.style,
|
|
110
|
+
...visuallyHiddenProps.style
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
thumbProps: {
|
|
114
|
+
...thumbProps,
|
|
115
|
+
style: {
|
|
116
|
+
...thumbProps.style,
|
|
117
|
+
...forcedColorAdjustNoneStyle
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
labelProps: labelProps,
|
|
121
|
+
outputProps: outputProps
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
export {$40af666d6c251e36$export$106b7a4e66508f66 as useColorSlider};
|
|
127
|
+
//# sourceMappingURL=useColorSlider.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAmCM,SAAS,0CAAe,KAA6B,EAAE,KAAuB;IACnF,IAAI,YAAC,QAAQ,YAAE,QAAQ,eAAE,WAAW,WAAE,OAAO,EAAE,cAAc,SAAS,QAAE,IAAI,EAAC,GAAG;IAEhF,IAAI,UAAC,MAAM,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAElC,oEAAoE;IACpE,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,kBAAkB,EACzD,YAAY,MAAM,KAAK,CAAC,cAAc,CAAC,SAAS;IAGlD,gDAAgD;IAChD,IAAI,cAAC,UAAU,cAAE,UAAU,cAAE,UAAU,eAAE,WAAW,EAAC,GAAG,CAAA,GAAA,gBAAQ,EAAE;QAAC,GAAG,KAAK;QAAE,cAAc;IAAS,GAAG,OAAO;IAC9G,IAAI,cAAC,UAAU,cAAE,UAAU,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QAC5C,OAAO;qBACP;QACA,YAAY,MAAM,UAAU;cAC5B;kBACA;kBACA;IACF,GAAG;IAEH,IAAI,QAAQ,MAAM,eAAe;IACjC,IAAI,qBAAqB;QACvB,IAAI;QACJ,IAAI,gBAAgB,YAClB,KAAK;aACA,IAAI,cAAc,OACvB,KAAK;aAEL,KAAK;QAEP,OAAQ;YACN,KAAK;gBAAO;oBACV,IAAI,QAAQ;wBAAC;wBAAG;wBAAI;wBAAK;wBAAK;wBAAK;wBAAK;qBAAI,CAAC,GAAG,CAAC,CAAA,MAAO,MAAM,gBAAgB,CAAC,OAAO,KAAK,QAAQ,CAAC,QAAQ,IAAI,CAAC;oBACjH,OAAO,CAAC,mBAAmB,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;gBAC9C;YACA,KAAK;gBAAa;oBAChB,oFAAoF;oBACpF,mDAAmD;oBACnD,IAAI,MAAM,MAAM,gBAAgB,CAAC;oBACjC,IAAI,MAAM,MAAM,gBAAgB,CAAC;oBACjC,IAAI,QAAQ,MAAM,gBAAgB,CAAC,SAAS,KAAK,QAAQ,CAAC;oBAC1D,IAAI,SAAS,MAAM,gBAAgB,CAAC,SAAS,AAAC,CAAA,MAAM,GAAE,IAAK,GAAG,QAAQ,CAAC;oBACvE,IAAI,MAAM,MAAM,gBAAgB,CAAC,SAAS,KAAK,QAAQ,CAAC;oBACxD,OAAO,CAAC,mBAAmB,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;gBACjE;YACA,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;YACL,KAAK;gBAAS;oBACZ,IAAI,QAAQ,MAAM,gBAAgB,CAAC,SAAS,MAAM,gBAAgB,CAAC,IAAI,QAAQ,CAAC;oBAChF,IAAI,MAAM,MAAM,gBAAgB,CAAC,SAAS,MAAM,gBAAgB,CAAC,IAAI,QAAQ,CAAC;oBAC9E,OAAO,CAAC,mBAAmB,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,CAAC;gBACtD;YACA;gBACE,MAAM,IAAI,MAAM,4BAA4B;QAChD;IACF;IAEA,IAAI,6BAA6B;QAAC,mBAAmB;IAAM;IAE3D,IAAI,YAAY,OACd,UAAU,CAAC,iBAAiB,IAAI,CAAC,EAAE,EAAE,MAAM,UAAU,CAAC,QAAQ,CAAC;SAC1D,IAAI,YAAY,SACrB,UAAU,CAAC,iBAAiB,IAAI,CAAC,EAAE,EAAE,MAAM,YAAY,CAAC,QAAQ,CAAC;IAGnE,IAAI,uBAAC,mBAAmB,EAAC,GAAG,CAAA,GAAA,wBAAgB,EAAE;QAC5C,OAAO;YACL,SAAS;YACT,OAAO;YACP,QAAQ;YACR,eAAe;QACjB;IACF;IAEA,OAAO;QACL,YAAY;YACV,GAAG,CAAA,GAAA,iBAAS,EAAE,YAAY,WAAW;YACrC,OAAO;gBACL,GAAG,WAAW,KAAK;gBACnB,GAAG,0BAA0B;gBAC7B,YAAY;YACd;QACF;QACA,YAAY;YACV,GAAG,UAAU;YACb,OAAO;gBACL,GAAG,WAAW,KAAK;gBACnB,GAAG,oBAAoB,KAAK;YAC9B;QACF;QACA,YAAY;YACV,GAAG,UAAU;YACb,OAAO;gBACL,GAAG,WAAW,KAAK;gBACnB,GAAG,0BAA0B;YAC/B;QACF;oBACA;qBACA;IACF;AACF","sources":["packages/@react-aria/color/src/useColorSlider.ts"],"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\nimport {AriaColorSliderProps} from '@react-types/color';\nimport {ColorSliderState} from '@react-stately/color';\nimport {DOMAttributes} from '@react-types/shared';\nimport {InputHTMLAttributes, RefObject} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSlider, useSliderThumb} from '@react-aria/slider';\nimport {useVisuallyHidden} from '@react-aria/visually-hidden';\n\nexport interface AriaColorSliderOptions extends AriaColorSliderProps {\n /** A ref for the track element. */\n trackRef: RefObject<Element>,\n /** A ref for the input element. */\n inputRef: RefObject<HTMLInputElement>\n}\n\nexport interface ColorSliderAria {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n /** Props for the track element. */\n trackProps: DOMAttributes,\n /** Props for the thumb element. */\n thumbProps: DOMAttributes,\n /** Props for the visually hidden range input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Props for the output element, displaying the value of the color slider. */\n outputProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a color slider component.\n * Color sliders allow users to adjust an individual channel of a color value.\n */\nexport function useColorSlider(props: AriaColorSliderOptions, state: ColorSliderState): ColorSliderAria {\n let {trackRef, inputRef, orientation, channel, 'aria-label': ariaLabel, name} = props;\n\n let {locale, direction} = useLocale();\n\n // Provide a default aria-label if there is no other label provided.\n if (!props.label && !ariaLabel && !props['aria-labelledby']) {\n ariaLabel = state.value.getChannelName(channel, locale);\n }\n\n // @ts-ignore - ignore unused incompatible props\n let {groupProps, trackProps, labelProps, outputProps} = useSlider({...props, 'aria-label': ariaLabel}, state, trackRef);\n let {inputProps, thumbProps} = useSliderThumb({\n index: 0,\n orientation,\n isDisabled: props.isDisabled,\n name,\n trackRef,\n inputRef\n }, state);\n\n let value = state.getDisplayColor();\n let generateBackground = () => {\n let to: string;\n if (orientation === 'vertical') {\n to = 'top';\n } else if (direction === 'ltr') {\n to = 'right';\n } else {\n to = 'left';\n }\n switch (channel) {\n case 'hue': {\n let stops = [0, 60, 120, 180, 240, 300, 360].map(hue => value.withChannelValue('hue', hue).toString('css')).join(', ');\n return `linear-gradient(to ${to}, ${stops})`;\n }\n case 'lightness': {\n // We have to add an extra color stop in the middle so that the hue shows up at all.\n // Otherwise it will always just be black to white.\n let min = state.getThumbMinValue(0);\n let max = state.getThumbMaxValue(0);\n let start = value.withChannelValue(channel, min).toString('css');\n let middle = value.withChannelValue(channel, (max - min) / 2).toString('css');\n let end = value.withChannelValue(channel, max).toString('css');\n return `linear-gradient(to ${to}, ${start}, ${middle}, ${end})`;\n }\n case 'saturation':\n case 'brightness':\n case 'red':\n case 'green':\n case 'blue':\n case 'alpha': {\n let start = value.withChannelValue(channel, state.getThumbMinValue(0)).toString('css');\n let end = value.withChannelValue(channel, state.getThumbMaxValue(0)).toString('css');\n return `linear-gradient(to ${to}, ${start}, ${end})`;\n }\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n };\n\n let forcedColorAdjustNoneStyle = {forcedColorAdjust: 'none'};\n\n if (channel === 'hue') {\n inputProps['aria-valuetext'] += `, ${value.getHueName(locale)}`;\n } else if (channel !== 'alpha') {\n inputProps['aria-valuetext'] += `, ${value.getColorName(locale)}`;\n }\n\n let {visuallyHiddenProps} = useVisuallyHidden({\n style: {\n opacity: '0.0001',\n width: '100%',\n height: '100%',\n pointerEvents: 'none'\n }\n });\n\n return {\n trackProps: {\n ...mergeProps(groupProps, trackProps),\n style: {\n ...trackProps.style,\n ...forcedColorAdjustNoneStyle,\n background: generateBackground()\n }\n },\n inputProps: {\n ...inputProps,\n style: {\n ...inputProps.style,\n ...visuallyHiddenProps.style\n }\n },\n thumbProps: {\n ...thumbProps,\n style: {\n ...thumbProps.style,\n ...forcedColorAdjustNoneStyle\n }\n },\n labelProps,\n outputProps\n };\n}\n"],"names":[],"version":3,"file":"useColorSlider.module.js.map"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var $4a33e168940636d5$exports = require("./intlStrings.main.js");
|
|
2
|
+
var $gp2Sz$reactariautils = require("@react-aria/utils");
|
|
3
|
+
var $gp2Sz$react = require("react");
|
|
4
|
+
var $gp2Sz$reactstatelycolor = require("@react-stately/color");
|
|
5
|
+
var $gp2Sz$reactariai18n = require("@react-aria/i18n");
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function $parcel$interopDefault(a) {
|
|
9
|
+
return a && a.__esModule ? a.default : a;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function $parcel$export(e, n, v, s) {
|
|
13
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
$parcel$export(module.exports, "useColorSwatch", () => $7c947b33be1ec2a6$export$9060ae606178d849);
|
|
17
|
+
/*
|
|
18
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
19
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
20
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
21
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
24
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
25
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
26
|
+
* governing permissions and limitations under the License.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
function $7c947b33be1ec2a6$export$9060ae606178d849(props) {
|
|
33
|
+
let { color: value, colorName: colorName } = props;
|
|
34
|
+
let nonNullValue = value || "#fff0";
|
|
35
|
+
let color = (0, $gp2Sz$react.useMemo)(()=>typeof nonNullValue === "string" ? (0, $gp2Sz$reactstatelycolor.parseColor)(nonNullValue) : nonNullValue, [
|
|
36
|
+
nonNullValue
|
|
37
|
+
]);
|
|
38
|
+
let { locale: locale } = (0, $gp2Sz$reactariai18n.useLocale)();
|
|
39
|
+
let DOMProps = (0, $gp2Sz$reactariautils.filterDOMProps)(props, {
|
|
40
|
+
labelable: true
|
|
41
|
+
});
|
|
42
|
+
let stringFormatter = (0, $gp2Sz$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($4a33e168940636d5$exports))), "@react-aria/color");
|
|
43
|
+
let id = (0, $gp2Sz$reactariautils.useId)(props.id);
|
|
44
|
+
if (!colorName) colorName = color.getChannelValue("alpha") === 0 ? stringFormatter.format("transparent") : color.getColorName(locale);
|
|
45
|
+
return {
|
|
46
|
+
colorSwatchProps: {
|
|
47
|
+
...DOMProps,
|
|
48
|
+
role: "img",
|
|
49
|
+
"aria-roledescription": stringFormatter.format("colorSwatch"),
|
|
50
|
+
"aria-label": [
|
|
51
|
+
colorName,
|
|
52
|
+
props["aria-label"] || ""
|
|
53
|
+
].filter(Boolean).join(", "),
|
|
54
|
+
"aria-labelledby": props["aria-labelledby"] ? `${id} ${props["aria-labelledby"]}` : undefined,
|
|
55
|
+
id: id,
|
|
56
|
+
style: {
|
|
57
|
+
backgroundColor: color.toString("css"),
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
forcedColorAdjust: "none"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
color: color || null
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=useColorSwatch.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAkCM,SAAS,0CAAe,KAA2B;IACxD,IAAI,EAAC,OAAO,KAAK,aAAE,SAAS,EAAC,GAAG;IAChC,IAAI,eAAe,SAAS;IAC5B,IAAI,QAAQ,CAAA,GAAA,oBAAM,EAAE,IAAM,OAAO,iBAAiB,WAAW,CAAA,GAAA,mCAAS,EAAE,gBAAgB,cAAc;QAAC;KAAa;IACpH,IAAI,UAAC,MAAM,EAAC,GAAG,CAAA,GAAA,8BAAQ;IACvB,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IACrD,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,KAAK,CAAA,GAAA,2BAAI,EAAE,MAAM,EAAE;IAEvB,IAAI,CAAC,WACH,YAAY,MAAM,eAAe,CAAC,aAAa,IAAI,gBAAgB,MAAM,CAAC,iBAAiB,MAAM,YAAY,CAAC;IAGhH,OAAO;QACL,kBAAkB;YAChB,GAAG,QAAQ;YACX,MAAM;YACN,wBAAwB,gBAAgB,MAAM,CAAC;YAC/C,cAAc;gBAAC;gBAAW,KAAK,CAAC,aAAa,IAAI;aAAG,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC;YAC1E,mBAAmB,KAAK,CAAC,kBAAkB,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC,GAAG;gBACpF;YACA,OAAO;gBACL,iBAAiB,MAAM,QAAQ,CAAC;gBAChC,aAAa;gBACb,mBAAmB;YACrB;QACF;QACA,OAAO,SAAS;IAClB;AACF","sources":["packages/@react-aria/color/src/useColorSwatch.ts"],"sourcesContent":["/*\n * Copyright 2024 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\nimport {AriaLabelingProps, DOMProps} from '@react-types/shared';\nimport {Color} from '@react-types/color';\nimport {filterDOMProps, useId} from '@react-aria/utils';\nimport {HTMLAttributes, useMemo} from 'react';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {parseColor} from '@react-stately/color';\nimport {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaColorSwatchProps extends AriaLabelingProps, DOMProps {\n /** The color value to display in the swatch. */\n color?: string | Color | null,\n /** \n * A localized accessible name for the color.\n * By default, a description is generated from the color value,\n * but this can be overridden if you have a more specific color\n * name (e.g. Pantone colors).\n */\n colorName?: string\n}\n\nexport interface ColorSwatchAria {\n /** Props for the color swatch element. */\n colorSwatchProps: HTMLAttributes<HTMLElement>,\n /** The parsed color value of the swatch. */\n color: Color\n}\n\n/**\n * Provides the accessibility implementation for a color swatch component.\n * A color swatch displays a preview of a selected color.\n */\nexport function useColorSwatch(props: AriaColorSwatchProps): ColorSwatchAria {\n let {color: value, colorName} = props;\n let nonNullValue = value || '#fff0';\n let color = useMemo(() => typeof nonNullValue === 'string' ? parseColor(nonNullValue) : nonNullValue, [nonNullValue]);\n let {locale} = useLocale();\n let DOMProps = filterDOMProps(props, {labelable: true});\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/color');\n let id = useId(props.id);\n\n if (!colorName) {\n colorName = color.getChannelValue('alpha') === 0 ? stringFormatter.format('transparent') : color.getColorName(locale);\n }\n\n return {\n colorSwatchProps: {\n ...DOMProps,\n role: 'img',\n 'aria-roledescription': stringFormatter.format('colorSwatch'),\n 'aria-label': [colorName, props['aria-label'] || ''].filter(Boolean).join(', '),\n 'aria-labelledby': props['aria-labelledby'] ? `${id} ${props['aria-labelledby']}` : undefined,\n id,\n style: {\n backgroundColor: color.toString('css'),\n // @ts-ignore\n forcedColorAdjust: 'none'\n }\n },\n color: color || null\n };\n}\n"],"names":[],"version":3,"file":"useColorSwatch.main.js.map"}
|