@yamada-ui/color-picker 2.0.0-next-20240614140233 → 2.0.0-next-20240615233332
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/alpha-slider.js +14 -25
- package/dist/alpha-slider.js.map +1 -1
- package/dist/alpha-slider.mjs +2 -2
- package/dist/{chunk-OTNMOPLH.mjs → chunk-27BXTC5D.mjs} +4 -4
- package/dist/{chunk-C7IY5KVP.mjs → chunk-2K4SHOHA.mjs} +2 -2
- package/dist/{chunk-DDHDVGOQ.mjs → chunk-7L64OYDQ.mjs} +2 -2
- package/dist/{chunk-UBSVLXYF.mjs → chunk-ABDJB4WV.mjs} +3 -4
- package/dist/{chunk-UBSVLXYF.mjs.map → chunk-ABDJB4WV.mjs.map} +1 -1
- package/dist/{chunk-KKQ3MOXJ.mjs → chunk-KKUDFHCJ.mjs} +15 -26
- package/dist/{chunk-KKQ3MOXJ.mjs.map → chunk-KKUDFHCJ.mjs.map} +1 -1
- package/dist/{chunk-HEBLEXJG.mjs → chunk-MPWT2DSW.mjs} +6 -6
- package/dist/{chunk-6CYIIW6Z.mjs → chunk-MXH5UN5E.mjs} +2 -2
- package/dist/{chunk-X7R6FWCD.mjs → chunk-PCXNTEF4.mjs} +2 -2
- package/dist/{chunk-SBN7FEOE.mjs → chunk-PVPQQB6L.mjs} +16 -31
- package/dist/{chunk-SBN7FEOE.mjs.map → chunk-PVPQQB6L.mjs.map} +1 -1
- package/dist/{chunk-YE3Z2X2L.mjs → chunk-RWVTJOMP.mjs} +4 -4
- package/dist/{chunk-5QT7SRA4.mjs → chunk-UZQ2UORY.mjs} +18 -35
- package/dist/{chunk-5QT7SRA4.mjs.map → chunk-UZQ2UORY.mjs.map} +1 -1
- package/dist/{chunk-R4DLOKLT.mjs → chunk-WRHKYN3W.mjs} +15 -26
- package/dist/{chunk-R4DLOKLT.mjs.map → chunk-WRHKYN3W.mjs.map} +1 -1
- package/dist/{chunk-NJEVZQVF.mjs → chunk-YPW3ZJM7.mjs} +5 -6
- package/dist/{chunk-NJEVZQVF.mjs.map → chunk-YPW3ZJM7.mjs.map} +1 -1
- package/dist/{chunk-LHNR2F5V.mjs → chunk-ZHZRZ3XZ.mjs} +2 -2
- package/dist/color-picker.js +62 -118
- package/dist/color-picker.js.map +1 -1
- package/dist/color-picker.mjs +14 -14
- package/dist/color-selector-body.js +15 -27
- package/dist/color-selector-body.js.map +1 -1
- package/dist/color-selector-body.mjs +7 -7
- package/dist/color-selector-channels.js +1 -2
- package/dist/color-selector-channels.js.map +1 -1
- package/dist/color-selector-channels.mjs +2 -2
- package/dist/color-selector-eye-dropper.mjs +2 -2
- package/dist/color-selector-sliders.js +15 -27
- package/dist/color-selector-sliders.js.map +1 -1
- package/dist/color-selector-sliders.mjs +5 -5
- package/dist/color-selector-swatches.mjs +2 -2
- package/dist/color-selector.js +47 -88
- package/dist/color-selector.js.map +1 -1
- package/dist/color-selector.mjs +12 -12
- package/dist/hue-slider.js +14 -25
- package/dist/hue-slider.js.map +1 -1
- package/dist/hue-slider.mjs +2 -2
- package/dist/index.js +62 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -14
- package/dist/saturation-slider.js +14 -25
- package/dist/saturation-slider.js.map +1 -1
- package/dist/saturation-slider.mjs +2 -2
- package/dist/use-color-picker.js +15 -30
- package/dist/use-color-picker.js.map +1 -1
- package/dist/use-color-picker.mjs +1 -1
- package/dist/use-color-selector.js +17 -34
- package/dist/use-color-selector.js.map +1 -1
- package/dist/use-color-selector.mjs +1 -1
- package/dist/use-color-slider.js +14 -25
- package/dist/use-color-slider.js.map +1 -1
- package/dist/use-color-slider.mjs +1 -1
- package/dist/use-saturation-slider.js +14 -25
- package/dist/use-saturation-slider.js.map +1 -1
- package/dist/use-saturation-slider.mjs +1 -1
- package/package.json +15 -15
- /package/dist/{chunk-OTNMOPLH.mjs.map → chunk-27BXTC5D.mjs.map} +0 -0
- /package/dist/{chunk-C7IY5KVP.mjs.map → chunk-2K4SHOHA.mjs.map} +0 -0
- /package/dist/{chunk-DDHDVGOQ.mjs.map → chunk-7L64OYDQ.mjs.map} +0 -0
- /package/dist/{chunk-HEBLEXJG.mjs.map → chunk-MPWT2DSW.mjs.map} +0 -0
- /package/dist/{chunk-6CYIIW6Z.mjs.map → chunk-MXH5UN5E.mjs.map} +0 -0
- /package/dist/{chunk-X7R6FWCD.mjs.map → chunk-PCXNTEF4.mjs.map} +0 -0
- /package/dist/{chunk-YE3Z2X2L.mjs.map → chunk-RWVTJOMP.mjs.map} +0 -0
- /package/dist/{chunk-LHNR2F5V.mjs.map → chunk-ZHZRZ3XZ.mjs.map} +0 -0
package/dist/hue-slider.js
CHANGED
@@ -39,8 +39,7 @@ var useColorSlider = ({
|
|
39
39
|
focusThumbOnChange = true,
|
40
40
|
...props
|
41
41
|
}) => {
|
42
|
-
if (!focusThumbOnChange)
|
43
|
-
props.isReadOnly = true;
|
42
|
+
if (!focusThumbOnChange) props.isReadOnly = true;
|
44
43
|
let {
|
45
44
|
id,
|
46
45
|
name,
|
@@ -87,16 +86,14 @@ var useColorSlider = ({
|
|
87
86
|
const getValueFromPointer = (0, import_react.useCallback)(
|
88
87
|
(ev) => {
|
89
88
|
var _a, _b;
|
90
|
-
if (!trackRef.current)
|
91
|
-
return;
|
89
|
+
if (!trackRef.current) return;
|
92
90
|
const { min: min2, max: max2, step: step2 } = latestRef.current;
|
93
91
|
latestRef.current.eventSource = "pointer";
|
94
92
|
const { left, width } = trackRef.current.getBoundingClientRect();
|
95
93
|
const { clientX } = (_b = (_a = ev.touches) == null ? void 0 : _a[0]) != null ? _b : ev;
|
96
94
|
let percent = (clientX - left) / width;
|
97
95
|
let nextValue = (0, import_utils.percentToValue)(percent, min2, max2);
|
98
|
-
if (step2)
|
99
|
-
nextValue = parseFloat((0, import_utils.roundNumberToStep)(nextValue, min2, step2));
|
96
|
+
if (step2) nextValue = parseFloat((0, import_utils.roundNumberToStep)(nextValue, min2, step2));
|
100
97
|
nextValue = (0, import_utils.clampNumber)(nextValue, min2, max2);
|
101
98
|
return nextValue;
|
102
99
|
},
|
@@ -105,22 +102,19 @@ var useColorSlider = ({
|
|
105
102
|
const setValueFromPointer = (ev) => {
|
106
103
|
const { value: value2 } = latestRef.current;
|
107
104
|
const nextValue = getValueFromPointer(ev);
|
108
|
-
if (nextValue != null && nextValue !== value2)
|
109
|
-
setValue(nextValue);
|
105
|
+
if (nextValue != null && nextValue !== value2) setValue(nextValue);
|
110
106
|
};
|
111
107
|
const focusThumb = (0, import_react.useCallback)(() => {
|
112
108
|
const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
|
113
|
-
if (focusThumbOnChange2)
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
});
|
109
|
+
if (focusThumbOnChange2) setTimeout(() => {
|
110
|
+
var _a;
|
111
|
+
return (_a = thumbRef.current) == null ? void 0 : _a.focus();
|
112
|
+
});
|
118
113
|
}, [latestRef]);
|
119
114
|
const constrain = (0, import_react.useCallback)(
|
120
115
|
(value2) => {
|
121
116
|
const { isInteractive: isInteractive2, min: min2, max: max2 } = latestRef.current;
|
122
|
-
if (!isInteractive2)
|
123
|
-
return;
|
117
|
+
if (!isInteractive2) return;
|
124
118
|
value2 = parseFloat((0, import_utils.roundNumberToStep)(value2, min2, oneStep));
|
125
119
|
value2 = (0, import_utils.clampNumber)(value2, min2, max2);
|
126
120
|
setValue(value2);
|
@@ -149,8 +143,7 @@ var useColorSlider = ({
|
|
149
143
|
End: () => constrain(max2)
|
150
144
|
};
|
151
145
|
const action = actions[ev.key];
|
152
|
-
if (!action)
|
153
|
-
return;
|
146
|
+
if (!action) return;
|
154
147
|
ev.preventDefault();
|
155
148
|
ev.stopPropagation();
|
156
149
|
action(ev);
|
@@ -161,8 +154,7 @@ var useColorSlider = ({
|
|
161
154
|
(0, import_use_pan_event.usePanEvent)(containerRef, {
|
162
155
|
onSessionStart: (ev) => {
|
163
156
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
164
|
-
if (!isInteractive2)
|
165
|
-
return;
|
157
|
+
if (!isInteractive2) return;
|
166
158
|
setDragging(true);
|
167
159
|
focusThumb();
|
168
160
|
setValueFromPointer(ev);
|
@@ -170,22 +162,19 @@ var useColorSlider = ({
|
|
170
162
|
},
|
171
163
|
onSessionEnd: () => {
|
172
164
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
173
|
-
if (!isInteractive2)
|
174
|
-
return;
|
165
|
+
if (!isInteractive2) return;
|
175
166
|
setDragging(false);
|
176
167
|
onChangeEnd(value2);
|
177
168
|
},
|
178
169
|
onMove: (ev) => {
|
179
170
|
const { isInteractive: isInteractive2 } = latestRef.current;
|
180
|
-
if (!isInteractive2)
|
181
|
-
return;
|
171
|
+
if (!isInteractive2) return;
|
182
172
|
setValueFromPointer(ev);
|
183
173
|
}
|
184
174
|
});
|
185
175
|
(0, import_utils.useUpdateEffect)(() => {
|
186
176
|
const { eventSource, value: value2 } = latestRef.current;
|
187
|
-
if (eventSource === "keyboard")
|
188
|
-
onChangeEnd(value2);
|
177
|
+
if (eventSource === "keyboard") onChangeEnd(value2);
|
189
178
|
}, [value, onChangeEnd]);
|
190
179
|
const getContainerProps = (0, import_react.useCallback)(
|
191
180
|
(props2 = {}, ref = null) => {
|
package/dist/hue-slider.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/hue-slider.tsx","../src/use-color-slider.ts"],"sourcesContent":["import {\n ui,\n forwardRef,\n omitThemeProps,\n useMultiComponentStyle,\n} from \"@yamada-ui/core\"\nimport type { CSSUIObject, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport { cx } from \"@yamada-ui/utils\"\nimport type { UseColorSliderProps } from \"./use-color-slider\"\nimport { useColorSlider } from \"./use-color-slider\"\n\nconst defaultOverlays = (\n min: number,\n max: number,\n withShadow: boolean,\n): HTMLUIProps<\"div\">[] => {\n let overlays: HTMLUIProps<\"div\">[] = [\n {\n bgGradient: `linear(to-r, ${[...Array(7)]\n .map(\n (_, index) =>\n `hsl(${Math.round(min + ((max - min) / 6) * index)}, 100%, 50%)`,\n )\n .join(\", \")})`,\n },\n ]\n\n if (withShadow)\n overlays = [\n ...overlays,\n {\n boxShadow: `rgba(0, 0, 0, .1) 0 0 0 1px inset, rgb(0, 0, 0, .15) 0 0 4px inset`,\n },\n ]\n\n return overlays\n}\n\ntype HueSliderOptions = {\n /**\n * The minimum allowed value of the slider. Cannot be greater than max.\n *\n * @default 0\n */\n min?: number\n /**\n * The maximum allowed value of the slider. Cannot be less than min.\n *\n * @default 360\n */\n max?: number\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 1\n */\n step?: number\n /**\n * If `true`, the slider has an inner `box-shadow`.\n *\n * @default true\n */\n withShadow?: boolean\n /**\n * Props for slider input element.\n */\n inputProps?: HTMLUIProps<\"input\">\n /**\n * Props for slider track element.\n */\n trackProps?: HTMLUIProps<\"div\">\n /**\n * Props for slider thumb element.\n */\n thumbProps?: HTMLUIProps<\"div\">\n /**\n * The overlay used for the slider.\n */\n overlays?: HTMLUIProps<\"div\">[]\n}\n\n/**\n * `HueSlider` is a component used to allow the user to select a color hue.\n *\n * @see Docs https://yamada-ui.com/components/forms/hue-slider\n */\nexport type HueSliderProps = ThemeProps<\"HueSlider\"> &\n Partial<UseColorSliderProps> &\n HueSliderOptions\n\nexport const HueSlider = forwardRef<HueSliderProps, \"input\">((props, ref) => {\n const [styles, mergedProps] = useMultiComponentStyle(\"HueSlider\", props)\n const {\n className,\n inputProps,\n trackProps,\n thumbProps,\n min = 0,\n max = 360,\n withShadow = true,\n overlays = defaultOverlays(min, max, withShadow),\n __css,\n ...computedProps\n } = omitThemeProps(mergedProps)\n const { getContainerProps, getTrackProps, getInputProps, getThumbProps } =\n useColorSlider({ min, max, step: 1, ...computedProps })\n\n const css: CSSUIObject = {\n ...styles.container,\n ...__css,\n }\n\n return (\n <ui.div\n className={cx(\"ui-hue-slider\", className)}\n __css={css}\n {...getContainerProps()}\n >\n <ui.input {...getInputProps(inputProps, ref)} />\n\n {overlays.map((props, index) => (\n <ui.div\n key={index}\n className=\"ui-hue-slider__overlay\"\n __css={{\n ...styles.overlay,\n }}\n {...props}\n />\n ))}\n\n <ui.div\n className=\"ui-hue-slider__track\"\n __css={{ ...styles.track }}\n {...getTrackProps(trackProps)}\n >\n <ui.div\n className=\"ui-hue-slider__thumb\"\n __css={{ ...styles.thumb }}\n {...getThumbProps(thumbProps)}\n />\n </ui.div>\n </ui.div>\n )\n})\n","import type { CSSUIProps, HTMLUIProps, UIPropGetter } from \"@yamada-ui/core\"\nimport {\n useFormControlProps,\n type FormControlOptions,\n formControlProperties,\n getFormControlProperties,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useLatestRef } from \"@yamada-ui/use-latest-ref\"\nimport { usePanEvent } from \"@yamada-ui/use-pan-event\"\nimport { useSize } from \"@yamada-ui/use-size\"\nimport {\n omitObject,\n dataAttr,\n handlerAll,\n mergeRefs,\n valueToPercent,\n clampNumber,\n useCallbackRef,\n roundNumberToStep,\n useUpdateEffect,\n percentToValue,\n pickObject,\n} from \"@yamada-ui/utils\"\nimport type { CSSProperties, KeyboardEvent, KeyboardEventHandler } from \"react\"\nimport { useCallback, useRef, useState } from \"react\"\n\ntype UseColorSliderOptions = {\n /**\n * The base `id` to use for the slider.\n */\n id?: string\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The value of the slider.\n */\n value?: number\n /**\n * The initial value of the slider.\n */\n defaultValue?: number\n /**\n * The minimum allowed value of the slider. Cannot be greater than max.\n */\n min: number\n /**\n * The maximum allowed value of the slider. Cannot be less than min.\n */\n max: number\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 1\n */\n step?: number\n /**\n * Function called whenever the slider value changes.\n */\n onChange?: (value: number) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: number) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: number) => void\n /**\n * If `false`, the slider handle will not capture focus when value changes.\n *\n * @default true\n */\n focusThumbOnChange?: boolean\n /**\n * The CSS `background` property. Used in `background` of thumb element.\n */\n thumbColor?: CSSUIProps[\"bg\"]\n}\n\nexport type UseColorSliderProps = Omit<\n HTMLUIProps<\"div\">,\n \"defaultValue\" | \"onChange\"\n> &\n UseColorSliderOptions &\n FormControlOptions\n\nexport const useColorSlider = ({\n focusThumbOnChange = true,\n ...props\n}: UseColorSliderProps) => {\n if (!focusThumbOnChange) props.isReadOnly = true\n\n let {\n id,\n name,\n value: valueProp,\n defaultValue,\n min = 0,\n max,\n step = 1,\n onChange: onChangeProp,\n onChangeStart: onChangeStartProp,\n onChangeEnd: onChangeEndProp,\n thumbColor,\n required,\n disabled,\n readOnly,\n ...rest\n } = useFormControlProps(props)\n\n const onChangeStart = useCallbackRef(onChangeStartProp)\n const onChangeEnd = useCallbackRef(onChangeEndProp)\n\n const [computedValue, setValue] = useControllableState({\n value: valueProp,\n defaultValue: defaultValue ?? min + (max - min) / 2,\n onChange: onChangeProp,\n })\n const value = clampNumber(computedValue, min, max)\n const thumbPercent = valueToPercent(value, min, max)\n const [isDragging, setDragging] = useState(false)\n const isInteractive = !(disabled || readOnly)\n\n const oneStep = step || (max - min) / 100\n const tenStep = (max - min) / 10\n\n const containerRef = useRef<HTMLElement>(null)\n const trackRef = useRef<HTMLElement>(null)\n const thumbRef = useRef<HTMLElement>(null)\n const latestRef = useLatestRef({\n value,\n min,\n max,\n step,\n isInteractive,\n eventSource: null as \"pointer\" | \"keyboard\" | null,\n focusThumbOnChange,\n })\n\n const thumbSize = useSize(thumbRef)\n\n const getValueFromPointer = useCallback(\n (ev: any) => {\n if (!trackRef.current) return\n\n const { min, max, step } = latestRef.current\n\n latestRef.current.eventSource = \"pointer\"\n\n const { left, width } = trackRef.current.getBoundingClientRect()\n const { clientX } = ev.touches?.[0] ?? ev\n\n let percent = (clientX - left) / width\n\n let nextValue = percentToValue(percent, min, max)\n\n if (step) nextValue = parseFloat(roundNumberToStep(nextValue, min, step))\n\n nextValue = clampNumber(nextValue, min, max)\n\n return nextValue\n },\n [latestRef],\n )\n\n const setValueFromPointer = (ev: MouseEvent | TouchEvent | PointerEvent) => {\n const { value } = latestRef.current\n const nextValue = getValueFromPointer(ev)\n\n if (nextValue != null && nextValue !== value) setValue(nextValue)\n }\n\n const focusThumb = useCallback(() => {\n const { focusThumbOnChange } = latestRef.current\n\n if (focusThumbOnChange) setTimeout(() => thumbRef.current?.focus())\n }, [latestRef])\n\n const constrain = useCallback(\n (value: number) => {\n const { isInteractive, min, max } = latestRef.current\n\n if (!isInteractive) return\n\n value = parseFloat(roundNumberToStep(value, min, oneStep))\n value = clampNumber(value, min, max)\n\n setValue(value)\n },\n [setValue, latestRef, oneStep],\n )\n\n const stepUp = useCallback(\n (step = oneStep) => constrain(value + step),\n [constrain, value, oneStep],\n )\n\n const stepDown = useCallback(\n (step = oneStep) => constrain(value - step),\n [constrain, value, oneStep],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n const { min, max } = latestRef.current\n\n const actions: Record<string, KeyboardEventHandler> = {\n ArrowRight: () => stepUp(),\n ArrowUp: () => stepUp(),\n ArrowLeft: () => stepDown(),\n ArrowDown: () => stepDown(),\n PageUp: () => stepUp(tenStep),\n PageDown: () => stepDown(tenStep),\n Home: () => constrain(min),\n End: () => constrain(max),\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n ev.stopPropagation()\n\n action(ev)\n\n latestRef.current.eventSource = \"keyboard\"\n },\n [constrain, latestRef, stepDown, stepUp, tenStep],\n )\n\n usePanEvent(containerRef, {\n onSessionStart: (ev) => {\n const { isInteractive, value } = latestRef.current\n\n if (!isInteractive) return\n\n setDragging(true)\n focusThumb()\n setValueFromPointer(ev)\n onChangeStart(value)\n },\n onSessionEnd: () => {\n const { isInteractive, value } = latestRef.current\n\n if (!isInteractive) return\n\n setDragging(false)\n onChangeEnd(value)\n },\n onMove: (ev) => {\n const { isInteractive } = latestRef.current\n\n if (!isInteractive) return\n\n setValueFromPointer(ev)\n },\n })\n\n useUpdateEffect(() => {\n const { eventSource, value } = latestRef.current\n\n if (eventSource === \"keyboard\") onChangeEnd(value)\n }, [value, onChangeEnd])\n\n const getContainerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => {\n const { width: w } = thumbSize ?? { width: 0 }\n\n const style: CSSProperties = {\n ...props.style,\n ...rest.style,\n paddingInline: `${w / 2}px`,\n }\n\n return {\n ...props,\n ...omitObject(rest, [\"aria-readonly\"]),\n ref: mergeRefs(ref, containerRef),\n tabIndex: -1,\n style,\n }\n },\n [rest, thumbSize],\n )\n\n const getInputProps: UIPropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...pickObject(rest, formControlProperties),\n ...props,\n id,\n ref,\n type: \"hidden\",\n name,\n value,\n required,\n disabled,\n readOnly,\n }),\n [disabled, id, name, readOnly, required, rest, value],\n )\n\n const getTrackProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ...pickObject(\n rest,\n getFormControlProperties({ omit: [\"aria-readonly\"] }),\n ),\n ...props,\n ref: mergeRefs(ref, trackRef),\n }),\n [rest],\n )\n\n const getThumbProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => {\n const n = thumbPercent\n const { width: w } = thumbSize ?? { width: 0 }\n\n const style: CSSProperties = {\n ...props.style,\n position: \"absolute\",\n userSelect: \"none\",\n touchAction: \"none\",\n left: `calc(${n}% - ${w / 2}px)`,\n }\n\n return {\n \"aria-label\": \"Slider thumb\",\n bg: thumbColor ?? `hsl(${value}, 100%, 50%)`,\n ...pickObject(rest, formControlProperties),\n ...props,\n ref: mergeRefs(ref, thumbRef),\n tabIndex: isInteractive && focusThumbOnChange ? 0 : undefined,\n role: \"slider\",\n \"aria-valuenow\": value,\n \"aria-valuemin\": min,\n \"aria-valuemax\": max,\n \"data-active\": dataAttr(isDragging && focusThumbOnChange),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onFocus: handlerAll(props.onFocus, rest.onFocus),\n onBlur: handlerAll(props.onBlur, rest.onBlur),\n style,\n }\n },\n [\n thumbColor,\n focusThumbOnChange,\n isDragging,\n isInteractive,\n min,\n max,\n onKeyDown,\n rest,\n thumbPercent,\n thumbSize,\n value,\n ],\n )\n\n return {\n value,\n getContainerProps,\n getTrackProps,\n getInputProps,\n getThumbProps,\n }\n}\n\nexport type UseColorSliderReturn = ReturnType<typeof useColorSlider>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAKO;AAEP,IAAAA,gBAAmB;;;ACNnB,0BAKO;AACP,oCAAqC;AACrC,4BAA6B;AAC7B,2BAA4B;AAC5B,sBAAwB;AACxB,mBAYO;AAEP,mBAA8C;AAiEvC,IAAM,iBAAiB,CAAC;AAAA,EAC7B,qBAAqB;AAAA,EACrB,GAAG;AACL,MAA2B;AACzB,MAAI,CAAC;AAAoB,UAAM,aAAa;AAE5C,MAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA,OAAO;AAAA,IACP,UAAU;AAAA,IACV,eAAe;AAAA,IACf,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,QAAI,yCAAoB,KAAK;AAE7B,QAAM,oBAAgB,6BAAe,iBAAiB;AACtD,QAAM,kBAAc,6BAAe,eAAe;AAElD,QAAM,CAAC,eAAe,QAAQ,QAAI,oDAAqB;AAAA,IACrD,OAAO;AAAA,IACP,cAAc,sCAAgB,OAAO,MAAM,OAAO;AAAA,IAClD,UAAU;AAAA,EACZ,CAAC;AACD,QAAM,YAAQ,0BAAY,eAAe,KAAK,GAAG;AACjD,QAAM,mBAAe,6BAAe,OAAO,KAAK,GAAG;AACnD,QAAM,CAAC,YAAY,WAAW,QAAI,uBAAS,KAAK;AAChD,QAAM,gBAAgB,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ACC,eAAW,kBAAG,iBAAiB,SAAS;AAAA,MACxC,OAAO;AAAA,MACN,GAAG,kBAAkB;AAAA,MAEtB;AAAA,oDAAC,eAAG,OAAH,EAAU,GAAG,cAAc,YAAY,GAAG,GAAG;AAAA,QAE7C,SAAS,IAAI,CAACC,QAAO,UACpB;AAAA,UAAC,eAAG;AAAA,UAAH;AAAA,YAEC,WAAU;AAAA,YACV,OAAO;AAAA,cACL,GAAG,OAAO;AAAA,YACZ;AAAA,YACC,GAAGA;AAAA;AAAA,UALC;AAAA,QAMP,CACD;AAAA,QAED;AAAA,UAAC,eAAG;AAAA,UAAH;AAAA,YACC,WAAU;AAAA,YACV,OAAO,EAAE,GAAG,OAAO,MAAM;AAAA,YACxB,GAAG,cAAc,UAAU;AAAA,YAE5B;AAAA,cAAC,eAAG;AAAA,cAAH;AAAA,gBACC,WAAU;AAAA,gBACV,OAAO,EAAE,GAAG,OAAO,MAAM;AAAA,gBACxB,GAAG,cAAc,UAAU;AAAA;AAAA,YAC9B;AAAA;AAAA,QACF;AAAA;AAAA;AAAA,EACF;AAEJ,CAAC;","names":["import_utils","min","max","step","value","focusThumbOnChange","isInteractive","props","props"]}
|
1
|
+
{"version":3,"sources":["../src/hue-slider.tsx","../src/use-color-slider.ts"],"sourcesContent":["import {\n ui,\n forwardRef,\n omitThemeProps,\n useMultiComponentStyle,\n} from \"@yamada-ui/core\"\nimport type { CSSUIObject, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport { cx } from \"@yamada-ui/utils\"\nimport type { UseColorSliderProps } from \"./use-color-slider\"\nimport { useColorSlider } from \"./use-color-slider\"\n\nconst defaultOverlays = (\n min: number,\n max: number,\n withShadow: boolean,\n): HTMLUIProps<\"div\">[] => {\n let overlays: HTMLUIProps<\"div\">[] = [\n {\n bgGradient: `linear(to-r, ${[...Array(7)]\n .map(\n (_, index) =>\n `hsl(${Math.round(min + ((max - min) / 6) * index)}, 100%, 50%)`,\n )\n .join(\", \")})`,\n },\n ]\n\n if (withShadow)\n overlays = [\n ...overlays,\n {\n boxShadow: `rgba(0, 0, 0, .1) 0 0 0 1px inset, rgb(0, 0, 0, .15) 0 0 4px inset`,\n },\n ]\n\n return overlays\n}\n\ntype HueSliderOptions = {\n /**\n * The minimum allowed value of the slider. Cannot be greater than max.\n *\n * @default 0\n */\n min?: number\n /**\n * The maximum allowed value of the slider. Cannot be less than min.\n *\n * @default 360\n */\n max?: number\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 1\n */\n step?: number\n /**\n * If `true`, the slider has an inner `box-shadow`.\n *\n * @default true\n */\n withShadow?: boolean\n /**\n * Props for slider input element.\n */\n inputProps?: HTMLUIProps<\"input\">\n /**\n * Props for slider track element.\n */\n trackProps?: HTMLUIProps<\"div\">\n /**\n * Props for slider thumb element.\n */\n thumbProps?: HTMLUIProps<\"div\">\n /**\n * The overlay used for the slider.\n */\n overlays?: HTMLUIProps<\"div\">[]\n}\n\n/**\n * `HueSlider` is a component used to allow the user to select a color hue.\n *\n * @see Docs https://yamada-ui.com/components/forms/hue-slider\n */\nexport type HueSliderProps = ThemeProps<\"HueSlider\"> &\n Partial<UseColorSliderProps> &\n HueSliderOptions\n\nexport const HueSlider = forwardRef<HueSliderProps, \"input\">((props, ref) => {\n const [styles, mergedProps] = useMultiComponentStyle(\"HueSlider\", props)\n const {\n className,\n inputProps,\n trackProps,\n thumbProps,\n min = 0,\n max = 360,\n withShadow = true,\n overlays = defaultOverlays(min, max, withShadow),\n __css,\n ...computedProps\n } = omitThemeProps(mergedProps)\n const { getContainerProps, getTrackProps, getInputProps, getThumbProps } =\n useColorSlider({ min, max, step: 1, ...computedProps })\n\n const css: CSSUIObject = {\n ...styles.container,\n ...__css,\n }\n\n return (\n <ui.div\n className={cx(\"ui-hue-slider\", className)}\n __css={css}\n {...getContainerProps()}\n >\n <ui.input {...getInputProps(inputProps, ref)} />\n\n {overlays.map((props, index) => (\n <ui.div\n key={index}\n className=\"ui-hue-slider__overlay\"\n __css={{\n ...styles.overlay,\n }}\n {...props}\n />\n ))}\n\n <ui.div\n className=\"ui-hue-slider__track\"\n __css={{ ...styles.track }}\n {...getTrackProps(trackProps)}\n >\n <ui.div\n className=\"ui-hue-slider__thumb\"\n __css={{ ...styles.thumb }}\n {...getThumbProps(thumbProps)}\n />\n </ui.div>\n </ui.div>\n )\n})\n","import type { CSSUIProps, HTMLUIProps, UIPropGetter } from \"@yamada-ui/core\"\nimport {\n useFormControlProps,\n type FormControlOptions,\n formControlProperties,\n getFormControlProperties,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useLatestRef } from \"@yamada-ui/use-latest-ref\"\nimport { usePanEvent } from \"@yamada-ui/use-pan-event\"\nimport { useSize } from \"@yamada-ui/use-size\"\nimport {\n omitObject,\n dataAttr,\n handlerAll,\n mergeRefs,\n valueToPercent,\n clampNumber,\n useCallbackRef,\n roundNumberToStep,\n useUpdateEffect,\n percentToValue,\n pickObject,\n} from \"@yamada-ui/utils\"\nimport type { CSSProperties, KeyboardEvent, KeyboardEventHandler } from \"react\"\nimport { useCallback, useRef, useState } from \"react\"\n\ntype UseColorSliderOptions = {\n /**\n * The base `id` to use for the slider.\n */\n id?: string\n /**\n * The name attribute of the hidden `input` field.\n * This is particularly useful in forms.\n */\n name?: string\n /**\n * The value of the slider.\n */\n value?: number\n /**\n * The initial value of the slider.\n */\n defaultValue?: number\n /**\n * The minimum allowed value of the slider. Cannot be greater than max.\n */\n min: number\n /**\n * The maximum allowed value of the slider. Cannot be less than min.\n */\n max: number\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 1\n */\n step?: number\n /**\n * Function called whenever the slider value changes.\n */\n onChange?: (value: number) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: number) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: number) => void\n /**\n * If `false`, the slider handle will not capture focus when value changes.\n *\n * @default true\n */\n focusThumbOnChange?: boolean\n /**\n * The CSS `background` property. Used in `background` of thumb element.\n */\n thumbColor?: CSSUIProps[\"bg\"]\n}\n\nexport type UseColorSliderProps = Omit<\n HTMLUIProps<\"div\">,\n \"defaultValue\" | \"onChange\"\n> &\n UseColorSliderOptions &\n FormControlOptions\n\nexport const useColorSlider = ({\n focusThumbOnChange = true,\n ...props\n}: UseColorSliderProps) => {\n if (!focusThumbOnChange) props.isReadOnly = true\n\n let {\n id,\n name,\n value: valueProp,\n defaultValue,\n min = 0,\n max,\n step = 1,\n onChange: onChangeProp,\n onChangeStart: onChangeStartProp,\n onChangeEnd: onChangeEndProp,\n thumbColor,\n required,\n disabled,\n readOnly,\n ...rest\n } = useFormControlProps(props)\n\n const onChangeStart = useCallbackRef(onChangeStartProp)\n const onChangeEnd = useCallbackRef(onChangeEndProp)\n\n const [computedValue, setValue] = useControllableState({\n value: valueProp,\n defaultValue: defaultValue ?? min + (max - min) / 2,\n onChange: onChangeProp,\n })\n const value = clampNumber(computedValue, min, max)\n const thumbPercent = valueToPercent(value, min, max)\n const [isDragging, setDragging] = useState(false)\n const isInteractive = !(disabled || readOnly)\n\n const oneStep = step || (max - min) / 100\n const tenStep = (max - min) / 10\n\n const containerRef = useRef<HTMLElement>(null)\n const trackRef = useRef<HTMLElement>(null)\n const thumbRef = useRef<HTMLElement>(null)\n const latestRef = useLatestRef({\n value,\n min,\n max,\n step,\n isInteractive,\n eventSource: null as \"pointer\" | \"keyboard\" | null,\n focusThumbOnChange,\n })\n\n const thumbSize = useSize(thumbRef)\n\n const getValueFromPointer = useCallback(\n (ev: any) => {\n if (!trackRef.current) return\n\n const { min, max, step } = latestRef.current\n\n latestRef.current.eventSource = \"pointer\"\n\n const { left, width } = trackRef.current.getBoundingClientRect()\n const { clientX } = ev.touches?.[0] ?? ev\n\n let percent = (clientX - left) / width\n\n let nextValue = percentToValue(percent, min, max)\n\n if (step) nextValue = parseFloat(roundNumberToStep(nextValue, min, step))\n\n nextValue = clampNumber(nextValue, min, max)\n\n return nextValue\n },\n [latestRef],\n )\n\n const setValueFromPointer = (ev: MouseEvent | TouchEvent | PointerEvent) => {\n const { value } = latestRef.current\n const nextValue = getValueFromPointer(ev)\n\n if (nextValue != null && nextValue !== value) setValue(nextValue)\n }\n\n const focusThumb = useCallback(() => {\n const { focusThumbOnChange } = latestRef.current\n\n if (focusThumbOnChange) setTimeout(() => thumbRef.current?.focus())\n }, [latestRef])\n\n const constrain = useCallback(\n (value: number) => {\n const { isInteractive, min, max } = latestRef.current\n\n if (!isInteractive) return\n\n value = parseFloat(roundNumberToStep(value, min, oneStep))\n value = clampNumber(value, min, max)\n\n setValue(value)\n },\n [setValue, latestRef, oneStep],\n )\n\n const stepUp = useCallback(\n (step = oneStep) => constrain(value + step),\n [constrain, value, oneStep],\n )\n\n const stepDown = useCallback(\n (step = oneStep) => constrain(value - step),\n [constrain, value, oneStep],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n const { min, max } = latestRef.current\n\n const actions: Record<string, KeyboardEventHandler> = {\n ArrowRight: () => stepUp(),\n ArrowUp: () => stepUp(),\n ArrowLeft: () => stepDown(),\n ArrowDown: () => stepDown(),\n PageUp: () => stepUp(tenStep),\n PageDown: () => stepDown(tenStep),\n Home: () => constrain(min),\n End: () => constrain(max),\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n ev.stopPropagation()\n\n action(ev)\n\n latestRef.current.eventSource = \"keyboard\"\n },\n [constrain, latestRef, stepDown, stepUp, tenStep],\n )\n\n usePanEvent(containerRef, {\n onSessionStart: (ev) => {\n const { isInteractive, value } = latestRef.current\n\n if (!isInteractive) return\n\n setDragging(true)\n focusThumb()\n setValueFromPointer(ev)\n onChangeStart(value)\n },\n onSessionEnd: () => {\n const { isInteractive, value } = latestRef.current\n\n if (!isInteractive) return\n\n setDragging(false)\n onChangeEnd(value)\n },\n onMove: (ev) => {\n const { isInteractive } = latestRef.current\n\n if (!isInteractive) return\n\n setValueFromPointer(ev)\n },\n })\n\n useUpdateEffect(() => {\n const { eventSource, value } = latestRef.current\n\n if (eventSource === \"keyboard\") onChangeEnd(value)\n }, [value, onChangeEnd])\n\n const getContainerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => {\n const { width: w } = thumbSize ?? { width: 0 }\n\n const style: CSSProperties = {\n ...props.style,\n ...rest.style,\n paddingInline: `${w / 2}px`,\n }\n\n return {\n ...props,\n ...omitObject(rest, [\"aria-readonly\"]),\n ref: mergeRefs(ref, containerRef),\n tabIndex: -1,\n style,\n }\n },\n [rest, thumbSize],\n )\n\n const getInputProps: UIPropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => ({\n ...pickObject(rest, formControlProperties),\n ...props,\n id,\n ref,\n type: \"hidden\",\n name,\n value,\n required,\n disabled,\n readOnly,\n }),\n [disabled, id, name, readOnly, required, rest, value],\n )\n\n const getTrackProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ...pickObject(\n rest,\n getFormControlProperties({ omit: [\"aria-readonly\"] }),\n ),\n ...props,\n ref: mergeRefs(ref, trackRef),\n }),\n [rest],\n )\n\n const getThumbProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => {\n const n = thumbPercent\n const { width: w } = thumbSize ?? { width: 0 }\n\n const style: CSSProperties = {\n ...props.style,\n position: \"absolute\",\n userSelect: \"none\",\n touchAction: \"none\",\n left: `calc(${n}% - ${w / 2}px)`,\n }\n\n return {\n \"aria-label\": \"Slider thumb\",\n bg: thumbColor ?? `hsl(${value}, 100%, 50%)`,\n ...pickObject(rest, formControlProperties),\n ...props,\n ref: mergeRefs(ref, thumbRef),\n tabIndex: isInteractive && focusThumbOnChange ? 0 : undefined,\n role: \"slider\",\n \"aria-valuenow\": value,\n \"aria-valuemin\": min,\n \"aria-valuemax\": max,\n \"data-active\": dataAttr(isDragging && focusThumbOnChange),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown),\n onFocus: handlerAll(props.onFocus, rest.onFocus),\n onBlur: handlerAll(props.onBlur, rest.onBlur),\n style,\n }\n },\n [\n thumbColor,\n focusThumbOnChange,\n isDragging,\n isInteractive,\n min,\n max,\n onKeyDown,\n rest,\n thumbPercent,\n thumbSize,\n value,\n ],\n )\n\n return {\n value,\n getContainerProps,\n getTrackProps,\n getInputProps,\n getThumbProps,\n }\n}\n\nexport type UseColorSliderReturn = ReturnType<typeof useColorSlider>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAKO;AAEP,IAAAA,gBAAmB;;;ACNnB,0BAKO;AACP,oCAAqC;AACrC,4BAA6B;AAC7B,2BAA4B;AAC5B,sBAAwB;AACxB,mBAYO;AAEP,mBAA8C;AAiEvC,IAAM,iBAAiB,CAAC;AAAA,EAC7B,qBAAqB;AAAA,EACrB,GAAG;AACL,MAA2B;AACzB,MAAI,CAAC,mBAAoB,OAAM,aAAa;AAE5C,MAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA,OAAO;AAAA,IACP,UAAU;AAAA,IACV,eAAe;AAAA,IACf,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,QAAI,yCAAoB,KAAK;AAE7B,QAAM,oBAAgB,6BAAe,iBAAiB;AACtD,QAAM,kBAAc,6BAAe,eAAe;AAElD,QAAM,CAAC,eAAe,QAAQ,QAAI,oDAAqB;AAAA,IACrD,OAAO;AAAA,IACP,cAAc,sCAAgB,OAAO,MAAM,OAAO;AAAA,IAClD,UAAU;AAAA,EACZ,CAAC;AACD,QAAM,YAAQ,0BAAY,eAAe,KAAK,GAAG;AACjD,QAAM,mBAAe,6BAAe,OAAO,KAAK,GAAG;AACnD,QAAM,CAAC,YAAY,WAAW,QAAI,uBAAS,KAAK;AAChD,QAAM,gBAAgB,EAAE,YAAY;AAEpC,QAAM,UAAU,SAAS,MAAM,OAAO;AAC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,MACN,GAAG,kBAAkB;AAAA,MAEtB;AAAA,oDAAC,eAAG,OAAH,EAAU,GAAG,cAAc,YAAY,GAAG,GAAG;AAAA,QAE7C,SAAS,IAAI,CAACC,QAAO,UACpB;AAAA,UAAC,eAAG;AAAA,UAAH;AAAA,YAEC,WAAU;AAAA,YACV,OAAO;AAAA,cACL,GAAG,OAAO;AAAA,YACZ;AAAA,YACC,GAAGA;AAAA;AAAA,UALC;AAAA,QAMP,CACD;AAAA,QAED;AAAA,UAAC,eAAG;AAAA,UAAH;AAAA,YACC,WAAU;AAAA,YACV,OAAO,EAAE,GAAG,OAAO,MAAM;AAAA,YACxB,GAAG,cAAc,UAAU;AAAA,YAE5B;AAAA,cAAC,eAAG;AAAA,cAAH;AAAA,gBACC,WAAU;AAAA,gBACV,OAAO,EAAE,GAAG,OAAO,MAAM;AAAA,gBACxB,GAAG,cAAc,UAAU;AAAA;AAAA,YAC9B;AAAA;AAAA,QACF;AAAA;AAAA;AAAA,EACF;AAEJ,CAAC;","names":["import_utils","min","max","step","value","focusThumbOnChange","isInteractive","props","props"]}
|
package/dist/hue-slider.mjs
CHANGED
package/dist/index.js
CHANGED
@@ -53,21 +53,16 @@ var import_react = require("react");
|
|
53
53
|
var convertHsla = (value, fallback) => {
|
54
54
|
var _a;
|
55
55
|
let [h, s, l, a] = (_a = (0, import_utils.parseToHsla)(value, fallback)) != null ? _a : [0, 0, 1, 1];
|
56
|
-
if (a > 1)
|
57
|
-
a = 1;
|
56
|
+
if (a > 1) a = 1;
|
58
57
|
return { h, s, l, a };
|
59
58
|
};
|
60
59
|
var convertRgba = (value, fallback) => {
|
61
60
|
var _a;
|
62
61
|
let [r, g, b, a] = (_a = (0, import_utils.parseToRgba)(value, fallback)) != null ? _a : [255, 255, 255, 1];
|
63
|
-
if (r > 255)
|
64
|
-
|
65
|
-
if (
|
66
|
-
|
67
|
-
if (b > 255)
|
68
|
-
b = 255;
|
69
|
-
if (a > 1)
|
70
|
-
a = 1;
|
62
|
+
if (r > 255) r = 255;
|
63
|
+
if (g > 255) g = 255;
|
64
|
+
if (b > 255) b = 255;
|
65
|
+
if (a > 1) a = 1;
|
71
66
|
return { r, g, b, a };
|
72
67
|
};
|
73
68
|
var convertHsva = (value, fallback) => {
|
@@ -187,8 +182,7 @@ var useColorSelector = ({
|
|
187
182
|
isDraggingRef.current = true;
|
188
183
|
const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
|
189
184
|
const nextValue = (0, import_utils.hsvTo)([h2, s2, v2, a2], fallbackValue)(formatRef.current);
|
190
|
-
if (nextValue)
|
191
|
-
onChangeStartRef(nextValue);
|
185
|
+
if (nextValue) onChangeStartRef(nextValue);
|
192
186
|
},
|
193
187
|
[formatRef, onChangeStartRef, fallbackValue, parsedValue]
|
194
188
|
);
|
@@ -205,18 +199,15 @@ var useColorSelector = ({
|
|
205
199
|
const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
|
206
200
|
nextValue = (0, import_utils.hsvTo)([h2, s2, v2, a2], fallbackValue)(formatRef.current);
|
207
201
|
}
|
208
|
-
if (nextValue)
|
209
|
-
onChangeEndRef(nextValue);
|
202
|
+
if (nextValue) onChangeEndRef(nextValue);
|
210
203
|
},
|
211
204
|
[formatRef, onChangeEndRef, fallbackValue, parsedValue]
|
212
205
|
);
|
213
206
|
const onChannelChange = (0, import_react.useCallback)(
|
214
207
|
(ev, space) => {
|
215
208
|
let n = Math.floor(parseFloat(ev.target.value));
|
216
|
-
if (isNaN(n))
|
217
|
-
|
218
|
-
if (["s", "l", "a"].includes(space))
|
219
|
-
n = n / 100;
|
209
|
+
if (isNaN(n)) n = 0;
|
210
|
+
if (["s", "l", "a"].includes(space)) n = n / 100;
|
220
211
|
let nextValue;
|
221
212
|
if (resolvedValue.startsWith("hsl")) {
|
222
213
|
const { h: h2, s: s2, l, a: a2 } = Object.assign(
|
@@ -231,8 +222,7 @@ var useColorSelector = ({
|
|
231
222
|
);
|
232
223
|
nextValue = (0, import_utils.rgbaTo)([r, g, b, a2], fallbackValue)(formatRef.current);
|
233
224
|
}
|
234
|
-
if (!nextValue)
|
235
|
-
return;
|
225
|
+
if (!nextValue) return;
|
236
226
|
onChange(nextValue);
|
237
227
|
onChangeEnd(nextValue);
|
238
228
|
},
|
@@ -242,8 +232,7 @@ var useColorSelector = ({
|
|
242
232
|
var _a;
|
243
233
|
try {
|
244
234
|
const { sRGBHex } = (_a = await onOpen()) != null ? _a : {};
|
245
|
-
if (!sRGBHex)
|
246
|
-
return;
|
235
|
+
if (!sRGBHex) return;
|
247
236
|
onChange(sRGBHex);
|
248
237
|
onChangeEnd(sRGBHex);
|
249
238
|
} catch {
|
@@ -251,22 +240,17 @@ var useColorSelector = ({
|
|
251
240
|
}, [onOpen, onChange, onChangeEnd]);
|
252
241
|
(0, import_utils.useUpdateEffect)(() => {
|
253
242
|
const nextValue = (0, import_utils.hsvTo)([h, s, v, a], fallbackValue)(formatRef.current);
|
254
|
-
if (nextValue)
|
255
|
-
setValue(nextValue);
|
243
|
+
if (nextValue) setValue(nextValue);
|
256
244
|
}, [h, s, v, a]);
|
257
245
|
(0, import_utils.useUpdateEffect)(() => {
|
258
|
-
if (isDraggingRef.current)
|
259
|
-
|
260
|
-
if (valueProp)
|
261
|
-
setParsedValue(convertHsva(valueProp, fallbackValue));
|
246
|
+
if (isDraggingRef.current) return;
|
247
|
+
if (valueProp) setParsedValue(convertHsva(valueProp, fallbackValue));
|
262
248
|
}, [valueProp]);
|
263
249
|
(0, import_utils.useUpdateEffect)(() => {
|
264
|
-
if (!format || !value)
|
265
|
-
return;
|
250
|
+
if (!format || !value) return;
|
266
251
|
formatRef.current = format;
|
267
252
|
const nextValue = (0, import_utils.convertColor)(value, fallbackValue)(format);
|
268
|
-
if (nextValue)
|
269
|
-
setValue(nextValue);
|
253
|
+
if (nextValue) setValue(nextValue);
|
270
254
|
}, [format]);
|
271
255
|
const getContainerProps = (props2 = {}, ref = null) => ({
|
272
256
|
...props2,
|
@@ -418,8 +402,7 @@ var useColorSelector = ({
|
|
418
402
|
ref,
|
419
403
|
color,
|
420
404
|
onClick: (0, import_utils.handlerAll)(props2.onClick, () => {
|
421
|
-
if (!color)
|
422
|
-
return;
|
405
|
+
if (!color) return;
|
423
406
|
onSwatchClick == null ? void 0 : onSwatchClick(color);
|
424
407
|
onChange(color);
|
425
408
|
onChangeEnd(color);
|
@@ -507,8 +490,7 @@ var useColorSlider = ({
|
|
507
490
|
focusThumbOnChange = true,
|
508
491
|
...props
|
509
492
|
}) => {
|
510
|
-
if (!focusThumbOnChange)
|
511
|
-
props.isReadOnly = true;
|
493
|
+
if (!focusThumbOnChange) props.isReadOnly = true;
|
512
494
|
let {
|
513
495
|
id,
|
514
496
|
name,
|
@@ -555,16 +537,14 @@ var useColorSlider = ({
|
|
555
537
|
const getValueFromPointer = (0, import_react2.useCallback)(
|
556
538
|
(ev) => {
|
557
539
|
var _a, _b;
|
558
|
-
if (!trackRef.current)
|
559
|
-
return;
|
540
|
+
if (!trackRef.current) return;
|
560
541
|
const { min: min2, max: max2, step: step2 } = latestRef.current;
|
561
542
|
latestRef.current.eventSource = "pointer";
|
562
543
|
const { left, width } = trackRef.current.getBoundingClientRect();
|
563
544
|
const { clientX } = (_b = (_a = ev.touches) == null ? void 0 : _a[0]) != null ? _b : ev;
|
564
545
|
let percent = (clientX - left) / width;
|
565
546
|
let nextValue = (0, import_utils3.percentToValue)(percent, min2, max2);
|
566
|
-
if (step2)
|
567
|
-
nextValue = parseFloat((0, import_utils3.roundNumberToStep)(nextValue, min2, step2));
|
547
|
+
if (step2) nextValue = parseFloat((0, import_utils3.roundNumberToStep)(nextValue, min2, step2));
|
568
548
|
nextValue = (0, import_utils3.clampNumber)(nextValue, min2, max2);
|
569
549
|
return nextValue;
|
570
550
|
},
|
@@ -573,22 +553,19 @@ var useColorSlider = ({
|
|
573
553
|
const setValueFromPointer = (ev) => {
|
574
554
|
const { value: value2 } = latestRef.current;
|
575
555
|
const nextValue = getValueFromPointer(ev);
|
576
|
-
if (nextValue != null && nextValue !== value2)
|
577
|
-
setValue(nextValue);
|
556
|
+
if (nextValue != null && nextValue !== value2) setValue(nextValue);
|
578
557
|
};
|
579
558
|
const focusThumb = (0, import_react2.useCallback)(() => {
|
580
559
|
const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
|
581
|
-
if (focusThumbOnChange2)
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
});
|
560
|
+
if (focusThumbOnChange2) setTimeout(() => {
|
561
|
+
var _a;
|
562
|
+
return (_a = thumbRef.current) == null ? void 0 : _a.focus();
|
563
|
+
});
|
586
564
|
}, [latestRef]);
|
587
565
|
const constrain = (0, import_react2.useCallback)(
|
588
566
|
(value2) => {
|
589
567
|
const { isInteractive: isInteractive2, min: min2, max: max2 } = latestRef.current;
|
590
|
-
if (!isInteractive2)
|
591
|
-
return;
|
568
|
+
if (!isInteractive2) return;
|
592
569
|
value2 = parseFloat((0, import_utils3.roundNumberToStep)(value2, min2, oneStep));
|
593
570
|
value2 = (0, import_utils3.clampNumber)(value2, min2, max2);
|
594
571
|
setValue(value2);
|
@@ -617,8 +594,7 @@ var useColorSlider = ({
|
|
617
594
|
End: () => constrain(max2)
|
618
595
|
};
|
619
596
|
const action = actions[ev.key];
|
620
|
-
if (!action)
|
621
|
-
return;
|
597
|
+
if (!action) return;
|
622
598
|
ev.preventDefault();
|
623
599
|
ev.stopPropagation();
|
624
600
|
action(ev);
|
@@ -629,8 +605,7 @@ var useColorSlider = ({
|
|
629
605
|
(0, import_use_pan_event.usePanEvent)(containerRef, {
|
630
606
|
onSessionStart: (ev) => {
|
631
607
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
632
|
-
if (!isInteractive2)
|
633
|
-
return;
|
608
|
+
if (!isInteractive2) return;
|
634
609
|
setDragging(true);
|
635
610
|
focusThumb();
|
636
611
|
setValueFromPointer(ev);
|
@@ -638,22 +613,19 @@ var useColorSlider = ({
|
|
638
613
|
},
|
639
614
|
onSessionEnd: () => {
|
640
615
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
641
|
-
if (!isInteractive2)
|
642
|
-
return;
|
616
|
+
if (!isInteractive2) return;
|
643
617
|
setDragging(false);
|
644
618
|
onChangeEnd(value2);
|
645
619
|
},
|
646
620
|
onMove: (ev) => {
|
647
621
|
const { isInteractive: isInteractive2 } = latestRef.current;
|
648
|
-
if (!isInteractive2)
|
649
|
-
return;
|
622
|
+
if (!isInteractive2) return;
|
650
623
|
setValueFromPointer(ev);
|
651
624
|
}
|
652
625
|
});
|
653
626
|
(0, import_utils3.useUpdateEffect)(() => {
|
654
627
|
const { eventSource, value: value2 } = latestRef.current;
|
655
|
-
if (eventSource === "keyboard")
|
656
|
-
onChangeEnd(value2);
|
628
|
+
if (eventSource === "keyboard") onChangeEnd(value2);
|
657
629
|
}, [value, onChangeEnd]);
|
658
630
|
const getContainerProps = (0, import_react2.useCallback)(
|
659
631
|
(props2 = {}, ref = null) => {
|
@@ -949,8 +921,7 @@ var ColorSelectorSliders = (0, import_core4.forwardRef)(
|
|
949
921
|
...rest
|
950
922
|
}, ref) => {
|
951
923
|
let { size, withAlpha, getHueSliderProps, getAlphaSliderProps, styles } = useColorSelectorContext();
|
952
|
-
if (size === "full")
|
953
|
-
size = "lg";
|
924
|
+
if (size === "full") size = "lg";
|
954
925
|
const css = {
|
955
926
|
...styles.sliders
|
956
927
|
};
|
@@ -1146,8 +1117,7 @@ var ColorSelectorChannels = (0, import_core7.forwardRef)(({ className, channelPr
|
|
1146
1117
|
var ColorSelectorChannel = (0, import_core7.forwardRef)(({ className, channelLabel, ...rest }, ref) => {
|
1147
1118
|
const id = (0, import_react3.useId)();
|
1148
1119
|
let { size, disabled, readOnly, styles } = useColorSelectorContext();
|
1149
|
-
if (size === "full")
|
1150
|
-
size = "lg";
|
1120
|
+
if (size === "full") size = "lg";
|
1151
1121
|
const css = { ...styles.channel };
|
1152
1122
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_core7.ui.div, { className: (0, import_utils9.cx)("ui-color-selector__channel", className), children: [
|
1153
1123
|
channelLabel ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
@@ -1254,8 +1224,7 @@ var useSaturationSlider = ({
|
|
1254
1224
|
focusThumbOnChange = true,
|
1255
1225
|
...props
|
1256
1226
|
}) => {
|
1257
|
-
if (!focusThumbOnChange)
|
1258
|
-
props.isReadOnly = true;
|
1227
|
+
if (!focusThumbOnChange) props.isReadOnly = true;
|
1259
1228
|
let {
|
1260
1229
|
id,
|
1261
1230
|
name,
|
@@ -1303,8 +1272,7 @@ var useSaturationSlider = ({
|
|
1303
1272
|
const getValueFromPointer = (0, import_react4.useCallback)(
|
1304
1273
|
(ev) => {
|
1305
1274
|
var _a, _b;
|
1306
|
-
if (!trackRef.current)
|
1307
|
-
return [];
|
1275
|
+
if (!trackRef.current) return [];
|
1308
1276
|
const { step: step2 } = latestRef.current;
|
1309
1277
|
latestRef.current.eventSource = "pointer";
|
1310
1278
|
const { bottom, left, height, width } = trackRef.current.getBoundingClientRect();
|
@@ -1322,25 +1290,21 @@ var useSaturationSlider = ({
|
|
1322
1290
|
const setValueFromPointer = (ev) => {
|
1323
1291
|
const { value: value2 } = latestRef.current;
|
1324
1292
|
const [nextS, nextV] = getValueFromPointer(ev);
|
1325
|
-
if (nextS == null || nextV == null)
|
1326
|
-
return;
|
1293
|
+
if (nextS == null || nextV == null) return;
|
1327
1294
|
const [, s2, v2] = value2;
|
1328
|
-
if (nextS !== s2 || nextV !== v2)
|
1329
|
-
setValue(([h2]) => [h2, nextS, nextV]);
|
1295
|
+
if (nextS !== s2 || nextV !== v2) setValue(([h2]) => [h2, nextS, nextV]);
|
1330
1296
|
};
|
1331
1297
|
const focusThumb = (0, import_react4.useCallback)(() => {
|
1332
1298
|
const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
|
1333
|
-
if (focusThumbOnChange2)
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
});
|
1299
|
+
if (focusThumbOnChange2) setTimeout(() => {
|
1300
|
+
var _a;
|
1301
|
+
return (_a = thumbRef.current) == null ? void 0 : _a.focus();
|
1302
|
+
});
|
1338
1303
|
}, [latestRef]);
|
1339
1304
|
const constrain = (0, import_react4.useCallback)(
|
1340
1305
|
([s2, v2]) => {
|
1341
1306
|
const { isInteractive: isInteractive2 } = latestRef.current;
|
1342
|
-
if (!isInteractive2)
|
1343
|
-
return;
|
1307
|
+
if (!isInteractive2) return;
|
1344
1308
|
s2 = (0, import_utils11.clampNumber)(s2, 0, 1);
|
1345
1309
|
v2 = (0, import_utils11.clampNumber)(v2, 0, 1);
|
1346
1310
|
setValue(([h2]) => [h2, s2, v2]);
|
@@ -1356,8 +1320,7 @@ var useSaturationSlider = ({
|
|
1356
1320
|
ArrowDown: () => constrain([s, v - step])
|
1357
1321
|
};
|
1358
1322
|
const action = actions[ev.key];
|
1359
|
-
if (!action)
|
1360
|
-
return;
|
1323
|
+
if (!action) return;
|
1361
1324
|
ev.preventDefault();
|
1362
1325
|
ev.stopPropagation();
|
1363
1326
|
action(ev);
|
@@ -1368,8 +1331,7 @@ var useSaturationSlider = ({
|
|
1368
1331
|
(0, import_use_pan_event2.usePanEvent)(containerRef, {
|
1369
1332
|
onSessionStart: (ev) => {
|
1370
1333
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
1371
|
-
if (!isInteractive2)
|
1372
|
-
return;
|
1334
|
+
if (!isInteractive2) return;
|
1373
1335
|
setDragging(true);
|
1374
1336
|
focusThumb();
|
1375
1337
|
setValueFromPointer(ev);
|
@@ -1377,22 +1339,19 @@ var useSaturationSlider = ({
|
|
1377
1339
|
},
|
1378
1340
|
onSessionEnd: () => {
|
1379
1341
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
1380
|
-
if (!isInteractive2)
|
1381
|
-
return;
|
1342
|
+
if (!isInteractive2) return;
|
1382
1343
|
setDragging(false);
|
1383
1344
|
onChangeEnd(value2);
|
1384
1345
|
},
|
1385
1346
|
onMove: (ev) => {
|
1386
1347
|
const { isInteractive: isInteractive2 } = latestRef.current;
|
1387
|
-
if (!isInteractive2)
|
1388
|
-
return;
|
1348
|
+
if (!isInteractive2) return;
|
1389
1349
|
setValueFromPointer(ev);
|
1390
1350
|
}
|
1391
1351
|
});
|
1392
1352
|
(0, import_utils11.useUpdateEffect)(() => {
|
1393
1353
|
const { eventSource, value: value2 } = latestRef.current;
|
1394
|
-
if (eventSource === "keyboard")
|
1395
|
-
onChangeEnd(value2);
|
1354
|
+
if (eventSource === "keyboard") onChangeEnd(value2);
|
1396
1355
|
}, [value, onChangeEnd]);
|
1397
1356
|
const getContainerProps = (0, import_react4.useCallback)(
|
1398
1357
|
(props2 = {}, ref = null) => ({
|
@@ -1790,13 +1749,11 @@ var useColorPicker = ({
|
|
1790
1749
|
});
|
1791
1750
|
const isColorSelectorFull = colorSelectorSize === "full";
|
1792
1751
|
const onOpen = (0, import_react5.useCallback)(() => {
|
1793
|
-
if (disabled || readOnly)
|
1794
|
-
return;
|
1752
|
+
if (disabled || readOnly) return;
|
1795
1753
|
onInternalOpen();
|
1796
1754
|
}, [onInternalOpen, disabled, readOnly]);
|
1797
1755
|
const onClose = (0, import_react5.useCallback)(() => {
|
1798
|
-
if (!isOpen)
|
1799
|
-
return;
|
1756
|
+
if (!isOpen) return;
|
1800
1757
|
const next = (0, import_utils14.convertColor)(value, fallbackValue)(formatRef.current);
|
1801
1758
|
setValue((prev) => !next || prev === next ? prev : next);
|
1802
1759
|
setInputValue(formatInput(next != null ? next : ""));
|
@@ -1812,14 +1769,12 @@ var useColorPicker = ({
|
|
1812
1769
|
fallbackValue
|
1813
1770
|
]);
|
1814
1771
|
const onContainerClick = (0, import_react5.useCallback)(() => {
|
1815
|
-
if (isOpen)
|
1816
|
-
return;
|
1772
|
+
if (isOpen) return;
|
1817
1773
|
onOpen();
|
1818
1774
|
}, [isOpen, onOpen]);
|
1819
1775
|
const onInputFocus = (0, import_react5.useCallback)(() => {
|
1820
1776
|
isInputFocused.current = true;
|
1821
|
-
if (isOpen)
|
1822
|
-
return;
|
1777
|
+
if (isOpen) return;
|
1823
1778
|
onOpen();
|
1824
1779
|
}, [isOpen, onOpen]);
|
1825
1780
|
const onInputBlur = (0, import_react5.useCallback)(() => {
|
@@ -1828,29 +1783,23 @@ var useColorPicker = ({
|
|
1828
1783
|
const onContainerBlur = (0, import_react5.useCallback)(
|
1829
1784
|
(ev) => {
|
1830
1785
|
const relatedTarget = (0, import_utils14.getEventRelatedTarget)(ev);
|
1831
|
-
if ((0, import_utils14.isContains)(containerRef.current, relatedTarget))
|
1832
|
-
|
1833
|
-
if (
|
1834
|
-
return;
|
1835
|
-
if (isOpen)
|
1836
|
-
onClose();
|
1786
|
+
if ((0, import_utils14.isContains)(containerRef.current, relatedTarget)) return;
|
1787
|
+
if (!closeOnBlur) return;
|
1788
|
+
if (isOpen) onClose();
|
1837
1789
|
},
|
1838
1790
|
[closeOnBlur, isOpen, onClose]
|
1839
1791
|
);
|
1840
1792
|
const onInputKeyDown = (0, import_react5.useCallback)(
|
1841
1793
|
(ev) => {
|
1842
|
-
if (ev.key === " ")
|
1843
|
-
|
1844
|
-
if (disabled || readOnly)
|
1845
|
-
return;
|
1794
|
+
if (ev.key === " ") ev.key = ev.code;
|
1795
|
+
if (disabled || readOnly) return;
|
1846
1796
|
const actions = {
|
1847
1797
|
Space: !isOpen ? onOpen : void 0,
|
1848
1798
|
Enter: !isOpen ? onOpen : void 0,
|
1849
1799
|
Escape: closeOnEsc ? onClose : void 0
|
1850
1800
|
};
|
1851
1801
|
const action = actions[ev.key];
|
1852
|
-
if (!action)
|
1853
|
-
return;
|
1802
|
+
if (!action) return;
|
1854
1803
|
ev.preventDefault();
|
1855
1804
|
ev.stopPropagation();
|
1856
1805
|
action();
|
@@ -1869,8 +1818,7 @@ var useColorPicker = ({
|
|
1869
1818
|
(value2) => {
|
1870
1819
|
setValue(value2);
|
1871
1820
|
setTimeout(() => {
|
1872
|
-
if (!isInputFocused.current)
|
1873
|
-
setInputValue(formatInput(value2));
|
1821
|
+
if (!isInputFocused.current) setInputValue(formatInput(value2));
|
1874
1822
|
});
|
1875
1823
|
},
|
1876
1824
|
[setValue, formatInput]
|
@@ -1882,8 +1830,7 @@ var useColorPicker = ({
|
|
1882
1830
|
ev.stopPropagation();
|
1883
1831
|
try {
|
1884
1832
|
const { sRGBHex } = (_a2 = await onEyeDropperOpen()) != null ? _a2 : {};
|
1885
|
-
if (!sRGBHex)
|
1886
|
-
return;
|
1833
|
+
if (!sRGBHex) return;
|
1887
1834
|
onColorSelectorChange(sRGBHex);
|
1888
1835
|
onChangeEnd == null ? void 0 : onChangeEnd(sRGBHex);
|
1889
1836
|
} catch {
|
@@ -1897,18 +1844,15 @@ var useColorPicker = ({
|
|
1897
1844
|
enabled: isOpen && closeOnBlur
|
1898
1845
|
});
|
1899
1846
|
(0, import_utils14.useUpdateEffect)(() => {
|
1900
|
-
if (!format || !value)
|
1901
|
-
return;
|
1847
|
+
if (!format || !value) return;
|
1902
1848
|
formatRef.current = format;
|
1903
1849
|
const nextValue = (0, import_utils14.convertColor)(value, fallbackValue)(format);
|
1904
|
-
if (!nextValue)
|
1905
|
-
return;
|
1850
|
+
if (!nextValue) return;
|
1906
1851
|
setInputValue(formatInput(nextValue));
|
1907
1852
|
setValue(nextValue);
|
1908
1853
|
}, [format]);
|
1909
1854
|
(0, import_utils14.useUpdateEffect)(() => {
|
1910
|
-
if (isInputFocused.current || !valueProp)
|
1911
|
-
return;
|
1855
|
+
if (isInputFocused.current || !valueProp) return;
|
1912
1856
|
setInputValue(formatInput(valueProp));
|
1913
1857
|
}, [valueProp]);
|
1914
1858
|
const getPopoverProps = (0, import_react5.useCallback)(
|