@react-stately/color 3.8.6 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useColorAreaState.main.js +2 -0
- package/dist/useColorAreaState.main.js.map +1 -1
- package/dist/useColorAreaState.mjs +3 -1
- package/dist/useColorAreaState.module.js +3 -1
- package/dist/useColorAreaState.module.js.map +1 -1
- package/dist/useColorChannelFieldState.main.js +19 -10
- package/dist/useColorChannelFieldState.main.js.map +1 -1
- package/dist/useColorChannelFieldState.mjs +20 -11
- package/dist/useColorChannelFieldState.module.js +20 -11
- package/dist/useColorChannelFieldState.module.js.map +1 -1
- package/dist/useColorFieldState.main.js +5 -2
- package/dist/useColorFieldState.main.js.map +1 -1
- package/dist/useColorFieldState.mjs +5 -2
- package/dist/useColorFieldState.module.js +5 -2
- package/dist/useColorFieldState.module.js.map +1 -1
- package/dist/useColorSliderState.main.js +7 -0
- package/dist/useColorSliderState.main.js.map +1 -1
- package/dist/useColorSliderState.mjs +8 -1
- package/dist/useColorSliderState.module.js +8 -1
- package/dist/useColorSliderState.module.js.map +1 -1
- package/dist/useColorWheelState.main.js +2 -0
- package/dist/useColorWheelState.main.js.map +1 -1
- package/dist/useColorWheelState.mjs +3 -1
- package/dist/useColorWheelState.module.js +3 -1
- package/dist/useColorWheelState.module.js.map +1 -1
- package/package.json +9 -9
- package/src/useColorAreaState.ts +4 -0
- package/src/useColorChannelFieldState.ts +23 -8
- package/src/useColorFieldState.ts +9 -2
- package/src/useColorSliderState.ts +5 -1
- package/src/useColorWheelState.ts +4 -0
|
@@ -26,9 +26,9 @@ const $b335ada08155d9c0$var$MAX_COLOR_INT = $b335ada08155d9c0$var$MAX_COLOR.toHe
|
|
|
26
26
|
function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
|
|
27
27
|
let { value: value, defaultValue: defaultValue, onChange: onChange } = props;
|
|
28
28
|
let { step: step } = $b335ada08155d9c0$var$MIN_COLOR.getChannelRange('red');
|
|
29
|
-
let initialValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(value);
|
|
30
29
|
let initialDefaultValue = (0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(defaultValue);
|
|
31
|
-
let [colorValue, setColorValue] = (0, $aP5W6$useControlledState)(
|
|
30
|
+
let [colorValue, setColorValue] = (0, $aP5W6$useControlledState)((0, $aa90ad8b2b1d015f$export$5aadd9c0606af5c2)(value), initialDefaultValue, onChange);
|
|
31
|
+
let [initialValue] = (0, $aP5W6$useState)(colorValue);
|
|
32
32
|
let [inputValue, setInputValue] = (0, $aP5W6$useState)(()=>(value || defaultValue) && colorValue ? colorValue.toString('hex') : '');
|
|
33
33
|
let validation = (0, $aP5W6$useFormValidationState)({
|
|
34
34
|
...props,
|
|
@@ -78,6 +78,7 @@ function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
|
|
|
78
78
|
let newColorValue = '';
|
|
79
79
|
if (colorValue) newColorValue = colorValue.toString('hex');
|
|
80
80
|
setInputValue(newColorValue);
|
|
81
|
+
validation.commitValidation();
|
|
81
82
|
};
|
|
82
83
|
let increment = ()=>{
|
|
83
84
|
let newValue = $b335ada08155d9c0$var$addColorValue(parsedValue, step);
|
|
@@ -109,6 +110,8 @@ function $b335ada08155d9c0$export$d52a01683abdfcd6(props) {
|
|
|
109
110
|
...validation,
|
|
110
111
|
validate: validate,
|
|
111
112
|
colorValue: colorValue,
|
|
113
|
+
defaultColorValue: initialDefaultValue !== null && initialDefaultValue !== void 0 ? initialDefaultValue : initialValue,
|
|
114
|
+
setColorValue: setColorValue,
|
|
112
115
|
inputValue: inputValue,
|
|
113
116
|
setInputValue: setInputValue,
|
|
114
117
|
commit: commit,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CA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Q;IAC/B,IAAI,WAAW,SAAS,QAAQ;IAEhC,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,WAAW,MAAM,sCAAgB;IAClE,IAAI,aAAa,UAAU;QACzB,IAAI,iBAAiB,CAAC,CAAC,EAAE,SAAS,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,KAAK,WAAW,IAAI;QAC/E,WAAW,CAAA,GAAA,wCAAS,EAAE;IACxB;IACA,OAAO;AACT","sources":["packages/@react-stately/color/src/useColorFieldState.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 {Color, ColorFieldProps} from '@react-types/color';\nimport {FormValidationState, useFormValidationState} from '@react-stately/form';\nimport {parseColor} from './Color';\nimport {useColor} from './useColor';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorFieldState extends FormValidationState {\n /**\n * The current text value of the input. Updated as the user types,\n * and formatted according to `formatOptions` on blur.\n */\n readonly inputValue: string,\n /**\n * The currently parsed color value, or null if the field is empty.\n * Updated based on the `inputValue` as the user types.\n */\n readonly colorValue: Color | null,\n /** The default value of the color field. */\n readonly defaultColorValue: Color | null,\n /** Sets the color value of the field. */\n setColorValue(value: Color | null): void,\n /** Sets the current text value of the input. */\n setInputValue(value: string): void,\n /**\n * Updates the input value based on the currently parsed color value.\n * Typically this is called when the field is blurred.\n */\n commit(): void,\n /** Increments the current input value to the next step boundary, and fires `onChange`. */\n increment(): void,\n /** Decrements the current input value to the next step boundary, and fires `onChange`. */\n decrement(): void,\n /** Sets the current value to the maximum color value, and fires `onChange`. */\n incrementToMax(): void,\n /** Sets the current value to the minimum color value, and fires `onChange`. */\n decrementToMin(): void,\n /**\n * Validates a user input string.\n * Values can be partially entered, and may be valid even if they cannot currently be parsed to a color.\n * Can be used to implement validation as a user types.\n */\n validate(value: string): boolean\n}\n\nconst MIN_COLOR = parseColor('#000000');\nconst MAX_COLOR = parseColor('#FFFFFF');\nconst MIN_COLOR_INT = MIN_COLOR.toHexInt();\nconst MAX_COLOR_INT = MAX_COLOR.toHexInt();\n\n/**\n * Provides state management for a color field component. Color fields allow\n * users to enter and adjust a hex color value.\n */\nexport function useColorFieldState(\n props: ColorFieldProps\n): ColorFieldState {\n let {\n value,\n defaultValue,\n onChange\n } = props;\n let {step} = MIN_COLOR.getChannelRange('red');\n\n let initialDefaultValue = useColor(defaultValue);\n let [colorValue, setColorValue] = useControlledState<Color | null>(useColor(value), initialDefaultValue!, onChange);\n let [initialValue] = useState(colorValue);\n let [inputValue, setInputValue] = useState(() => (value || defaultValue) && colorValue ? colorValue.toString('hex') : '');\n\n let validation = useFormValidationState({\n ...props,\n value: colorValue\n });\n\n let safelySetColorValue = (newColor: Color | null) => {\n if (!colorValue || !newColor) {\n setColorValue(newColor);\n return;\n }\n if (newColor.toHexInt() !== colorValue.toHexInt()) {\n setColorValue(newColor);\n return;\n }\n };\n\n let [prevValue, setPrevValue] = useState(colorValue);\n if (prevValue !== colorValue) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n setPrevValue(colorValue);\n }\n\n let parsedValue = useMemo(() => {\n let color;\n try {\n color = parseColor(inputValue.startsWith('#') ? inputValue : `#${inputValue}`);\n } catch {\n color = null;\n }\n return color;\n }, [inputValue]);\n\n let commit = () => {\n // Set to empty state if input value is empty\n if (!inputValue.length) {\n safelySetColorValue(null);\n if (value === undefined || colorValue === null) {\n setInputValue('');\n } else {\n setInputValue(colorValue.toString('hex'));\n }\n return;\n }\n\n // if it failed to parse, then reset input to formatted version of current number\n if (parsedValue == null) {\n setInputValue(colorValue ? colorValue.toString('hex') : '');\n return;\n }\n\n safelySetColorValue(parsedValue);\n // in a controlled state, the numberValue won't change, so we won't go back to our old input without help\n let newColorValue = '';\n if (colorValue) {\n newColorValue = colorValue.toString('hex');\n }\n setInputValue(newColorValue);\n validation.commitValidation();\n };\n\n let increment = () => {\n let newValue = addColorValue(parsedValue, step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let decrement = () => {\n let newValue = addColorValue(parsedValue, -step);\n // if we've arrived at the same value that was previously in the state, the\n // input value should be updated to match\n // ex type 4, press increment, highlight the number in the input, type 4 again, press increment\n // you'd be at 5, then incrementing to 5 again, so no re-render would happen and 4 would be left in the input\n if (newValue === colorValue) {\n setInputValue(newValue.toString('hex'));\n }\n safelySetColorValue(newValue);\n validation.commitValidation();\n };\n let incrementToMax = () => safelySetColorValue(MAX_COLOR);\n let decrementToMin = () => safelySetColorValue(MIN_COLOR);\n\n let validate = (value: string) => value === '' || !!value.match(/^#?[0-9a-f]{0,6}$/i)?.[0];\n\n return {\n ...validation,\n validate,\n colorValue,\n defaultColorValue: initialDefaultValue ?? initialValue,\n setColorValue,\n inputValue,\n setInputValue,\n commit,\n increment,\n incrementToMax,\n decrement,\n decrementToMin\n };\n}\n\nfunction addColorValue(color: Color, step: number) {\n let newColor = color ? color : MIN_COLOR;\n let colorInt = newColor.toHexInt();\n\n let clampInt = Math.min(Math.max(colorInt + step, MIN_COLOR_INT), MAX_COLOR_INT);\n if (clampInt !== colorInt) {\n let newColorString = `#${clampInt.toString(16).padStart(6, '0').toUpperCase()}`;\n newColor = parseColor(newColorString);\n }\n return newColor;\n}\n"],"names":[],"version":3,"file":"useColorFieldState.module.js.map"}
|
|
@@ -34,6 +34,12 @@ function $5386a492cfd3234c$export$57bc203e1c9c6d44(props) {
|
|
|
34
34
|
colorValue,
|
|
35
35
|
colorSpace
|
|
36
36
|
]);
|
|
37
|
+
let [initialValue] = (0, $93tpS$react.useState)(colorValue);
|
|
38
|
+
let defaultColorValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : initialValue;
|
|
39
|
+
let defaultColor = (0, $93tpS$react.useMemo)(()=>colorSpace && defaultColorValue ? defaultColorValue.toFormat(colorSpace) : defaultColorValue, [
|
|
40
|
+
defaultColorValue,
|
|
41
|
+
colorSpace
|
|
42
|
+
]);
|
|
37
43
|
let sliderState = (0, $93tpS$reactstatelyslider.useSliderState)({
|
|
38
44
|
...color.getChannelRange(channel),
|
|
39
45
|
...otherProps,
|
|
@@ -41,6 +47,7 @@ function $5386a492cfd3234c$export$57bc203e1c9c6d44(props) {
|
|
|
41
47
|
// @ts-ignore
|
|
42
48
|
numberFormatter: null,
|
|
43
49
|
value: color.getChannelValue(channel),
|
|
50
|
+
defaultValue: defaultColor.getChannelValue(channel),
|
|
44
51
|
onChange (v) {
|
|
45
52
|
setColor(color.withChannelValue(channel, v));
|
|
46
53
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA6BM,SAAS,0CAAoB,KAA8B;IAChE,IAAI,WAAC,OAAO,cAAE,UAAU,SAAE,KAAK,gBAAE,YAAY,YAAE,QAAQ,UAAE,MAAM,EAAE,GAAG,YAAW,GAAG;IAClF,IAAI,SAAS,QAAQ,gBAAgB,MACnC,MAAM,IAAI,MAAM;IAGlB,IAAI,OACF,QAAQ,CAAA,GAAA,wCAAa,EAAE;IAEzB,IAAI,cACF,eAAe,CAAA,GAAA,wCAAa,EAAE;IAEhC,6HAA6H;IAC7H,IAAI,CAAC,YAAY,SAAS,GAAG,CAAA,GAAA,2CAAiB,EAAS,OAAgB,cAAuB;IAC9F,IAAI,QAAQ,CAAA,GAAA,oBAAM,EAAE,IAAM,cAAc,aAAa,WAAW,QAAQ,CAAC,cAAc,YAAY;QAAC;QAAY;KAAW;IAC3H,IAAI,cAAc,CAAA,GAAA,wCAAa,EAAE;QAC/B,GAAG,MAAM,eAAe,CAAC,QAAQ;QACjC,GAAG,UAAU;QACb,sHAAsH;QACtH,aAAa;QACb,iBAAiB;QACjB,OAAO,MAAM,eAAe,CAAC;QAC7B,UAAS,CAAC;YACR,SAAS,MAAM,gBAAgB,CAAC,SAAS;QAC3C;QACA,aAAY,CAAC;YACX,mGAAmG;YACnG,IAAI,MAAM,WAAW,EACnB,MAAM,WAAW,CAAC,MAAM,gBAAgB,CAAC,SAAS;QAEtD;IACF;IAEA,IAAI,QAAC,IAAI,YAAE,QAAQ,EAAC,GAAG,MAAM,eAAe,CAAC;IAC7C,OAAO;QACL,GAAG,WAAW;QACd,OAAO;QACP,UAAS,KAAK;YACZ,SAAS,CAAA,GAAA,wCAAa,EAAE;QAC1B;QACA;YACE,OAAQ;gBACN,KAAK;oBACH,OAAO,CAAA,GAAA,oCAAS,EAAE,CAAC,IAAI,EAAE,MAAM,eAAe,CAAC,OAAO,YAAY,CAAC;gBACrE,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;oBACH,OAAO,MAAM,gBAAgB,CAAC,SAAS;gBACzC,KAAK;oBACH,OAAO;gBAET;oBACE,MAAM,IAAI,MAAM,4BAA4B;YAChD;QACF;QACA;YACE,OAAO,MAAM,kBAAkB,CAAC,SAAS;QAC3C;cACA;kBACA;QACA,YAAY,YAAY,eAAe,CAAC;IAC1C;AACF","sources":["packages/@react-stately/color/src/useColorSliderState.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 {Color, ColorSliderProps} from '@react-types/color';\nimport {normalizeColor, parseColor} from './Color';\nimport {SliderState, useSliderState} from '@react-stately/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo} from 'react';\n\nexport interface ColorSliderState extends SliderState {\n /** The current color value represented by the color slider. */\n readonly value: Color,\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void,\n /** Returns the color that should be displayed in the slider instead of `value` or the optional parameter. */\n getDisplayColor(): Color,\n /** Whether the color slider is currently being dragged. */\n readonly isDragging: boolean\n}\n\n\nexport interface ColorSliderStateOptions extends ColorSliderProps {\n /** The locale to use for formatting the color channel value. */\n locale: string\n}\n\n/**\n * Provides state management for a color slider component.\n * Color sliders allow users to adjust an individual channel of a color value.\n */\nexport function useColorSliderState(props: ColorSliderStateOptions): ColorSliderState {\n let {channel, colorSpace, value, defaultValue, onChange, locale, ...otherProps} = props;\n if (value == null && defaultValue == null) {\n throw new Error('useColorSliderState requires a value or defaultValue');\n }\n\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we throw an error\n let [colorValue, setColor] = useControlledState<Color>(value as Color, defaultValue as Color, onChange);\n let color = useMemo(() => colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue, [colorValue, colorSpace]);\n let sliderState = useSliderState({\n ...color.getChannelRange(channel),\n ...otherProps,\n // Unused except in getThumbValueLabel, which is overridden below. null to localize the TypeScript error for ignoring.\n // @ts-ignore\n numberFormatter: null,\n value: color.getChannelValue(channel),\n onChange(v) {\n setColor(color.withChannelValue(channel, v));\n },\n onChangeEnd(v) {\n // onChange will have already been called with the right value, this is just to trigger onChangeEnd\n if (props.onChangeEnd) {\n props.onChangeEnd(color.withChannelValue(channel, v));\n }\n }\n });\n\n let {step, pageSize} = color.getChannelRange(channel);\n return {\n ...sliderState,\n value: color,\n setValue(value) {\n setColor(normalizeColor(value));\n },\n getDisplayColor() {\n switch (channel) {\n case 'hue':\n return parseColor(`hsl(${color.getChannelValue('hue')}, 100%, 50%)`);\n case 'lightness':\n case 'brightness':\n case 'saturation':\n case 'red':\n case 'green':\n case 'blue':\n return color.withChannelValue('alpha', 1);\n case 'alpha': {\n return color;\n }\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n },\n getThumbValueLabel() {\n return color.formatChannelValue(channel, locale);\n },\n step,\n pageSize,\n isDragging: sliderState.isThumbDragging(0)\n };\n}\n"],"names":[],"version":3,"file":"useColorSliderState.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA6BM,SAAS,0CAAoB,KAA8B;IAChE,IAAI,WAAC,OAAO,cAAE,UAAU,SAAE,KAAK,gBAAE,YAAY,YAAE,QAAQ,UAAE,MAAM,EAAE,GAAG,YAAW,GAAG;IAClF,IAAI,SAAS,QAAQ,gBAAgB,MACnC,MAAM,IAAI,MAAM;IAGlB,IAAI,OACF,QAAQ,CAAA,GAAA,wCAAa,EAAE;IAEzB,IAAI,cACF,eAAe,CAAA,GAAA,wCAAa,EAAE;IAEhC,6HAA6H;IAC7H,IAAI,CAAC,YAAY,SAAS,GAAG,CAAA,GAAA,2CAAiB,EAAS,OAAgB,cAAuB;IAC9F,IAAI,QAAQ,CAAA,GAAA,oBAAM,EAAE,IAAM,cAAc,aAAa,WAAW,QAAQ,CAAC,cAAc,YAAY;QAAC;QAAY;KAAW;IAC3H,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC9B,IAAI,oBAAoB,AAAC,yBAAA,0BAAA,eAA0B;IACnD,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IAAM,cAAc,oBAAoB,kBAAkB,QAAQ,CAAC,cAAc,mBAAmB;QAAC;QAAmB;KAAW;IAC9J,IAAI,cAAc,CAAA,GAAA,wCAAa,EAAE;QAC/B,GAAG,MAAM,eAAe,CAAC,QAAQ;QACjC,GAAG,UAAU;QACb,sHAAsH;QACtH,aAAa;QACb,iBAAiB;QACjB,OAAO,MAAM,eAAe,CAAC;QAC7B,cAAc,aAAa,eAAe,CAAC;QAC3C,UAAS,CAAC;YACR,SAAS,MAAM,gBAAgB,CAAC,SAAS;QAC3C;QACA,aAAY,CAAC;YACX,mGAAmG;YACnG,IAAI,MAAM,WAAW,EACnB,MAAM,WAAW,CAAC,MAAM,gBAAgB,CAAC,SAAS;QAEtD;IACF;IAEA,IAAI,QAAC,IAAI,YAAE,QAAQ,EAAC,GAAG,MAAM,eAAe,CAAC;IAC7C,OAAO;QACL,GAAG,WAAW;QACd,OAAO;QACP,UAAS,KAAK;YACZ,SAAS,CAAA,GAAA,wCAAa,EAAE;QAC1B;QACA;YACE,OAAQ;gBACN,KAAK;oBACH,OAAO,CAAA,GAAA,oCAAS,EAAE,CAAC,IAAI,EAAE,MAAM,eAAe,CAAC,OAAO,YAAY,CAAC;gBACrE,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;oBACH,OAAO,MAAM,gBAAgB,CAAC,SAAS;gBACzC,KAAK;oBACH,OAAO;gBAET;oBACE,MAAM,IAAI,MAAM,4BAA4B;YAChD;QACF;QACA;YACE,OAAO,MAAM,kBAAkB,CAAC,SAAS;QAC3C;cACA;kBACA;QACA,YAAY,YAAY,eAAe,CAAC;IAC1C;AACF","sources":["packages/@react-stately/color/src/useColorSliderState.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 {Color, ColorSliderProps} from '@react-types/color';\nimport {normalizeColor, parseColor} from './Color';\nimport {SliderState, useSliderState} from '@react-stately/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorSliderState extends SliderState {\n /** The current color value represented by the color slider. */\n readonly value: Color,\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void,\n /** Returns the color that should be displayed in the slider instead of `value` or the optional parameter. */\n getDisplayColor(): Color,\n /** Whether the color slider is currently being dragged. */\n readonly isDragging: boolean\n}\n\n\nexport interface ColorSliderStateOptions extends ColorSliderProps {\n /** The locale to use for formatting the color channel value. */\n locale: string\n}\n\n/**\n * Provides state management for a color slider component.\n * Color sliders allow users to adjust an individual channel of a color value.\n */\nexport function useColorSliderState(props: ColorSliderStateOptions): ColorSliderState {\n let {channel, colorSpace, value, defaultValue, onChange, locale, ...otherProps} = props;\n if (value == null && defaultValue == null) {\n throw new Error('useColorSliderState requires a value or defaultValue');\n }\n\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we throw an error\n let [colorValue, setColor] = useControlledState<Color>(value as Color, defaultValue as Color, onChange);\n let color = useMemo(() => colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue, [colorValue, colorSpace]);\n let [initialValue] = useState(colorValue);\n let defaultColorValue = (defaultValue as Color) ?? initialValue;\n let defaultColor = useMemo(() => colorSpace && defaultColorValue ? defaultColorValue.toFormat(colorSpace) : defaultColorValue, [defaultColorValue, colorSpace]);\n let sliderState = useSliderState({\n ...color.getChannelRange(channel),\n ...otherProps,\n // Unused except in getThumbValueLabel, which is overridden below. null to localize the TypeScript error for ignoring.\n // @ts-ignore\n numberFormatter: null,\n value: color.getChannelValue(channel),\n defaultValue: defaultColor.getChannelValue(channel),\n onChange(v) {\n setColor(color.withChannelValue(channel, v));\n },\n onChangeEnd(v) {\n // onChange will have already been called with the right value, this is just to trigger onChangeEnd\n if (props.onChangeEnd) {\n props.onChangeEnd(color.withChannelValue(channel, v));\n }\n }\n });\n\n let {step, pageSize} = color.getChannelRange(channel);\n return {\n ...sliderState,\n value: color,\n setValue(value) {\n setColor(normalizeColor(value));\n },\n getDisplayColor() {\n switch (channel) {\n case 'hue':\n return parseColor(`hsl(${color.getChannelValue('hue')}, 100%, 50%)`);\n case 'lightness':\n case 'brightness':\n case 'saturation':\n case 'red':\n case 'green':\n case 'blue':\n return color.withChannelValue('alpha', 1);\n case 'alpha': {\n return color;\n }\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n },\n getThumbValueLabel() {\n return color.formatChannelValue(channel, locale);\n },\n step,\n pageSize,\n isDragging: sliderState.isThumbDragging(0)\n };\n}\n"],"names":[],"version":3,"file":"useColorSliderState.main.js.map"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {normalizeColor as $799cddbef784668f$export$4cde5df63f53f473, parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.mjs";
|
|
2
2
|
import {useSliderState as $1Eavr$useSliderState} from "@react-stately/slider";
|
|
3
3
|
import {useControlledState as $1Eavr$useControlledState} from "@react-stately/utils";
|
|
4
|
-
import {useMemo as $1Eavr$useMemo} from "react";
|
|
4
|
+
import {useMemo as $1Eavr$useMemo, useState as $1Eavr$useState} from "react";
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -28,6 +28,12 @@ function $25a25ac0d1624665$export$57bc203e1c9c6d44(props) {
|
|
|
28
28
|
colorValue,
|
|
29
29
|
colorSpace
|
|
30
30
|
]);
|
|
31
|
+
let [initialValue] = (0, $1Eavr$useState)(colorValue);
|
|
32
|
+
let defaultColorValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : initialValue;
|
|
33
|
+
let defaultColor = (0, $1Eavr$useMemo)(()=>colorSpace && defaultColorValue ? defaultColorValue.toFormat(colorSpace) : defaultColorValue, [
|
|
34
|
+
defaultColorValue,
|
|
35
|
+
colorSpace
|
|
36
|
+
]);
|
|
31
37
|
let sliderState = (0, $1Eavr$useSliderState)({
|
|
32
38
|
...color.getChannelRange(channel),
|
|
33
39
|
...otherProps,
|
|
@@ -35,6 +41,7 @@ function $25a25ac0d1624665$export$57bc203e1c9c6d44(props) {
|
|
|
35
41
|
// @ts-ignore
|
|
36
42
|
numberFormatter: null,
|
|
37
43
|
value: color.getChannelValue(channel),
|
|
44
|
+
defaultValue: defaultColor.getChannelValue(channel),
|
|
38
45
|
onChange (v) {
|
|
39
46
|
setColor(color.withChannelValue(channel, v));
|
|
40
47
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {normalizeColor as $799cddbef784668f$export$4cde5df63f53f473, parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.module.js";
|
|
2
2
|
import {useSliderState as $1Eavr$useSliderState} from "@react-stately/slider";
|
|
3
3
|
import {useControlledState as $1Eavr$useControlledState} from "@react-stately/utils";
|
|
4
|
-
import {useMemo as $1Eavr$useMemo} from "react";
|
|
4
|
+
import {useMemo as $1Eavr$useMemo, useState as $1Eavr$useState} from "react";
|
|
5
5
|
|
|
6
6
|
/*
|
|
7
7
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -28,6 +28,12 @@ function $25a25ac0d1624665$export$57bc203e1c9c6d44(props) {
|
|
|
28
28
|
colorValue,
|
|
29
29
|
colorSpace
|
|
30
30
|
]);
|
|
31
|
+
let [initialValue] = (0, $1Eavr$useState)(colorValue);
|
|
32
|
+
let defaultColorValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : initialValue;
|
|
33
|
+
let defaultColor = (0, $1Eavr$useMemo)(()=>colorSpace && defaultColorValue ? defaultColorValue.toFormat(colorSpace) : defaultColorValue, [
|
|
34
|
+
defaultColorValue,
|
|
35
|
+
colorSpace
|
|
36
|
+
]);
|
|
31
37
|
let sliderState = (0, $1Eavr$useSliderState)({
|
|
32
38
|
...color.getChannelRange(channel),
|
|
33
39
|
...otherProps,
|
|
@@ -35,6 +41,7 @@ function $25a25ac0d1624665$export$57bc203e1c9c6d44(props) {
|
|
|
35
41
|
// @ts-ignore
|
|
36
42
|
numberFormatter: null,
|
|
37
43
|
value: color.getChannelValue(channel),
|
|
44
|
+
defaultValue: defaultColor.getChannelValue(channel),
|
|
38
45
|
onChange (v) {
|
|
39
46
|
setColor(color.withChannelValue(channel, v));
|
|
40
47
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA6BM,SAAS,0CAAoB,KAA8B;IAChE,IAAI,WAAC,OAAO,cAAE,UAAU,SAAE,KAAK,gBAAE,YAAY,YAAE,QAAQ,UAAE,MAAM,EAAE,GAAG,YAAW,GAAG;IAClF,IAAI,SAAS,QAAQ,gBAAgB,MACnC,MAAM,IAAI,MAAM;IAGlB,IAAI,OACF,QAAQ,CAAA,GAAA,yCAAa,EAAE;IAEzB,IAAI,cACF,eAAe,CAAA,GAAA,yCAAa,EAAE;IAEhC,6HAA6H;IAC7H,IAAI,CAAC,YAAY,SAAS,GAAG,CAAA,GAAA,yBAAiB,EAAS,OAAgB,cAAuB;IAC9F,IAAI,QAAQ,CAAA,GAAA,cAAM,EAAE,IAAM,cAAc,aAAa,WAAW,QAAQ,CAAC,cAAc,YAAY;QAAC;QAAY;KAAW;IAC3H,IAAI,cAAc,CAAA,GAAA,qBAAa,EAAE;QAC/B,GAAG,MAAM,eAAe,CAAC,QAAQ;QACjC,GAAG,UAAU;QACb,sHAAsH;QACtH,aAAa;QACb,iBAAiB;QACjB,OAAO,MAAM,eAAe,CAAC;QAC7B,UAAS,CAAC;YACR,SAAS,MAAM,gBAAgB,CAAC,SAAS;QAC3C;QACA,aAAY,CAAC;YACX,mGAAmG;YACnG,IAAI,MAAM,WAAW,EACnB,MAAM,WAAW,CAAC,MAAM,gBAAgB,CAAC,SAAS;QAEtD;IACF;IAEA,IAAI,QAAC,IAAI,YAAE,QAAQ,EAAC,GAAG,MAAM,eAAe,CAAC;IAC7C,OAAO;QACL,GAAG,WAAW;QACd,OAAO;QACP,UAAS,KAAK;YACZ,SAAS,CAAA,GAAA,yCAAa,EAAE;QAC1B;QACA;YACE,OAAQ;gBACN,KAAK;oBACH,OAAO,CAAA,GAAA,wCAAS,EAAE,CAAC,IAAI,EAAE,MAAM,eAAe,CAAC,OAAO,YAAY,CAAC;gBACrE,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;oBACH,OAAO,MAAM,gBAAgB,CAAC,SAAS;gBACzC,KAAK;oBACH,OAAO;gBAET;oBACE,MAAM,IAAI,MAAM,4BAA4B;YAChD;QACF;QACA;YACE,OAAO,MAAM,kBAAkB,CAAC,SAAS;QAC3C;cACA;kBACA;QACA,YAAY,YAAY,eAAe,CAAC;IAC1C;AACF","sources":["packages/@react-stately/color/src/useColorSliderState.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 {Color, ColorSliderProps} from '@react-types/color';\nimport {normalizeColor, parseColor} from './Color';\nimport {SliderState, useSliderState} from '@react-stately/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo} from 'react';\n\nexport interface ColorSliderState extends SliderState {\n /** The current color value represented by the color slider. */\n readonly value: Color,\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void,\n /** Returns the color that should be displayed in the slider instead of `value` or the optional parameter. */\n getDisplayColor(): Color,\n /** Whether the color slider is currently being dragged. */\n readonly isDragging: boolean\n}\n\n\nexport interface ColorSliderStateOptions extends ColorSliderProps {\n /** The locale to use for formatting the color channel value. */\n locale: string\n}\n\n/**\n * Provides state management for a color slider component.\n * Color sliders allow users to adjust an individual channel of a color value.\n */\nexport function useColorSliderState(props: ColorSliderStateOptions): ColorSliderState {\n let {channel, colorSpace, value, defaultValue, onChange, locale, ...otherProps} = props;\n if (value == null && defaultValue == null) {\n throw new Error('useColorSliderState requires a value or defaultValue');\n }\n\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we throw an error\n let [colorValue, setColor] = useControlledState<Color>(value as Color, defaultValue as Color, onChange);\n let color = useMemo(() => colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue, [colorValue, colorSpace]);\n let sliderState = useSliderState({\n ...color.getChannelRange(channel),\n ...otherProps,\n // Unused except in getThumbValueLabel, which is overridden below. null to localize the TypeScript error for ignoring.\n // @ts-ignore\n numberFormatter: null,\n value: color.getChannelValue(channel),\n onChange(v) {\n setColor(color.withChannelValue(channel, v));\n },\n onChangeEnd(v) {\n // onChange will have already been called with the right value, this is just to trigger onChangeEnd\n if (props.onChangeEnd) {\n props.onChangeEnd(color.withChannelValue(channel, v));\n }\n }\n });\n\n let {step, pageSize} = color.getChannelRange(channel);\n return {\n ...sliderState,\n value: color,\n setValue(value) {\n setColor(normalizeColor(value));\n },\n getDisplayColor() {\n switch (channel) {\n case 'hue':\n return parseColor(`hsl(${color.getChannelValue('hue')}, 100%, 50%)`);\n case 'lightness':\n case 'brightness':\n case 'saturation':\n case 'red':\n case 'green':\n case 'blue':\n return color.withChannelValue('alpha', 1);\n case 'alpha': {\n return color;\n }\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n },\n getThumbValueLabel() {\n return color.formatChannelValue(channel, locale);\n },\n step,\n pageSize,\n isDragging: sliderState.isThumbDragging(0)\n };\n}\n"],"names":[],"version":3,"file":"useColorSliderState.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA6BM,SAAS,0CAAoB,KAA8B;IAChE,IAAI,WAAC,OAAO,cAAE,UAAU,SAAE,KAAK,gBAAE,YAAY,YAAE,QAAQ,UAAE,MAAM,EAAE,GAAG,YAAW,GAAG;IAClF,IAAI,SAAS,QAAQ,gBAAgB,MACnC,MAAM,IAAI,MAAM;IAGlB,IAAI,OACF,QAAQ,CAAA,GAAA,yCAAa,EAAE;IAEzB,IAAI,cACF,eAAe,CAAA,GAAA,yCAAa,EAAE;IAEhC,6HAA6H;IAC7H,IAAI,CAAC,YAAY,SAAS,GAAG,CAAA,GAAA,yBAAiB,EAAS,OAAgB,cAAuB;IAC9F,IAAI,QAAQ,CAAA,GAAA,cAAM,EAAE,IAAM,cAAc,aAAa,WAAW,QAAQ,CAAC,cAAc,YAAY;QAAC;QAAY;KAAW;IAC3H,IAAI,CAAC,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC9B,IAAI,oBAAoB,AAAC,yBAAA,0BAAA,eAA0B;IACnD,IAAI,eAAe,CAAA,GAAA,cAAM,EAAE,IAAM,cAAc,oBAAoB,kBAAkB,QAAQ,CAAC,cAAc,mBAAmB;QAAC;QAAmB;KAAW;IAC9J,IAAI,cAAc,CAAA,GAAA,qBAAa,EAAE;QAC/B,GAAG,MAAM,eAAe,CAAC,QAAQ;QACjC,GAAG,UAAU;QACb,sHAAsH;QACtH,aAAa;QACb,iBAAiB;QACjB,OAAO,MAAM,eAAe,CAAC;QAC7B,cAAc,aAAa,eAAe,CAAC;QAC3C,UAAS,CAAC;YACR,SAAS,MAAM,gBAAgB,CAAC,SAAS;QAC3C;QACA,aAAY,CAAC;YACX,mGAAmG;YACnG,IAAI,MAAM,WAAW,EACnB,MAAM,WAAW,CAAC,MAAM,gBAAgB,CAAC,SAAS;QAEtD;IACF;IAEA,IAAI,QAAC,IAAI,YAAE,QAAQ,EAAC,GAAG,MAAM,eAAe,CAAC;IAC7C,OAAO;QACL,GAAG,WAAW;QACd,OAAO;QACP,UAAS,KAAK;YACZ,SAAS,CAAA,GAAA,yCAAa,EAAE;QAC1B;QACA;YACE,OAAQ;gBACN,KAAK;oBACH,OAAO,CAAA,GAAA,wCAAS,EAAE,CAAC,IAAI,EAAE,MAAM,eAAe,CAAC,OAAO,YAAY,CAAC;gBACrE,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;gBACL,KAAK;oBACH,OAAO,MAAM,gBAAgB,CAAC,SAAS;gBACzC,KAAK;oBACH,OAAO;gBAET;oBACE,MAAM,IAAI,MAAM,4BAA4B;YAChD;QACF;QACA;YACE,OAAO,MAAM,kBAAkB,CAAC,SAAS;QAC3C;cACA;kBACA;QACA,YAAY,YAAY,eAAe,CAAC;IAC1C;AACF","sources":["packages/@react-stately/color/src/useColorSliderState.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 {Color, ColorSliderProps} from '@react-types/color';\nimport {normalizeColor, parseColor} from './Color';\nimport {SliderState, useSliderState} from '@react-stately/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\n\nexport interface ColorSliderState extends SliderState {\n /** The current color value represented by the color slider. */\n readonly value: Color,\n /** Sets the current color value. If a string is passed, it will be parsed to a Color. */\n setValue(value: string | Color): void,\n /** Returns the color that should be displayed in the slider instead of `value` or the optional parameter. */\n getDisplayColor(): Color,\n /** Whether the color slider is currently being dragged. */\n readonly isDragging: boolean\n}\n\n\nexport interface ColorSliderStateOptions extends ColorSliderProps {\n /** The locale to use for formatting the color channel value. */\n locale: string\n}\n\n/**\n * Provides state management for a color slider component.\n * Color sliders allow users to adjust an individual channel of a color value.\n */\nexport function useColorSliderState(props: ColorSliderStateOptions): ColorSliderState {\n let {channel, colorSpace, value, defaultValue, onChange, locale, ...otherProps} = props;\n if (value == null && defaultValue == null) {\n throw new Error('useColorSliderState requires a value or defaultValue');\n }\n\n if (value) {\n value = normalizeColor(value);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we throw an error\n let [colorValue, setColor] = useControlledState<Color>(value as Color, defaultValue as Color, onChange);\n let color = useMemo(() => colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue, [colorValue, colorSpace]);\n let [initialValue] = useState(colorValue);\n let defaultColorValue = (defaultValue as Color) ?? initialValue;\n let defaultColor = useMemo(() => colorSpace && defaultColorValue ? defaultColorValue.toFormat(colorSpace) : defaultColorValue, [defaultColorValue, colorSpace]);\n let sliderState = useSliderState({\n ...color.getChannelRange(channel),\n ...otherProps,\n // Unused except in getThumbValueLabel, which is overridden below. null to localize the TypeScript error for ignoring.\n // @ts-ignore\n numberFormatter: null,\n value: color.getChannelValue(channel),\n defaultValue: defaultColor.getChannelValue(channel),\n onChange(v) {\n setColor(color.withChannelValue(channel, v));\n },\n onChangeEnd(v) {\n // onChange will have already been called with the right value, this is just to trigger onChangeEnd\n if (props.onChangeEnd) {\n props.onChangeEnd(color.withChannelValue(channel, v));\n }\n }\n });\n\n let {step, pageSize} = color.getChannelRange(channel);\n return {\n ...sliderState,\n value: color,\n setValue(value) {\n setColor(normalizeColor(value));\n },\n getDisplayColor() {\n switch (channel) {\n case 'hue':\n return parseColor(`hsl(${color.getChannelValue('hue')}, 100%, 50%)`);\n case 'lightness':\n case 'brightness':\n case 'saturation':\n case 'red':\n case 'green':\n case 'blue':\n return color.withChannelValue('alpha', 1);\n case 'alpha': {\n return color;\n }\n default:\n throw new Error('Unknown color channel: ' + channel);\n }\n },\n getThumbValueLabel() {\n return color.formatChannelValue(channel, locale);\n },\n step,\n pageSize,\n isDragging: sliderState.isThumbDragging(0)\n };\n}\n"],"names":[],"version":3,"file":"useColorSliderState.module.js.map"}
|
|
@@ -60,6 +60,7 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
|
|
|
60
60
|
if (defaultValue) defaultValue = (0, $83fe1a57d631223b$exports.normalizeColor)(defaultValue);
|
|
61
61
|
// safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default
|
|
62
62
|
let [stateValue, setValueState] = (0, $5Frb2$reactstatelyutils.useControlledState)(propsValue, defaultValue, onChange);
|
|
63
|
+
let [initialValue] = (0, $5Frb2$react.useState)(stateValue);
|
|
63
64
|
let value = (0, $5Frb2$react.useMemo)(()=>{
|
|
64
65
|
let colorSpace = stateValue.getColorSpace();
|
|
65
66
|
return colorSpace === 'hsl' || colorSpace === 'hsb' ? stateValue : stateValue.toFormat('hsl');
|
|
@@ -87,6 +88,7 @@ function $9d7d8736d45f74b8$export$f4301076d9336137(props) {
|
|
|
87
88
|
}
|
|
88
89
|
return {
|
|
89
90
|
value: value,
|
|
91
|
+
defaultValue: propsValue !== undefined ? initialValue : defaultValue,
|
|
90
92
|
step: step,
|
|
91
93
|
pageStep: pageStep,
|
|
92
94
|
setValue (v) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA6CD,MAAM,sCAAgB,CAAA,GAAA,oCAAS,EAAE;AAEjC,SAAS,kCAAY,KAAa,EAAE,IAAY;IAC9C,OAAO,KAAK,KAAK,CAAC,QAAQ,QAAQ;AACpC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oCAAoC;YACpC,OAAO,gCAAU,MAAM,KAAK;iBAE5B,OAAO,kCAAY,0BAAI,MAAM,GAAG,MAAM;QAE1C;QACA,aAAY,UAAU;YACpB,IAAI,cAAc,cAAc,OAAO;YACvC,cAAc,OAAO,GAAG;YAExB,IAAI,eAAe,CAAC,cAAc,aAChC,YAAY,SAAS,OAAO;YAG9B,YAAY;QACd;oBACA;QACA;YACE,OAAO,MAAM,QAAQ,CAAC,OAAO,gBAAgB,CAAC,cAAc,KAAK,gBAAgB,CAAC,aAAa,IAAI,gBAAgB,CAAC,SAAS;QAC/H;QACA,YAAY,MAAM,UAAU,IAAI;IAClC;AACF","sources":["packages/@react-stately/color/src/useColorWheelState.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 {Color, ColorWheelProps} from '@react-types/color';\nimport {normalizeColor, parseColor} from './Color';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useRef, useState} from 'react';\n\nexport interface ColorWheelState {\n /** The current color value represented by the color wheel. */\n readonly value: Color,\n /** The default color value. */\n readonly defaultValue: Color,\n /** Sets the color value represented by the color wheel, and triggers `onChange`. */\n setValue(value: string | Color): void,\n\n /** The current value of the hue channel displayed by the color wheel. */\n readonly hue: number,\n /** Sets the hue channel of the current color value and triggers `onChange`. */\n setHue(value: number): void,\n\n /** Sets the hue channel of the current color value based on the given coordinates and radius of the color wheel, and triggers `onChange`. */\n setHueFromPoint(x: number, y: number, radius: number): void,\n /** Returns the coordinates of the thumb relative to the center point of the color wheel. */\n getThumbPosition(radius: number): {x: number, y: number},\n\n /** Increments the hue by the given amount (defaults to 1). */\n increment(stepSize?: number): void,\n /** Decrements the hue by the given amount (defaults to 1). */\n decrement(stepSize?: number): void,\n\n /** Whether the color wheel is currently being dragged. */\n readonly isDragging: boolean,\n /** Sets whether the color wheel is being dragged. */\n setDragging(value: boolean): void,\n /** Returns the color that should be displayed in the color wheel instead of `value`. */\n getDisplayColor(): Color,\n /** The step value of the hue channel, used when incrementing and decrementing. */\n step: number,\n /** The page step value of the hue channel, used when incrementing and decrementing. */\n pageStep: number,\n\n /** Whether the color wheel is disabled. */\n readonly isDisabled: boolean\n}\n\nconst DEFAULT_COLOR = parseColor('hsl(0, 100%, 50%)');\n\nfunction roundToStep(value: number, step: number): number {\n return Math.round(value / step) * step;\n}\n\nfunction mod(n: number, m: number) {\n return ((n % m) + m) % m;\n}\n\nfunction roundDown(v: number) {\n let r = Math.floor(v);\n if (r === v) {\n return v - 1;\n } else {\n return r;\n }\n}\n\nfunction degToRad(deg: number) {\n return deg * Math.PI / 180;\n}\n\nfunction radToDeg(rad: number) {\n return rad * 180 / Math.PI;\n}\n\n// 0deg = 3 o'clock. increases clockwise\nfunction angleToCartesian(angle: number, radius: number): {x: number, y: number} {\n let rad = degToRad(360 - angle + 90);\n let x = Math.sin(rad) * (radius);\n let y = Math.cos(rad) * (radius);\n return {x, y};\n}\n\nfunction cartesianToAngle(x: number, y: number, radius: number): number {\n let deg = radToDeg(Math.atan2(y / radius, x / radius));\n return (deg + 360) % 360;\n}\n\n/**\n * Provides state management for a color wheel component.\n * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.\n */\nexport function useColorWheelState(props: ColorWheelProps): ColorWheelState {\n let {value: propsValue, defaultValue, onChange, onChangeEnd} = props;\n\n if (!propsValue && !defaultValue) {\n defaultValue = DEFAULT_COLOR;\n }\n if (propsValue) {\n propsValue = normalizeColor(propsValue);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default\n let [stateValue, setValueState] = useControlledState<Color>(propsValue as Color, defaultValue as Color, onChange);\n let [initialValue] = useState(stateValue);\n let value = useMemo(() => {\n let colorSpace = stateValue.getColorSpace();\n return colorSpace === 'hsl' || colorSpace === 'hsb' ? stateValue : stateValue.toFormat('hsl');\n }, [stateValue]);\n let valueRef = useRef(value);\n let setValue = (value: Color) => {\n valueRef.current = value;\n setValueState(value);\n };\n\n let channelRange = value.getChannelRange('hue');\n let {minValue: minValueX, maxValue: maxValueX, step: step, pageSize: pageStep} = channelRange;\n let [isDragging, setDragging] = useState(false);\n let isDraggingRef = useRef(false);\n\n let hue = value.getChannelValue('hue');\n function setHue(v: number) {\n if (v > 360) {\n // Make sure you can always get back to 0.\n v = 0;\n }\n v = roundToStep(mod(v, 360), step);\n if (hue !== v) {\n let color = value.withChannelValue('hue', v);\n setValue(color);\n }\n }\n\n return {\n value,\n defaultValue: propsValue !== undefined ? initialValue : defaultValue as Color,\n step,\n pageStep,\n setValue(v) {\n let color = normalizeColor(v);\n setValue(color);\n },\n hue,\n setHue,\n setHueFromPoint(x, y, radius) {\n setHue(cartesianToAngle(x, y, radius));\n },\n getThumbPosition(radius) {\n return angleToCartesian(value.getChannelValue('hue'), radius);\n },\n increment(stepSize = 1) {\n let s = Math.max(stepSize, step);\n let newValue = hue + s;\n if (newValue >= maxValueX) {\n // Make sure you can always get back to 0.\n newValue = minValueX;\n }\n setHue(roundToStep(mod(newValue, 360), s));\n },\n decrement(stepSize = 1) {\n let s = Math.max(stepSize, step);\n if (hue === 0) {\n // We can't just subtract step because this might be the case:\n // |(previous step) - 0| < step size\n setHue(roundDown(360 / s) * s);\n } else {\n setHue(roundToStep(mod(hue - s, 360), s));\n }\n },\n setDragging(isDragging) {\n let wasDragging = isDraggingRef.current;\n isDraggingRef.current = isDragging;\n\n if (onChangeEnd && !isDragging && wasDragging) {\n onChangeEnd(valueRef.current);\n }\n\n setDragging(isDragging);\n },\n isDragging,\n getDisplayColor() {\n return value.toFormat('hsl').withChannelValue('saturation', 100).withChannelValue('lightness', 50).withChannelValue('alpha', 1);\n },\n isDisabled: props.isDisabled || false\n };\n}\n"],"names":[],"version":3,"file":"useColorWheelState.main.js.map"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {normalizeColor as $799cddbef784668f$export$4cde5df63f53f473, parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.mjs";
|
|
2
2
|
import {useControlledState as $d4Pfi$useControlledState} from "@react-stately/utils";
|
|
3
|
-
import {
|
|
3
|
+
import {useState as $d4Pfi$useState, useMemo as $d4Pfi$useMemo, useRef as $d4Pfi$useRef} from "react";
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -54,6 +54,7 @@ function $ee4262c74a467b07$export$f4301076d9336137(props) {
|
|
|
54
54
|
if (defaultValue) defaultValue = (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue);
|
|
55
55
|
// safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default
|
|
56
56
|
let [stateValue, setValueState] = (0, $d4Pfi$useControlledState)(propsValue, defaultValue, onChange);
|
|
57
|
+
let [initialValue] = (0, $d4Pfi$useState)(stateValue);
|
|
57
58
|
let value = (0, $d4Pfi$useMemo)(()=>{
|
|
58
59
|
let colorSpace = stateValue.getColorSpace();
|
|
59
60
|
return colorSpace === 'hsl' || colorSpace === 'hsb' ? stateValue : stateValue.toFormat('hsl');
|
|
@@ -81,6 +82,7 @@ function $ee4262c74a467b07$export$f4301076d9336137(props) {
|
|
|
81
82
|
}
|
|
82
83
|
return {
|
|
83
84
|
value: value,
|
|
85
|
+
defaultValue: propsValue !== undefined ? initialValue : defaultValue,
|
|
84
86
|
step: step,
|
|
85
87
|
pageStep: pageStep,
|
|
86
88
|
setValue (v) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {normalizeColor as $799cddbef784668f$export$4cde5df63f53f473, parseColor as $799cddbef784668f$export$6e865ea70d7724f} from "./Color.module.js";
|
|
2
2
|
import {useControlledState as $d4Pfi$useControlledState} from "@react-stately/utils";
|
|
3
|
-
import {
|
|
3
|
+
import {useState as $d4Pfi$useState, useMemo as $d4Pfi$useMemo, useRef as $d4Pfi$useRef} from "react";
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -54,6 +54,7 @@ function $ee4262c74a467b07$export$f4301076d9336137(props) {
|
|
|
54
54
|
if (defaultValue) defaultValue = (0, $799cddbef784668f$export$4cde5df63f53f473)(defaultValue);
|
|
55
55
|
// safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default
|
|
56
56
|
let [stateValue, setValueState] = (0, $d4Pfi$useControlledState)(propsValue, defaultValue, onChange);
|
|
57
|
+
let [initialValue] = (0, $d4Pfi$useState)(stateValue);
|
|
57
58
|
let value = (0, $d4Pfi$useMemo)(()=>{
|
|
58
59
|
let colorSpace = stateValue.getColorSpace();
|
|
59
60
|
return colorSpace === 'hsl' || colorSpace === 'hsb' ? stateValue : stateValue.toFormat('hsl');
|
|
@@ -81,6 +82,7 @@ function $ee4262c74a467b07$export$f4301076d9336137(props) {
|
|
|
81
82
|
}
|
|
82
83
|
return {
|
|
83
84
|
value: value,
|
|
85
|
+
defaultValue: propsValue !== undefined ? initialValue : defaultValue,
|
|
84
86
|
step: step,
|
|
85
87
|
pageStep: pageStep,
|
|
86
88
|
setValue (v) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA6CD,MAAM,sCAAgB,CAAA,GAAA,wCAAS,EAAE;AAEjC,SAAS,kCAAY,KAAa,EAAE,IAAY;IAC9C,OAAO,KAAK,KAAK,CAAC,QAAQ,QAAQ;AACpC;AAEA,SAAS,0BAAI,CAAS,EAAE,CAAS;IAC/B,OAAO,AAAC,C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AI,MAAM,GAAG,MAAM;QAE1C;QACA,aAAY,UAAU;YACpB,IAAI,cAAc,cAAc,OAAO;YACvC,cAAc,OAAO,GAAG;YAExB,IAAI,eAAe,CAAC,cAAc,aAChC,YAAY,SAAS,OAAO;YAG9B,YAAY;QACd;oBACA;QACA;YACE,OAAO,MAAM,QAAQ,CAAC,OAAO,gBAAgB,CAAC,cAAc,KAAK,gBAAgB,CAAC,aAAa,IAAI,gBAAgB,CAAC,SAAS;QAC/H;QACA,YAAY,MAAM,UAAU,IAAI;IAClC;AACF","sources":["packages/@react-stately/color/src/useColorWheelState.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 {Color, ColorWheelProps} from '@react-types/color';\nimport {normalizeColor, parseColor} from './Color';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useRef, useState} from 'react';\n\nexport interface ColorWheelState {\n /** The current color value represented by the color wheel. */\n readonly value: Color,\n /** The default color value. */\n readonly defaultValue: Color,\n /** Sets the color value represented by the color wheel, and triggers `onChange`. */\n setValue(value: string | Color): void,\n\n /** The current value of the hue channel displayed by the color wheel. */\n readonly hue: number,\n /** Sets the hue channel of the current color value and triggers `onChange`. */\n setHue(value: number): void,\n\n /** Sets the hue channel of the current color value based on the given coordinates and radius of the color wheel, and triggers `onChange`. */\n setHueFromPoint(x: number, y: number, radius: number): void,\n /** Returns the coordinates of the thumb relative to the center point of the color wheel. */\n getThumbPosition(radius: number): {x: number, y: number},\n\n /** Increments the hue by the given amount (defaults to 1). */\n increment(stepSize?: number): void,\n /** Decrements the hue by the given amount (defaults to 1). */\n decrement(stepSize?: number): void,\n\n /** Whether the color wheel is currently being dragged. */\n readonly isDragging: boolean,\n /** Sets whether the color wheel is being dragged. */\n setDragging(value: boolean): void,\n /** Returns the color that should be displayed in the color wheel instead of `value`. */\n getDisplayColor(): Color,\n /** The step value of the hue channel, used when incrementing and decrementing. */\n step: number,\n /** The page step value of the hue channel, used when incrementing and decrementing. */\n pageStep: number,\n\n /** Whether the color wheel is disabled. */\n readonly isDisabled: boolean\n}\n\nconst DEFAULT_COLOR = parseColor('hsl(0, 100%, 50%)');\n\nfunction roundToStep(value: number, step: number): number {\n return Math.round(value / step) * step;\n}\n\nfunction mod(n: number, m: number) {\n return ((n % m) + m) % m;\n}\n\nfunction roundDown(v: number) {\n let r = Math.floor(v);\n if (r === v) {\n return v - 1;\n } else {\n return r;\n }\n}\n\nfunction degToRad(deg: number) {\n return deg * Math.PI / 180;\n}\n\nfunction radToDeg(rad: number) {\n return rad * 180 / Math.PI;\n}\n\n// 0deg = 3 o'clock. increases clockwise\nfunction angleToCartesian(angle: number, radius: number): {x: number, y: number} {\n let rad = degToRad(360 - angle + 90);\n let x = Math.sin(rad) * (radius);\n let y = Math.cos(rad) * (radius);\n return {x, y};\n}\n\nfunction cartesianToAngle(x: number, y: number, radius: number): number {\n let deg = radToDeg(Math.atan2(y / radius, x / radius));\n return (deg + 360) % 360;\n}\n\n/**\n * Provides state management for a color wheel component.\n * Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.\n */\nexport function useColorWheelState(props: ColorWheelProps): ColorWheelState {\n let {value: propsValue, defaultValue, onChange, onChangeEnd} = props;\n\n if (!propsValue && !defaultValue) {\n defaultValue = DEFAULT_COLOR;\n }\n if (propsValue) {\n propsValue = normalizeColor(propsValue);\n }\n if (defaultValue) {\n defaultValue = normalizeColor(defaultValue);\n }\n\n // safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default\n let [stateValue, setValueState] = useControlledState<Color>(propsValue as Color, defaultValue as Color, onChange);\n let [initialValue] = useState(stateValue);\n let value = useMemo(() => {\n let colorSpace = stateValue.getColorSpace();\n return colorSpace === 'hsl' || colorSpace === 'hsb' ? stateValue : stateValue.toFormat('hsl');\n }, [stateValue]);\n let valueRef = useRef(value);\n let setValue = (value: Color) => {\n valueRef.current = value;\n setValueState(value);\n };\n\n let channelRange = value.getChannelRange('hue');\n let {minValue: minValueX, maxValue: maxValueX, step: step, pageSize: pageStep} = channelRange;\n let [isDragging, setDragging] = useState(false);\n let isDraggingRef = useRef(false);\n\n let hue = value.getChannelValue('hue');\n function setHue(v: number) {\n if (v > 360) {\n // Make sure you can always get back to 0.\n v = 0;\n }\n v = roundToStep(mod(v, 360), step);\n if (hue !== v) {\n let color = value.withChannelValue('hue', v);\n setValue(color);\n }\n }\n\n return {\n value,\n defaultValue: propsValue !== undefined ? initialValue : defaultValue as Color,\n step,\n pageStep,\n setValue(v) {\n let color = normalizeColor(v);\n setValue(color);\n },\n hue,\n setHue,\n setHueFromPoint(x, y, radius) {\n setHue(cartesianToAngle(x, y, radius));\n },\n getThumbPosition(radius) {\n return angleToCartesian(value.getChannelValue('hue'), radius);\n },\n increment(stepSize = 1) {\n let s = Math.max(stepSize, step);\n let newValue = hue + s;\n if (newValue >= maxValueX) {\n // Make sure you can always get back to 0.\n newValue = minValueX;\n }\n setHue(roundToStep(mod(newValue, 360), s));\n },\n decrement(stepSize = 1) {\n let s = Math.max(stepSize, step);\n if (hue === 0) {\n // We can't just subtract step because this might be the case:\n // |(previous step) - 0| < step size\n setHue(roundDown(360 / s) * s);\n } else {\n setHue(roundToStep(mod(hue - s, 360), s));\n }\n },\n setDragging(isDragging) {\n let wasDragging = isDraggingRef.current;\n isDraggingRef.current = isDragging;\n\n if (onChangeEnd && !isDragging && wasDragging) {\n onChangeEnd(valueRef.current);\n }\n\n setDragging(isDragging);\n },\n isDragging,\n getDisplayColor() {\n return value.toFormat('hsl').withChannelValue('saturation', 100).withChannelValue('lightness', 50).withChannelValue('alpha', 1);\n },\n isDisabled: props.isDisabled || false\n };\n}\n"],"names":[],"version":3,"file":"useColorWheelState.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/color",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@internationalized/number": "^3.6.
|
|
29
|
+
"@internationalized/number": "^3.6.4",
|
|
30
30
|
"@internationalized/string": "^3.2.7",
|
|
31
|
-
"@react-stately/form": "^3.
|
|
32
|
-
"@react-stately/numberfield": "^3.
|
|
33
|
-
"@react-stately/slider": "^3.
|
|
34
|
-
"@react-stately/utils": "^3.10.
|
|
35
|
-
"@react-types/color": "^3.0
|
|
36
|
-
"@react-types/shared": "^3.
|
|
31
|
+
"@react-stately/form": "^3.2.0",
|
|
32
|
+
"@react-stately/numberfield": "^3.10.0",
|
|
33
|
+
"@react-stately/slider": "^3.7.0",
|
|
34
|
+
"@react-stately/utils": "^3.10.8",
|
|
35
|
+
"@react-types/color": "^3.1.0",
|
|
36
|
+
"@react-types/shared": "^3.31.0",
|
|
37
37
|
"@swc/helpers": "^0.5.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "8b9348ff255e018b2dd9b27e2a45507cadfa1d35"
|
|
46
46
|
}
|
package/src/useColorAreaState.ts
CHANGED
|
@@ -18,6 +18,8 @@ import {useMemo, useRef, useState} from 'react';
|
|
|
18
18
|
export interface ColorAreaState {
|
|
19
19
|
/** The current color value displayed by the color area. */
|
|
20
20
|
readonly value: Color,
|
|
21
|
+
/** The default value of the color area. */
|
|
22
|
+
readonly defaultValue: Color,
|
|
21
23
|
/** Sets the current color value. If a string is passed, it will be parsed to a Color. */
|
|
22
24
|
setValue(value: string | Color): void,
|
|
23
25
|
|
|
@@ -94,6 +96,7 @@ export function useColorAreaState(props: ColorAreaProps): ColorAreaState {
|
|
|
94
96
|
|
|
95
97
|
// safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default
|
|
96
98
|
let [colorValue, setColorState] = useControlledState<Color>(value as Color, defaultValue as Color, onChange);
|
|
99
|
+
let [initialValue] = useState(colorValue);
|
|
97
100
|
let color = useMemo(() => colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue, [colorValue, colorSpace]);
|
|
98
101
|
let valueRef = useRef(color);
|
|
99
102
|
let setColor = (color: Color) => {
|
|
@@ -138,6 +141,7 @@ export function useColorAreaState(props: ColorAreaProps): ColorAreaState {
|
|
|
138
141
|
xChannelPageStep: pageSizeX,
|
|
139
142
|
yChannelPageStep: pageSizeY,
|
|
140
143
|
value: color,
|
|
144
|
+
defaultValue: value !== undefined ? initialValue : defaultValue as Color,
|
|
141
145
|
setValue(value) {
|
|
142
146
|
setColor(normalizeColor(value));
|
|
143
147
|
},
|
|
@@ -2,7 +2,7 @@ import {Color, ColorChannel, ColorFieldProps, ColorSpace} from '@react-types/col
|
|
|
2
2
|
import {NumberFieldState, useNumberFieldState} from '@react-stately/numberfield';
|
|
3
3
|
import {useColor} from './useColor';
|
|
4
4
|
import {useControlledState} from '@react-stately/utils';
|
|
5
|
-
import {useMemo} from 'react';
|
|
5
|
+
import {useMemo, useState} from 'react';
|
|
6
6
|
|
|
7
7
|
export interface ColorChannelFieldProps extends ColorFieldProps {
|
|
8
8
|
colorSpace?: ColorSpace,
|
|
@@ -14,7 +14,12 @@ export interface ColorChannelFieldStateOptions extends ColorChannelFieldProps {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface ColorChannelFieldState extends NumberFieldState {
|
|
17
|
-
|
|
17
|
+
/** The current value of the field. */
|
|
18
|
+
colorValue: Color,
|
|
19
|
+
/** The default value of the field. */
|
|
20
|
+
defaultColorValue: Color | null,
|
|
21
|
+
/** Sets the color value of the field. */
|
|
22
|
+
setColorValue(value: Color | null): void
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
/**
|
|
@@ -23,14 +28,13 @@ export interface ColorChannelFieldState extends NumberFieldState {
|
|
|
23
28
|
*/
|
|
24
29
|
export function useColorChannelFieldState(props: ColorChannelFieldStateOptions): ColorChannelFieldState {
|
|
25
30
|
let {channel, colorSpace, locale} = props;
|
|
26
|
-
let black = useColor('#000')!;
|
|
27
31
|
let initialValue = useColor(props.value);
|
|
28
32
|
let initialDefaultValue = useColor(props.defaultValue);
|
|
29
33
|
let [colorValue, setColor] = useControlledState(initialValue, initialDefaultValue ?? null, props.onChange);
|
|
30
|
-
let color =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
let color = useConvertColor(colorValue, colorSpace);
|
|
35
|
+
let [initialColorValue] = useState(colorValue);
|
|
36
|
+
let defaultColorValue = initialDefaultValue ?? initialColorValue;
|
|
37
|
+
let defaultColor = useConvertColor(defaultColorValue, colorSpace);
|
|
34
38
|
let value = color.getChannelValue(channel);
|
|
35
39
|
let range = color.getChannelRange(channel);
|
|
36
40
|
let formatOptions = useMemo(() => color.getChannelFormatOptions(channel), [color, channel]);
|
|
@@ -39,6 +43,7 @@ export function useColorChannelFieldState(props: ColorChannelFieldStateOptions):
|
|
|
39
43
|
let numberFieldState = useNumberFieldState({
|
|
40
44
|
locale,
|
|
41
45
|
value: colorValue === null ? NaN : value / multiplier,
|
|
46
|
+
defaultValue: defaultColorValue === null ? NaN : defaultColor.getChannelValue(channel) / multiplier,
|
|
42
47
|
onChange: (v) => {
|
|
43
48
|
if (!Number.isNaN(v)) {
|
|
44
49
|
setColor(color.withChannelValue(channel, v * multiplier));
|
|
@@ -54,6 +59,16 @@ export function useColorChannelFieldState(props: ColorChannelFieldStateOptions):
|
|
|
54
59
|
|
|
55
60
|
return {
|
|
56
61
|
...numberFieldState,
|
|
57
|
-
colorValue: color
|
|
62
|
+
colorValue: color,
|
|
63
|
+
defaultColorValue,
|
|
64
|
+
setColorValue: setColor
|
|
58
65
|
};
|
|
59
66
|
}
|
|
67
|
+
|
|
68
|
+
function useConvertColor(colorValue: Color | null, colorSpace: ColorSpace | null | undefined) {
|
|
69
|
+
let black = useColor('#000')!;
|
|
70
|
+
return useMemo(() => {
|
|
71
|
+
let nonNullColorValue = colorValue || black;
|
|
72
|
+
return colorSpace && nonNullColorValue ? nonNullColorValue.toFormat(colorSpace) : nonNullColorValue;
|
|
73
|
+
}, [black, colorValue, colorSpace]);
|
|
74
|
+
}
|
|
@@ -28,6 +28,10 @@ export interface ColorFieldState extends FormValidationState {
|
|
|
28
28
|
* Updated based on the `inputValue` as the user types.
|
|
29
29
|
*/
|
|
30
30
|
readonly colorValue: Color | null,
|
|
31
|
+
/** The default value of the color field. */
|
|
32
|
+
readonly defaultColorValue: Color | null,
|
|
33
|
+
/** Sets the color value of the field. */
|
|
34
|
+
setColorValue(value: Color | null): void,
|
|
31
35
|
/** Sets the current text value of the input. */
|
|
32
36
|
setInputValue(value: string): void,
|
|
33
37
|
/**
|
|
@@ -70,9 +74,9 @@ export function useColorFieldState(
|
|
|
70
74
|
} = props;
|
|
71
75
|
let {step} = MIN_COLOR.getChannelRange('red');
|
|
72
76
|
|
|
73
|
-
let initialValue = useColor(value);
|
|
74
77
|
let initialDefaultValue = useColor(defaultValue);
|
|
75
|
-
let [colorValue, setColorValue] = useControlledState<Color | null>(
|
|
78
|
+
let [colorValue, setColorValue] = useControlledState<Color | null>(useColor(value), initialDefaultValue!, onChange);
|
|
79
|
+
let [initialValue] = useState(colorValue);
|
|
76
80
|
let [inputValue, setInputValue] = useState(() => (value || defaultValue) && colorValue ? colorValue.toString('hex') : '');
|
|
77
81
|
|
|
78
82
|
let validation = useFormValidationState({
|
|
@@ -132,6 +136,7 @@ export function useColorFieldState(
|
|
|
132
136
|
newColorValue = colorValue.toString('hex');
|
|
133
137
|
}
|
|
134
138
|
setInputValue(newColorValue);
|
|
139
|
+
validation.commitValidation();
|
|
135
140
|
};
|
|
136
141
|
|
|
137
142
|
let increment = () => {
|
|
@@ -167,6 +172,8 @@ export function useColorFieldState(
|
|
|
167
172
|
...validation,
|
|
168
173
|
validate,
|
|
169
174
|
colorValue,
|
|
175
|
+
defaultColorValue: initialDefaultValue ?? initialValue,
|
|
176
|
+
setColorValue,
|
|
170
177
|
inputValue,
|
|
171
178
|
setInputValue,
|
|
172
179
|
commit,
|
|
@@ -14,7 +14,7 @@ import {Color, ColorSliderProps} from '@react-types/color';
|
|
|
14
14
|
import {normalizeColor, parseColor} from './Color';
|
|
15
15
|
import {SliderState, useSliderState} from '@react-stately/slider';
|
|
16
16
|
import {useControlledState} from '@react-stately/utils';
|
|
17
|
-
import {useMemo} from 'react';
|
|
17
|
+
import {useMemo, useState} from 'react';
|
|
18
18
|
|
|
19
19
|
export interface ColorSliderState extends SliderState {
|
|
20
20
|
/** The current color value represented by the color slider. */
|
|
@@ -52,6 +52,9 @@ export function useColorSliderState(props: ColorSliderStateOptions): ColorSlider
|
|
|
52
52
|
// safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we throw an error
|
|
53
53
|
let [colorValue, setColor] = useControlledState<Color>(value as Color, defaultValue as Color, onChange);
|
|
54
54
|
let color = useMemo(() => colorSpace && colorValue ? colorValue.toFormat(colorSpace) : colorValue, [colorValue, colorSpace]);
|
|
55
|
+
let [initialValue] = useState(colorValue);
|
|
56
|
+
let defaultColorValue = (defaultValue as Color) ?? initialValue;
|
|
57
|
+
let defaultColor = useMemo(() => colorSpace && defaultColorValue ? defaultColorValue.toFormat(colorSpace) : defaultColorValue, [defaultColorValue, colorSpace]);
|
|
55
58
|
let sliderState = useSliderState({
|
|
56
59
|
...color.getChannelRange(channel),
|
|
57
60
|
...otherProps,
|
|
@@ -59,6 +62,7 @@ export function useColorSliderState(props: ColorSliderStateOptions): ColorSlider
|
|
|
59
62
|
// @ts-ignore
|
|
60
63
|
numberFormatter: null,
|
|
61
64
|
value: color.getChannelValue(channel),
|
|
65
|
+
defaultValue: defaultColor.getChannelValue(channel),
|
|
62
66
|
onChange(v) {
|
|
63
67
|
setColor(color.withChannelValue(channel, v));
|
|
64
68
|
},
|
|
@@ -18,6 +18,8 @@ import {useMemo, useRef, useState} from 'react';
|
|
|
18
18
|
export interface ColorWheelState {
|
|
19
19
|
/** The current color value represented by the color wheel. */
|
|
20
20
|
readonly value: Color,
|
|
21
|
+
/** The default color value. */
|
|
22
|
+
readonly defaultValue: Color,
|
|
21
23
|
/** Sets the color value represented by the color wheel, and triggers `onChange`. */
|
|
22
24
|
setValue(value: string | Color): void,
|
|
23
25
|
|
|
@@ -110,6 +112,7 @@ export function useColorWheelState(props: ColorWheelProps): ColorWheelState {
|
|
|
110
112
|
|
|
111
113
|
// safe to cast value and defaultValue to Color, one of them will always be defined because if neither are, we assign a default
|
|
112
114
|
let [stateValue, setValueState] = useControlledState<Color>(propsValue as Color, defaultValue as Color, onChange);
|
|
115
|
+
let [initialValue] = useState(stateValue);
|
|
113
116
|
let value = useMemo(() => {
|
|
114
117
|
let colorSpace = stateValue.getColorSpace();
|
|
115
118
|
return colorSpace === 'hsl' || colorSpace === 'hsb' ? stateValue : stateValue.toFormat('hsl');
|
|
@@ -140,6 +143,7 @@ export function useColorWheelState(props: ColorWheelProps): ColorWheelState {
|
|
|
140
143
|
|
|
141
144
|
return {
|
|
142
145
|
value,
|
|
146
|
+
defaultValue: propsValue !== undefined ? initialValue : defaultValue as Color,
|
|
143
147
|
step,
|
|
144
148
|
pageStep,
|
|
145
149
|
setValue(v) {
|