@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
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/use-color-selector.ts"],"sourcesContent":["import type {\n CSSUIObject,\n HTMLUIProps,\n UIPropGetter,\n ThemeProps,\n RequiredUIPropGetter,\n} from \"@yamada-ui/core\"\nimport {\n useFormControlProps,\n type FormControlOptions,\n formControlProperties,\n} from \"@yamada-ui/form-control\"\nimport type { InputProps } from \"@yamada-ui/input\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useEyeDropper } from \"@yamada-ui/use-eye-dropper\"\nimport type { ColorFormat, Dict, Merge } from \"@yamada-ui/utils\"\nimport {\n calcFormat,\n convertColor,\n createContext,\n handlerAll,\n hsvTo,\n isString,\n parseToHsv,\n useCallbackRef,\n useUpdateEffect,\n omitObject,\n parseToRgba,\n parseToHsla,\n rgbaTo,\n hslaTo,\n pickObject,\n} from \"@yamada-ui/utils\"\nimport type { ChangeEvent } from \"react\"\nimport { useCallback, useMemo, useRef, useState } from \"react\"\nimport type { AlphaSliderProps } from \"./alpha-slider\"\nimport type { ColorSwatchProps } from \"./color-swatch\"\nimport type { HueSliderProps } from \"./hue-slider\"\nimport type { SaturationSliderProps } from \"./saturation-slider\"\n\ntype Space = keyof Hsla | keyof Rgba\ntype Hsla = { h: number; s: number; l: number; a: number }\ntype Rgba = { r: number; g: number; b: number; a: number }\ntype Hsva = { h: number; s: number; v: number; a: number }\ntype Channel = {\n label: string\n space: Space\n value: number\n min: number\n max: number\n}\n\nconst convertHsla = (value: string, fallback?: string): Hsla => {\n let [h, s, l, a] = parseToHsla(value, fallback) ?? [0, 0, 1, 1]\n\n if (a > 1) a = 1\n\n return { h, s, l, a }\n}\n\nconst convertRgba = (value: string, fallback?: string): Rgba => {\n let [r, g, b, a] = parseToRgba(value, fallback) ?? [255, 255, 255, 1]\n\n if (r > 255) r = 255\n if (g > 255) g = 255\n if (b > 255) b = 255\n if (a > 1) a = 1\n\n return { r, g, b, a }\n}\n\nconst convertHsva = (value: string, fallback?: string): Hsva => {\n const [h, s, v, a] = parseToHsv(value, fallback)\n\n return { h, s, v, a }\n}\n\ntype ColorSelectorContext = {\n value: string\n onChange: (value: string | Partial<Hsva>) => void\n eyeDropperSupported: boolean\n withAlpha: boolean\n isInteractive: boolean\n disabled?: boolean\n readOnly?: boolean\n channels: Channel[]\n size?: ThemeProps<\"ColorSelector\">[\"size\"]\n getHueSliderProps: UIPropGetter<\"input\", HueSliderProps, HueSliderProps>\n getAlphaSliderProps: UIPropGetter<\"input\", AlphaSliderProps, AlphaSliderProps>\n getEyeDropperProps: UIPropGetter<\"button\">\n getChannelProps: RequiredUIPropGetter<\n \"input\",\n Merge<InputProps, { space: Space }>,\n InputProps\n >\n getSwatchProps: UIPropGetter<\"div\", ColorSwatchProps, ColorSwatchProps>\n styles: Record<string, CSSUIObject>\n}\n\nexport const [ColorSelectorProvider, useColorSelectorContext] =\n createContext<ColorSelectorContext>({\n name: \"ColorSelectorContext\",\n errorMessage: `useColorSelectorContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ColorSelector />\"`,\n })\n\ntype UseColorSelectorOptions = {\n /**\n * The base `id` to use for the color selector.\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 color selector.\n */\n value?: string\n /**\n * The initial value of the color selector.\n */\n defaultValue?: string\n /**\n * The fallback value returned when color determination fails.\n */\n fallbackValue?: string\n /**\n * Function called whenever the color selector value changes.\n */\n onChange?: (value: string) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: string) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: string) => void\n /**\n * Color format. For example, `hex`, `rgba`, etc.\n *\n * @default \"hexa\"\n */\n format?: ColorFormat\n /**\n * Function called whenever the color swatch click.\n */\n onSwatchClick?: (value: string) => void\n}\n\nexport type UseColorSelectorBaseProps = UseColorSelectorOptions &\n FormControlOptions\n\nexport type UseColorSelectorProps = Omit<\n HTMLUIProps<\"div\">,\n \"defaultValue\" | \"onChange\" | \"children\"\n> &\n UseColorSelectorBaseProps\n\nexport const useColorSelector = ({\n isInvalid,\n ...props\n}: UseColorSelectorProps) => {\n let {\n id,\n name,\n value: valueProp,\n defaultValue,\n fallbackValue,\n onChange: onChangeProp,\n onChangeStart: onChangeStartProp,\n onChangeEnd: onChangeEndProp,\n format,\n required,\n disabled,\n readOnly,\n onSwatchClick,\n ...rest\n } = useFormControlProps({ isInvalid, ...props })\n\n const onChangeStartRef = useCallbackRef(onChangeStartProp)\n const onChangeEndRef = useCallbackRef(onChangeEndProp)\n const { supported: eyeDropperSupported, onOpen } = useEyeDropper()\n const [value, setValue] = useControllableState({\n value: valueProp,\n defaultValue: defaultValue ?? fallbackValue,\n onChange: onChangeProp,\n })\n const resolvedValue = value ?? \"#ffffff\"\n const timeoutId = useRef<any>(undefined)\n const formatRef = useRef<ColorFormat>(format ?? calcFormat(resolvedValue))\n const isDraggingRef = useRef<boolean>(false)\n const [parsedValue, setParsedValue] = useState<Hsva>(\n convertHsva(resolvedValue, fallbackValue),\n )\n const { h, s, v, a } = parsedValue\n const withAlpha = formatRef.current.endsWith(\"a\")\n const isInteractive = !(disabled || readOnly)\n\n const channels: Channel[] = useMemo(() => {\n if (resolvedValue.startsWith(\"hsl\")) {\n const { h, s, l, a } = convertHsla(resolvedValue, fallbackValue)\n\n let channels: Channel[] = [\n { label: \"H\", space: \"h\", value: Math.round(h), min: 0, max: 360 },\n {\n label: \"S(%)\",\n space: \"s\",\n value: Math.round(s * 100),\n min: 0,\n max: 100,\n },\n {\n label: \"L(%)\",\n space: \"l\",\n value: Math.round(l * 100),\n min: 0,\n max: 100,\n },\n ]\n\n if (withAlpha) {\n channels = [\n ...channels,\n {\n label: \"A(%)\",\n space: \"a\",\n value: Math.round(a * 100),\n min: 0,\n max: 100,\n },\n ]\n }\n\n return channels\n } else {\n const { r, g, b, a } = convertRgba(resolvedValue, fallbackValue)\n\n let channels: Channel[] = [\n { label: \"R\", space: \"r\", value: Math.round(r), min: 0, max: 255 },\n { label: \"G\", space: \"g\", value: Math.round(g), min: 0, max: 255 },\n { label: \"B\", space: \"b\", value: Math.round(b), min: 0, max: 255 },\n ]\n\n if (withAlpha) {\n channels = [\n ...channels,\n {\n label: \"A(%)\",\n space: \"a\",\n value: Math.round(a * 100),\n min: 0,\n max: 100,\n },\n ]\n }\n\n return channels\n }\n }, [resolvedValue, withAlpha, fallbackValue])\n\n const onChange = useCallback(\n (value: string | Partial<Hsva>) => {\n if (isString(value)) {\n setParsedValue(convertHsva(value, fallbackValue))\n } else {\n setParsedValue((prev) => ({ ...prev, ...value }))\n }\n },\n [fallbackValue],\n )\n\n const onChangeStart = useCallback(\n (value: Partial<Hsva>) => {\n window.clearTimeout(timeoutId.current)\n\n isDraggingRef.current = true\n\n const { h, s, v, a } = { ...parsedValue, ...value }\n\n const nextValue = hsvTo([h, s, v, a], fallbackValue)(formatRef.current)\n\n if (nextValue) onChangeStartRef(nextValue)\n },\n [formatRef, onChangeStartRef, fallbackValue, parsedValue],\n )\n\n const onChangeEnd = useCallback(\n (value: string | Partial<Hsva>) => {\n window.clearTimeout(timeoutId.current)\n\n timeoutId.current = window.setTimeout(() => {\n isDraggingRef.current = false\n }, 200)\n\n let nextValue: string | undefined\n\n if (isString(value)) {\n nextValue = convertColor(value, fallbackValue)(formatRef.current)\n } else {\n const { h, s, v, a } = { ...parsedValue, ...value }\n\n nextValue = hsvTo([h, s, v, a], fallbackValue)(formatRef.current)\n }\n\n if (nextValue) onChangeEndRef(nextValue)\n },\n [formatRef, onChangeEndRef, fallbackValue, parsedValue],\n )\n\n const onChannelChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>, space: Space) => {\n let n = Math.floor(parseFloat(ev.target.value))\n\n if (isNaN(n)) n = 0\n\n if ([\"s\", \"l\", \"a\"].includes(space)) n = n / 100\n\n let nextValue: string | undefined\n\n if (resolvedValue.startsWith(\"hsl\")) {\n const { h, s, l, a } = Object.assign(\n convertHsla(resolvedValue, fallbackValue),\n { [space]: n },\n )\n\n nextValue = hslaTo([h, s, l, a], fallbackValue)(formatRef.current)\n } else {\n const { r, g, b, a } = Object.assign(\n convertRgba(resolvedValue, fallbackValue),\n { [space]: n },\n )\n\n nextValue = rgbaTo([r, g, b, a], fallbackValue)(formatRef.current)\n }\n\n if (!nextValue) return\n\n onChange(nextValue)\n onChangeEnd(nextValue)\n },\n [resolvedValue, onChange, onChangeEnd, formatRef, fallbackValue],\n )\n\n const onEyeDropperClick = useCallback(async () => {\n try {\n const { sRGBHex } = (await onOpen()) ?? {}\n\n if (!sRGBHex) return\n\n onChange(sRGBHex)\n onChangeEnd(sRGBHex)\n } catch {}\n }, [onOpen, onChange, onChangeEnd])\n\n useUpdateEffect(() => {\n const nextValue = hsvTo([h, s, v, a], fallbackValue)(formatRef.current)\n\n if (nextValue) setValue(nextValue)\n }, [h, s, v, a])\n\n useUpdateEffect(() => {\n if (isDraggingRef.current) return\n\n if (valueProp) setParsedValue(convertHsva(valueProp, fallbackValue))\n }, [valueProp])\n\n useUpdateEffect(() => {\n if (!format || !value) return\n\n formatRef.current = format\n\n const nextValue = convertColor(value, fallbackValue)(format)\n\n if (nextValue) setValue(nextValue)\n }, [format])\n\n const getContainerProps: UIPropGetter = (props = {}, ref = null) => ({\n ...props,\n ref,\n ...omitObject(rest, [\"aria-readonly\"]),\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: resolvedValue,\n required,\n disabled,\n readOnly,\n }),\n [disabled, id, name, readOnly, required, rest, resolvedValue],\n )\n\n const getSaturationSliderProps: UIPropGetter<\n \"input\",\n SaturationSliderProps,\n SaturationSliderProps\n > = useCallback(\n (props = {}, ref = null) => ({\n required,\n disabled,\n readOnly,\n isInvalid,\n ...props,\n ref,\n value: [h, s, v],\n onChange: handlerAll(props.onChange, ([, s, v]) => onChange({ s, v })),\n onChangeStart: handlerAll(props.onChangeStart, ([, s, v]) =>\n onChangeStart({ s, v }),\n ),\n onChangeEnd: handlerAll(props.onChangeEnd, ([, s, v]) =>\n onChangeEnd({ s, v }),\n ),\n }),\n [\n required,\n disabled,\n readOnly,\n isInvalid,\n h,\n s,\n v,\n onChange,\n onChangeStart,\n onChangeEnd,\n ],\n )\n\n const getHueSliderProps: UIPropGetter<\n \"input\",\n HueSliderProps,\n HueSliderProps\n > = useCallback(\n (props = {}, ref = null) => ({\n required,\n disabled,\n readOnly,\n isInvalid,\n ...props,\n ref,\n value: h,\n onChange: handlerAll(props.onChange, (h) => onChange({ h })),\n onChangeStart: handlerAll(props.onChangeStart, (h) =>\n onChangeStart({ h }),\n ),\n onChangeEnd: handlerAll(props.onChangeEnd, (h) => onChangeEnd({ h })),\n }),\n [\n required,\n disabled,\n readOnly,\n isInvalid,\n h,\n onChange,\n onChangeStart,\n onChangeEnd,\n ],\n )\n\n const getAlphaSliderProps: UIPropGetter<\n \"input\",\n AlphaSliderProps,\n AlphaSliderProps\n > = useCallback(\n (props = {}, ref = null) => ({\n required,\n disabled,\n readOnly,\n isInvalid,\n ...props,\n ref,\n value: a,\n color: hsvTo([h, s, v, a], fallbackValue)(formatRef.current),\n onChange: handlerAll(props.onChange, (a) => onChange({ a })),\n onChangeStart: handlerAll(props.onChangeStart, (a) =>\n onChangeStart({ a }),\n ),\n onChangeEnd: handlerAll(props.onChangeEnd, (a) => onChangeEnd({ a })),\n }),\n [\n fallbackValue,\n required,\n disabled,\n readOnly,\n isInvalid,\n formatRef,\n h,\n s,\n v,\n a,\n onChange,\n onChangeStart,\n onChangeEnd,\n ],\n )\n\n const getChannelProps: RequiredUIPropGetter<\n \"input\",\n Merge<InputProps, { space: Space }>,\n InputProps\n > = useCallback(\n ({ space, ...props }, ref = null) => {\n return {\n required,\n disabled,\n readOnly,\n isInvalid,\n ...props,\n ref,\n type: \"number\",\n step: 1,\n onChange: handlerAll(props.onChange, (ev) =>\n onChannelChange(ev, space),\n ),\n } as Dict\n },\n [required, disabled, readOnly, isInvalid, onChannelChange],\n )\n\n const getEyeDropperProps: UIPropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n disabled,\n \"aria-label\": \"Pick a color\",\n ...props,\n ref,\n onClick: handlerAll(props.onClick, onEyeDropperClick),\n }),\n [disabled, onEyeDropperClick],\n )\n\n const getSwatchProps: UIPropGetter<\n \"div\",\n ColorSwatchProps,\n ColorSwatchProps\n > = useCallback(\n ({ color, ...props } = {}, ref = null) => ({\n \"aria-label\": `Select ${color} as the color`,\n disabled,\n readOnly,\n ...props,\n ref,\n color,\n onClick: handlerAll(props.onClick, () => {\n if (!color) return\n\n onSwatchClick?.(color)\n onChange(color)\n onChangeEnd(color)\n }),\n }),\n [disabled, readOnly, onSwatchClick, onChange, onChangeEnd],\n )\n\n return {\n value: resolvedValue,\n onChange,\n eyeDropperSupported,\n withAlpha,\n isInteractive,\n disabled,\n readOnly,\n channels,\n getContainerProps,\n getInputProps,\n getSaturationSliderProps,\n getHueSliderProps,\n getAlphaSliderProps,\n getEyeDropperProps,\n getChannelProps,\n getSwatchProps,\n }\n}\n\nexport type UseColorSelectorReturn = ReturnType<typeof useColorSelector>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,0BAIO;AAEP,oCAAqC;AACrC,6BAA8B;AAE9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F;","names":["h","s","a","channels","value","v","props"]}
|
1
|
+
{"version":3,"sources":["../src/use-color-selector.ts"],"sourcesContent":["import type {\n CSSUIObject,\n HTMLUIProps,\n UIPropGetter,\n ThemeProps,\n RequiredUIPropGetter,\n} from \"@yamada-ui/core\"\nimport {\n useFormControlProps,\n type FormControlOptions,\n formControlProperties,\n} from \"@yamada-ui/form-control\"\nimport type { InputProps } from \"@yamada-ui/input\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useEyeDropper } from \"@yamada-ui/use-eye-dropper\"\nimport type { ColorFormat, Dict, Merge } from \"@yamada-ui/utils\"\nimport {\n calcFormat,\n convertColor,\n createContext,\n handlerAll,\n hsvTo,\n isString,\n parseToHsv,\n useCallbackRef,\n useUpdateEffect,\n omitObject,\n parseToRgba,\n parseToHsla,\n rgbaTo,\n hslaTo,\n pickObject,\n} from \"@yamada-ui/utils\"\nimport type { ChangeEvent } from \"react\"\nimport { useCallback, useMemo, useRef, useState } from \"react\"\nimport type { AlphaSliderProps } from \"./alpha-slider\"\nimport type { ColorSwatchProps } from \"./color-swatch\"\nimport type { HueSliderProps } from \"./hue-slider\"\nimport type { SaturationSliderProps } from \"./saturation-slider\"\n\ntype Space = keyof Hsla | keyof Rgba\ntype Hsla = { h: number; s: number; l: number; a: number }\ntype Rgba = { r: number; g: number; b: number; a: number }\ntype Hsva = { h: number; s: number; v: number; a: number }\ntype Channel = {\n label: string\n space: Space\n value: number\n min: number\n max: number\n}\n\nconst convertHsla = (value: string, fallback?: string): Hsla => {\n let [h, s, l, a] = parseToHsla(value, fallback) ?? [0, 0, 1, 1]\n\n if (a > 1) a = 1\n\n return { h, s, l, a }\n}\n\nconst convertRgba = (value: string, fallback?: string): Rgba => {\n let [r, g, b, a] = parseToRgba(value, fallback) ?? [255, 255, 255, 1]\n\n if (r > 255) r = 255\n if (g > 255) g = 255\n if (b > 255) b = 255\n if (a > 1) a = 1\n\n return { r, g, b, a }\n}\n\nconst convertHsva = (value: string, fallback?: string): Hsva => {\n const [h, s, v, a] = parseToHsv(value, fallback)\n\n return { h, s, v, a }\n}\n\ntype ColorSelectorContext = {\n value: string\n onChange: (value: string | Partial<Hsva>) => void\n eyeDropperSupported: boolean\n withAlpha: boolean\n isInteractive: boolean\n disabled?: boolean\n readOnly?: boolean\n channels: Channel[]\n size?: ThemeProps<\"ColorSelector\">[\"size\"]\n getHueSliderProps: UIPropGetter<\"input\", HueSliderProps, HueSliderProps>\n getAlphaSliderProps: UIPropGetter<\"input\", AlphaSliderProps, AlphaSliderProps>\n getEyeDropperProps: UIPropGetter<\"button\">\n getChannelProps: RequiredUIPropGetter<\n \"input\",\n Merge<InputProps, { space: Space }>,\n InputProps\n >\n getSwatchProps: UIPropGetter<\"div\", ColorSwatchProps, ColorSwatchProps>\n styles: Record<string, CSSUIObject>\n}\n\nexport const [ColorSelectorProvider, useColorSelectorContext] =\n createContext<ColorSelectorContext>({\n name: \"ColorSelectorContext\",\n errorMessage: `useColorSelectorContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ColorSelector />\"`,\n })\n\ntype UseColorSelectorOptions = {\n /**\n * The base `id` to use for the color selector.\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 color selector.\n */\n value?: string\n /**\n * The initial value of the color selector.\n */\n defaultValue?: string\n /**\n * The fallback value returned when color determination fails.\n */\n fallbackValue?: string\n /**\n * Function called whenever the color selector value changes.\n */\n onChange?: (value: string) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: string) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: string) => void\n /**\n * Color format. For example, `hex`, `rgba`, etc.\n *\n * @default \"hexa\"\n */\n format?: ColorFormat\n /**\n * Function called whenever the color swatch click.\n */\n onSwatchClick?: (value: string) => void\n}\n\nexport type UseColorSelectorBaseProps = UseColorSelectorOptions &\n FormControlOptions\n\nexport type UseColorSelectorProps = Omit<\n HTMLUIProps<\"div\">,\n \"defaultValue\" | \"onChange\" | \"children\"\n> &\n UseColorSelectorBaseProps\n\nexport const useColorSelector = ({\n isInvalid,\n ...props\n}: UseColorSelectorProps) => {\n let {\n id,\n name,\n value: valueProp,\n defaultValue,\n fallbackValue,\n onChange: onChangeProp,\n onChangeStart: onChangeStartProp,\n onChangeEnd: onChangeEndProp,\n format,\n required,\n disabled,\n readOnly,\n onSwatchClick,\n ...rest\n } = useFormControlProps({ isInvalid, ...props })\n\n const onChangeStartRef = useCallbackRef(onChangeStartProp)\n const onChangeEndRef = useCallbackRef(onChangeEndProp)\n const { supported: eyeDropperSupported, onOpen } = useEyeDropper()\n const [value, setValue] = useControllableState({\n value: valueProp,\n defaultValue: defaultValue ?? fallbackValue,\n onChange: onChangeProp,\n })\n const resolvedValue = value ?? \"#ffffff\"\n const timeoutId = useRef<any>(undefined)\n const formatRef = useRef<ColorFormat>(format ?? calcFormat(resolvedValue))\n const isDraggingRef = useRef<boolean>(false)\n const [parsedValue, setParsedValue] = useState<Hsva>(\n convertHsva(resolvedValue, fallbackValue),\n )\n const { h, s, v, a } = parsedValue\n const withAlpha = formatRef.current.endsWith(\"a\")\n const isInteractive = !(disabled || readOnly)\n\n const channels: Channel[] = useMemo(() => {\n if (resolvedValue.startsWith(\"hsl\")) {\n const { h, s, l, a } = convertHsla(resolvedValue, fallbackValue)\n\n let channels: Channel[] = [\n { label: \"H\", space: \"h\", value: Math.round(h), min: 0, max: 360 },\n {\n label: \"S(%)\",\n space: \"s\",\n value: Math.round(s * 100),\n min: 0,\n max: 100,\n },\n {\n label: \"L(%)\",\n space: \"l\",\n value: Math.round(l * 100),\n min: 0,\n max: 100,\n },\n ]\n\n if (withAlpha) {\n channels = [\n ...channels,\n {\n label: \"A(%)\",\n space: \"a\",\n value: Math.round(a * 100),\n min: 0,\n max: 100,\n },\n ]\n }\n\n return channels\n } else {\n const { r, g, b, a } = convertRgba(resolvedValue, fallbackValue)\n\n let channels: Channel[] = [\n { label: \"R\", space: \"r\", value: Math.round(r), min: 0, max: 255 },\n { label: \"G\", space: \"g\", value: Math.round(g), min: 0, max: 255 },\n { label: \"B\", space: \"b\", value: Math.round(b), min: 0, max: 255 },\n ]\n\n if (withAlpha) {\n channels = [\n ...channels,\n {\n label: \"A(%)\",\n space: \"a\",\n value: Math.round(a * 100),\n min: 0,\n max: 100,\n },\n ]\n }\n\n return channels\n }\n }, [resolvedValue, withAlpha, fallbackValue])\n\n const onChange = useCallback(\n (value: string | Partial<Hsva>) => {\n if (isString(value)) {\n setParsedValue(convertHsva(value, fallbackValue))\n } else {\n setParsedValue((prev) => ({ ...prev, ...value }))\n }\n },\n [fallbackValue],\n )\n\n const onChangeStart = useCallback(\n (value: Partial<Hsva>) => {\n window.clearTimeout(timeoutId.current)\n\n isDraggingRef.current = true\n\n const { h, s, v, a } = { ...parsedValue, ...value }\n\n const nextValue = hsvTo([h, s, v, a], fallbackValue)(formatRef.current)\n\n if (nextValue) onChangeStartRef(nextValue)\n },\n [formatRef, onChangeStartRef, fallbackValue, parsedValue],\n )\n\n const onChangeEnd = useCallback(\n (value: string | Partial<Hsva>) => {\n window.clearTimeout(timeoutId.current)\n\n timeoutId.current = window.setTimeout(() => {\n isDraggingRef.current = false\n }, 200)\n\n let nextValue: string | undefined\n\n if (isString(value)) {\n nextValue = convertColor(value, fallbackValue)(formatRef.current)\n } else {\n const { h, s, v, a } = { ...parsedValue, ...value }\n\n nextValue = hsvTo([h, s, v, a], fallbackValue)(formatRef.current)\n }\n\n if (nextValue) onChangeEndRef(nextValue)\n },\n [formatRef, onChangeEndRef, fallbackValue, parsedValue],\n )\n\n const onChannelChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>, space: Space) => {\n let n = Math.floor(parseFloat(ev.target.value))\n\n if (isNaN(n)) n = 0\n\n if ([\"s\", \"l\", \"a\"].includes(space)) n = n / 100\n\n let nextValue: string | undefined\n\n if (resolvedValue.startsWith(\"hsl\")) {\n const { h, s, l, a } = Object.assign(\n convertHsla(resolvedValue, fallbackValue),\n { [space]: n },\n )\n\n nextValue = hslaTo([h, s, l, a], fallbackValue)(formatRef.current)\n } else {\n const { r, g, b, a } = Object.assign(\n convertRgba(resolvedValue, fallbackValue),\n { [space]: n },\n )\n\n nextValue = rgbaTo([r, g, b, a], fallbackValue)(formatRef.current)\n }\n\n if (!nextValue) return\n\n onChange(nextValue)\n onChangeEnd(nextValue)\n },\n [resolvedValue, onChange, onChangeEnd, formatRef, fallbackValue],\n )\n\n const onEyeDropperClick = useCallback(async () => {\n try {\n const { sRGBHex } = (await onOpen()) ?? {}\n\n if (!sRGBHex) return\n\n onChange(sRGBHex)\n onChangeEnd(sRGBHex)\n } catch {}\n }, [onOpen, onChange, onChangeEnd])\n\n useUpdateEffect(() => {\n const nextValue = hsvTo([h, s, v, a], fallbackValue)(formatRef.current)\n\n if (nextValue) setValue(nextValue)\n }, [h, s, v, a])\n\n useUpdateEffect(() => {\n if (isDraggingRef.current) return\n\n if (valueProp) setParsedValue(convertHsva(valueProp, fallbackValue))\n }, [valueProp])\n\n useUpdateEffect(() => {\n if (!format || !value) return\n\n formatRef.current = format\n\n const nextValue = convertColor(value, fallbackValue)(format)\n\n if (nextValue) setValue(nextValue)\n }, [format])\n\n const getContainerProps: UIPropGetter = (props = {}, ref = null) => ({\n ...props,\n ref,\n ...omitObject(rest, [\"aria-readonly\"]),\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: resolvedValue,\n required,\n disabled,\n readOnly,\n }),\n [disabled, id, name, readOnly, required, rest, resolvedValue],\n )\n\n const getSaturationSliderProps: UIPropGetter<\n \"input\",\n SaturationSliderProps,\n SaturationSliderProps\n > = useCallback(\n (props = {}, ref = null) => ({\n required,\n disabled,\n readOnly,\n isInvalid,\n ...props,\n ref,\n value: [h, s, v],\n onChange: handlerAll(props.onChange, ([, s, v]) => onChange({ s, v })),\n onChangeStart: handlerAll(props.onChangeStart, ([, s, v]) =>\n onChangeStart({ s, v }),\n ),\n onChangeEnd: handlerAll(props.onChangeEnd, ([, s, v]) =>\n onChangeEnd({ s, v }),\n ),\n }),\n [\n required,\n disabled,\n readOnly,\n isInvalid,\n h,\n s,\n v,\n onChange,\n onChangeStart,\n onChangeEnd,\n ],\n )\n\n const getHueSliderProps: UIPropGetter<\n \"input\",\n HueSliderProps,\n HueSliderProps\n > = useCallback(\n (props = {}, ref = null) => ({\n required,\n disabled,\n readOnly,\n isInvalid,\n ...props,\n ref,\n value: h,\n onChange: handlerAll(props.onChange, (h) => onChange({ h })),\n onChangeStart: handlerAll(props.onChangeStart, (h) =>\n onChangeStart({ h }),\n ),\n onChangeEnd: handlerAll(props.onChangeEnd, (h) => onChangeEnd({ h })),\n }),\n [\n required,\n disabled,\n readOnly,\n isInvalid,\n h,\n onChange,\n onChangeStart,\n onChangeEnd,\n ],\n )\n\n const getAlphaSliderProps: UIPropGetter<\n \"input\",\n AlphaSliderProps,\n AlphaSliderProps\n > = useCallback(\n (props = {}, ref = null) => ({\n required,\n disabled,\n readOnly,\n isInvalid,\n ...props,\n ref,\n value: a,\n color: hsvTo([h, s, v, a], fallbackValue)(formatRef.current),\n onChange: handlerAll(props.onChange, (a) => onChange({ a })),\n onChangeStart: handlerAll(props.onChangeStart, (a) =>\n onChangeStart({ a }),\n ),\n onChangeEnd: handlerAll(props.onChangeEnd, (a) => onChangeEnd({ a })),\n }),\n [\n fallbackValue,\n required,\n disabled,\n readOnly,\n isInvalid,\n formatRef,\n h,\n s,\n v,\n a,\n onChange,\n onChangeStart,\n onChangeEnd,\n ],\n )\n\n const getChannelProps: RequiredUIPropGetter<\n \"input\",\n Merge<InputProps, { space: Space }>,\n InputProps\n > = useCallback(\n ({ space, ...props }, ref = null) => {\n return {\n required,\n disabled,\n readOnly,\n isInvalid,\n ...props,\n ref,\n type: \"number\",\n step: 1,\n onChange: handlerAll(props.onChange, (ev) =>\n onChannelChange(ev, space),\n ),\n } as Dict\n },\n [required, disabled, readOnly, isInvalid, onChannelChange],\n )\n\n const getEyeDropperProps: UIPropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n disabled,\n \"aria-label\": \"Pick a color\",\n ...props,\n ref,\n onClick: handlerAll(props.onClick, onEyeDropperClick),\n }),\n [disabled, onEyeDropperClick],\n )\n\n const getSwatchProps: UIPropGetter<\n \"div\",\n ColorSwatchProps,\n ColorSwatchProps\n > = useCallback(\n ({ color, ...props } = {}, ref = null) => ({\n \"aria-label\": `Select ${color} as the color`,\n disabled,\n readOnly,\n ...props,\n ref,\n color,\n onClick: handlerAll(props.onClick, () => {\n if (!color) return\n\n onSwatchClick?.(color)\n onChange(color)\n onChangeEnd(color)\n }),\n }),\n [disabled, readOnly, onSwatchClick, onChange, onChangeEnd],\n )\n\n return {\n value: resolvedValue,\n onChange,\n eyeDropperSupported,\n withAlpha,\n isInteractive,\n disabled,\n readOnly,\n channels,\n getContainerProps,\n getInputProps,\n getSaturationSliderProps,\n getHueSliderProps,\n getAlphaSliderProps,\n getEyeDropperProps,\n getChannelProps,\n getSwatchProps,\n }\n}\n\nexport type UseColorSelectorReturn = ReturnType<typeof useColorSelector>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,0BAIO;AAEP,oCAAqC;AACrC,6BAA8B;AAE9B,mBAgBO;AAEP,mBAAuD;AAkBvD,IAAM,cAAc,CAAC,OAAe,aAA4B;AApDhE;AAqDE,MAAI,CAAC,GAAG,GAAG,GAAG,CAAC,KAAI,mCAAY,OAAO,QAAQ,MAA3B,YAAgC,CAAC,GAAG,GAAG,GAAG,CAAC;AAE9D,MAAI,IAAI,EAAG,KAAI;AAEf,SAAO,EAAE,GAAG,GAAG,GAAG,EAAE;AACtB;AAEA,IAAM,cAAc,CAAC,OAAe,aAA4B;AA5DhE;AA6DE,MAAI,CAAC,GAAG,GAAG,G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AA,IACA,CAAC,UAAU,UAAU,UAAU,WAAW,eAAe;AAAA,EAC3D;AAEA,QAAM,yBAA6C;AAAA,IACjD,CAACA,SAAQ,CAAC,GAAG,MAAM,UAAU;AAAA,MAC3B;AAAA,MACA,cAAc;AAAA,MACd,GAAGA;AAAA,MACH;AAAA,MACA,aAAS,yBAAWA,OAAM,SAAS,iBAAiB;AAAA,IACtD;AAAA,IACA,CAAC,UAAU,iBAAiB;AAAA,EAC9B;AAEA,QAAM,qBAIF;AAAA,IACF,CAAC,EAAE,OAAO,GAAGA,OAAM,IAAI,CAAC,GAAG,MAAM,UAAU;AAAA,MACzC,cAAc,UAAU,KAAK;AAAA,MAC7B;AAAA,MACA;AAAA,MACA,GAAGA;AAAA,MACH;AAAA,MACA;AAAA,MACA,aAAS,yBAAWA,OAAM,SAAS,MAAM;AACvC,YAAI,CAAC,MAAO;AAEZ,uDAAgB;AAChB,iBAAS,KAAK;AACd,oBAAY,KAAK;AAAA,MACnB,CAAC;AAAA,IACH;AAAA,IACA,CAAC,UAAU,UAAU,eAAe,UAAU,WAAW;AAAA,EAC3D;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["h","s","a","channels","value","v","props"]}
|
package/dist/use-color-slider.js
CHANGED
@@ -35,8 +35,7 @@ var useColorSlider = ({
|
|
35
35
|
focusThumbOnChange = true,
|
36
36
|
...props
|
37
37
|
}) => {
|
38
|
-
if (!focusThumbOnChange)
|
39
|
-
props.isReadOnly = true;
|
38
|
+
if (!focusThumbOnChange) props.isReadOnly = true;
|
40
39
|
let {
|
41
40
|
id,
|
42
41
|
name,
|
@@ -83,16 +82,14 @@ var useColorSlider = ({
|
|
83
82
|
const getValueFromPointer = (0, import_react.useCallback)(
|
84
83
|
(ev) => {
|
85
84
|
var _a, _b;
|
86
|
-
if (!trackRef.current)
|
87
|
-
return;
|
85
|
+
if (!trackRef.current) return;
|
88
86
|
const { min: min2, max: max2, step: step2 } = latestRef.current;
|
89
87
|
latestRef.current.eventSource = "pointer";
|
90
88
|
const { left, width } = trackRef.current.getBoundingClientRect();
|
91
89
|
const { clientX } = (_b = (_a = ev.touches) == null ? void 0 : _a[0]) != null ? _b : ev;
|
92
90
|
let percent = (clientX - left) / width;
|
93
91
|
let nextValue = (0, import_utils.percentToValue)(percent, min2, max2);
|
94
|
-
if (step2)
|
95
|
-
nextValue = parseFloat((0, import_utils.roundNumberToStep)(nextValue, min2, step2));
|
92
|
+
if (step2) nextValue = parseFloat((0, import_utils.roundNumberToStep)(nextValue, min2, step2));
|
96
93
|
nextValue = (0, import_utils.clampNumber)(nextValue, min2, max2);
|
97
94
|
return nextValue;
|
98
95
|
},
|
@@ -101,22 +98,19 @@ var useColorSlider = ({
|
|
101
98
|
const setValueFromPointer = (ev) => {
|
102
99
|
const { value: value2 } = latestRef.current;
|
103
100
|
const nextValue = getValueFromPointer(ev);
|
104
|
-
if (nextValue != null && nextValue !== value2)
|
105
|
-
setValue(nextValue);
|
101
|
+
if (nextValue != null && nextValue !== value2) setValue(nextValue);
|
106
102
|
};
|
107
103
|
const focusThumb = (0, import_react.useCallback)(() => {
|
108
104
|
const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
|
109
|
-
if (focusThumbOnChange2)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
});
|
105
|
+
if (focusThumbOnChange2) setTimeout(() => {
|
106
|
+
var _a;
|
107
|
+
return (_a = thumbRef.current) == null ? void 0 : _a.focus();
|
108
|
+
});
|
114
109
|
}, [latestRef]);
|
115
110
|
const constrain = (0, import_react.useCallback)(
|
116
111
|
(value2) => {
|
117
112
|
const { isInteractive: isInteractive2, min: min2, max: max2 } = latestRef.current;
|
118
|
-
if (!isInteractive2)
|
119
|
-
return;
|
113
|
+
if (!isInteractive2) return;
|
120
114
|
value2 = parseFloat((0, import_utils.roundNumberToStep)(value2, min2, oneStep));
|
121
115
|
value2 = (0, import_utils.clampNumber)(value2, min2, max2);
|
122
116
|
setValue(value2);
|
@@ -145,8 +139,7 @@ var useColorSlider = ({
|
|
145
139
|
End: () => constrain(max2)
|
146
140
|
};
|
147
141
|
const action = actions[ev.key];
|
148
|
-
if (!action)
|
149
|
-
return;
|
142
|
+
if (!action) return;
|
150
143
|
ev.preventDefault();
|
151
144
|
ev.stopPropagation();
|
152
145
|
action(ev);
|
@@ -157,8 +150,7 @@ var useColorSlider = ({
|
|
157
150
|
(0, import_use_pan_event.usePanEvent)(containerRef, {
|
158
151
|
onSessionStart: (ev) => {
|
159
152
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
160
|
-
if (!isInteractive2)
|
161
|
-
return;
|
153
|
+
if (!isInteractive2) return;
|
162
154
|
setDragging(true);
|
163
155
|
focusThumb();
|
164
156
|
setValueFromPointer(ev);
|
@@ -166,22 +158,19 @@ var useColorSlider = ({
|
|
166
158
|
},
|
167
159
|
onSessionEnd: () => {
|
168
160
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
169
|
-
if (!isInteractive2)
|
170
|
-
return;
|
161
|
+
if (!isInteractive2) return;
|
171
162
|
setDragging(false);
|
172
163
|
onChangeEnd(value2);
|
173
164
|
},
|
174
165
|
onMove: (ev) => {
|
175
166
|
const { isInteractive: isInteractive2 } = latestRef.current;
|
176
|
-
if (!isInteractive2)
|
177
|
-
return;
|
167
|
+
if (!isInteractive2) return;
|
178
168
|
setValueFromPointer(ev);
|
179
169
|
}
|
180
170
|
});
|
181
171
|
(0, import_utils.useUpdateEffect)(() => {
|
182
172
|
const { eventSource, value: value2 } = latestRef.current;
|
183
|
-
if (eventSource === "keyboard")
|
184
|
-
onChangeEnd(value2);
|
173
|
+
if (eventSource === "keyboard") onChangeEnd(value2);
|
185
174
|
}, [value, onChangeEnd]);
|
186
175
|
const getContainerProps = (0, import_react.useCallback)(
|
187
176
|
(props2 = {}, ref = null) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/use-color-slider.ts"],"sourcesContent":["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;AACA,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,EAAE,YAAY;AAEpC,QAAM,UAAU,SAAS,MAAM,OAAO;AACtC,QAAM,WAAW,MAAM,OAAO;AAE9B,QAAM,mBAAe,qBAAoB,IAAI;AAC7C,QAAM,eAAW,qBAAoB,IAAI;AACzC,QAAM,eAAW,q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MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["min","max","step","value","focusThumbOnChange","isInteractive","props"]}
|
1
|
+
{"version":3,"sources":["../src/use-color-slider.ts"],"sourcesContent":["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;AACA,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;AACtC,QAAM,WAAW,MAAM,OAAO;AAE9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AAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["min","max","step","value","focusThumbOnChange","isInteractive","props"]}
|
@@ -51,8 +51,7 @@ var useSaturationSlider = ({
|
|
51
51
|
focusThumbOnChange = true,
|
52
52
|
...props
|
53
53
|
}) => {
|
54
|
-
if (!focusThumbOnChange)
|
55
|
-
props.isReadOnly = true;
|
54
|
+
if (!focusThumbOnChange) props.isReadOnly = true;
|
56
55
|
let {
|
57
56
|
id,
|
58
57
|
name,
|
@@ -100,8 +99,7 @@ var useSaturationSlider = ({
|
|
100
99
|
const getValueFromPointer = (0, import_react.useCallback)(
|
101
100
|
(ev) => {
|
102
101
|
var _a, _b;
|
103
|
-
if (!trackRef.current)
|
104
|
-
return [];
|
102
|
+
if (!trackRef.current) return [];
|
105
103
|
const { step: step2 } = latestRef.current;
|
106
104
|
latestRef.current.eventSource = "pointer";
|
107
105
|
const { bottom, left, height, width } = trackRef.current.getBoundingClientRect();
|
@@ -119,25 +117,21 @@ var useSaturationSlider = ({
|
|
119
117
|
const setValueFromPointer = (ev) => {
|
120
118
|
const { value: value2 } = latestRef.current;
|
121
119
|
const [nextS, nextV] = getValueFromPointer(ev);
|
122
|
-
if (nextS == null || nextV == null)
|
123
|
-
return;
|
120
|
+
if (nextS == null || nextV == null) return;
|
124
121
|
const [, s2, v2] = value2;
|
125
|
-
if (nextS !== s2 || nextV !== v2)
|
126
|
-
setValue(([h2]) => [h2, nextS, nextV]);
|
122
|
+
if (nextS !== s2 || nextV !== v2) setValue(([h2]) => [h2, nextS, nextV]);
|
127
123
|
};
|
128
124
|
const focusThumb = (0, import_react.useCallback)(() => {
|
129
125
|
const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
|
130
|
-
if (focusThumbOnChange2)
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
});
|
126
|
+
if (focusThumbOnChange2) setTimeout(() => {
|
127
|
+
var _a;
|
128
|
+
return (_a = thumbRef.current) == null ? void 0 : _a.focus();
|
129
|
+
});
|
135
130
|
}, [latestRef]);
|
136
131
|
const constrain = (0, import_react.useCallback)(
|
137
132
|
([s2, v2]) => {
|
138
133
|
const { isInteractive: isInteractive2 } = latestRef.current;
|
139
|
-
if (!isInteractive2)
|
140
|
-
return;
|
134
|
+
if (!isInteractive2) return;
|
141
135
|
s2 = (0, import_utils.clampNumber)(s2, 0, 1);
|
142
136
|
v2 = (0, import_utils.clampNumber)(v2, 0, 1);
|
143
137
|
setValue(([h2]) => [h2, s2, v2]);
|
@@ -153,8 +147,7 @@ var useSaturationSlider = ({
|
|
153
147
|
ArrowDown: () => constrain([s, v - step])
|
154
148
|
};
|
155
149
|
const action = actions[ev.key];
|
156
|
-
if (!action)
|
157
|
-
return;
|
150
|
+
if (!action) return;
|
158
151
|
ev.preventDefault();
|
159
152
|
ev.stopPropagation();
|
160
153
|
action(ev);
|
@@ -165,8 +158,7 @@ var useSaturationSlider = ({
|
|
165
158
|
(0, import_use_pan_event.usePanEvent)(containerRef, {
|
166
159
|
onSessionStart: (ev) => {
|
167
160
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
168
|
-
if (!isInteractive2)
|
169
|
-
return;
|
161
|
+
if (!isInteractive2) return;
|
170
162
|
setDragging(true);
|
171
163
|
focusThumb();
|
172
164
|
setValueFromPointer(ev);
|
@@ -174,22 +166,19 @@ var useSaturationSlider = ({
|
|
174
166
|
},
|
175
167
|
onSessionEnd: () => {
|
176
168
|
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
177
|
-
if (!isInteractive2)
|
178
|
-
return;
|
169
|
+
if (!isInteractive2) return;
|
179
170
|
setDragging(false);
|
180
171
|
onChangeEnd(value2);
|
181
172
|
},
|
182
173
|
onMove: (ev) => {
|
183
174
|
const { isInteractive: isInteractive2 } = latestRef.current;
|
184
|
-
if (!isInteractive2)
|
185
|
-
return;
|
175
|
+
if (!isInteractive2) return;
|
186
176
|
setValueFromPointer(ev);
|
187
177
|
}
|
188
178
|
});
|
189
179
|
(0, import_utils.useUpdateEffect)(() => {
|
190
180
|
const { eventSource, value: value2 } = latestRef.current;
|
191
|
-
if (eventSource === "keyboard")
|
192
|
-
onChangeEnd(value2);
|
181
|
+
if (eventSource === "keyboard") onChangeEnd(value2);
|
193
182
|
}, [value, onChangeEnd]);
|
194
183
|
const getContainerProps = (0, import_react.useCallback)(
|
195
184
|
(props2 = {}, ref = null) => ({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/use-saturation-slider.ts"],"sourcesContent":["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 useCallbackRef,\n runIfFunc,\n clampNumber,\n hsvTo,\n roundNumberToStep,\n pickObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { CSSProperties, KeyboardEvent, KeyboardEventHandler } from \"react\"\nimport { useCallback, useMemo, useRef, useState } from \"react\"\n\nexport type Hsv = [number, number, number]\ntype Overlay = HTMLUIProps<\"div\"> | ((value: Hsv) => HTMLUIProps<\"div\">)\n\nconst defaultOverlays = (withShadow: boolean): Overlay[] => {\n let overlays: Overlay[] = [\n ([h]) => ({\n bg: `hsl(${h}, 100%, 50%)`,\n bgImage:\n \"linear-gradient(0deg, #000, transparent), linear-gradient(90deg, #fff, transparent)\",\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 UseSaturationSliderOptions = {\n /**\n * The base `id` to use for the saturation 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 saturation slider.\n */\n value?: Hsv\n /**\n * The initial value of the saturation slider.\n *\n * @default \"[0, 0, 1]\"\n */\n defaultValue?: Hsv\n /**\n * Function called whenever the saturation slider value changes.\n */\n onChange?: (value: Hsv) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: Hsv) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: Hsv) => void\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 0.01\n */\n step?: number\n /**\n * If `false`, the saturation 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 * If `true`, the slider has an inner `box-shadow`.\n *\n * @default true\n */\n withShadow?: boolean\n /**\n * The overlay used for the saturation slider.\n */\n overlays?: Overlay[]\n}\n\nexport type UseSaturationSliderProps = Omit<\n HTMLUIProps<\"div\">,\n \"defaultValue\" | \"onChange\"\n> &\n UseSaturationSliderOptions &\n FormControlOptions\n\nexport const useSaturationSlider = ({\n focusThumbOnChange = true,\n ...props\n}: UseSaturationSliderProps) => {\n if (!focusThumbOnChange) props.isReadOnly = true\n\n let {\n id,\n name,\n value: valueProp,\n defaultValue = [0, 0, 1],\n onChange: onChangeProp,\n onChangeStart: onChangeStartProp,\n onChangeEnd: onChangeEndProp,\n step = 0.01,\n thumbColor,\n required,\n disabled,\n readOnly,\n withShadow = true,\n overlays: overlaysProp = defaultOverlays(withShadow),\n ...rest\n } = useFormControlProps(props)\n\n const onChangeStart = useCallbackRef(onChangeStartProp)\n const onChangeEnd = useCallbackRef(onChangeEndProp)\n\n const [value, setValue] = useControllableState({\n value: valueProp,\n defaultValue,\n onChange: onChangeProp,\n })\n const [isDragging, setDragging] = useState(false)\n const isInteractive = !(disabled || readOnly)\n let [h, s, v] = value\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\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 step,\n isInteractive,\n eventSource: null as \"pointer\" | \"keyboard\" | null,\n focusThumbOnChange,\n })\n\n const thumbSize = useSize(thumbRef)\n\n const overlays = useMemo(\n () => overlaysProp.map((propsOrFunc) => runIfFunc(propsOrFunc, [h, s, v])),\n [overlaysProp, h, s, v],\n )\n\n const getValueFromPointer = useCallback(\n (ev: any) => {\n if (!trackRef.current) return []\n\n const { step } = latestRef.current\n\n latestRef.current.eventSource = \"pointer\"\n\n const { bottom, left, height, width } =\n trackRef.current.getBoundingClientRect()\n const { clientX, clientY } = ev.touches?.[0] ?? ev\n\n let s = clampNumber((clientX - left) / width, 0, 1)\n let v = clampNumber((bottom - clientY) / height, 0, 1)\n\n if (step) {\n s = parseFloat(roundNumberToStep(s, 0, step))\n v = parseFloat(roundNumberToStep(v, 0, step))\n }\n\n return [s, v]\n },\n [latestRef],\n )\n\n const setValueFromPointer = (ev: MouseEvent | TouchEvent | PointerEvent) => {\n const { value } = latestRef.current\n const [nextS, nextV] = getValueFromPointer(ev)\n\n if (nextS == null || nextV == null) return\n\n const [, s, v] = value\n\n if (nextS !== s || nextV !== v) setValue(([h]) => [h, nextS, nextV])\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 ([s, v]: [number, number]) => {\n const { isInteractive } = latestRef.current\n\n if (!isInteractive) return\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\n\n setValue(([h]) => [h, s, v])\n },\n [latestRef, setValue],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n const actions: Record<string, KeyboardEventHandler> = {\n ArrowRight: () => constrain([s + step, v]),\n ArrowUp: () => constrain([s, v + step]),\n ArrowLeft: () => constrain([s - step, v]),\n ArrowDown: () => constrain([s, v - step]),\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 [latestRef, constrain, s, v, step],\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 ...props,\n ...omitObject(rest, [\"aria-readonly\"]),\n ref: mergeRefs(ref, containerRef),\n tabIndex: -1,\n }),\n [rest],\n )\n\n const getInnerProps: 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 padding: `${w / 2}px`,\n }\n\n return {\n ...props,\n ref,\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: [h, s, v].toString(),\n required,\n disabled,\n readOnly,\n }),\n [disabled, id, name, readOnly, required, rest, h, s, v],\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 { width, height } = thumbSize ?? { width: 0, height: 0 }\n const x = s * 100\n const y = v * 100\n\n const style: CSSProperties = {\n ...props.style,\n position: \"absolute\",\n userSelect: \"none\",\n touchAction: \"none\",\n left: `calc(${x}% - ${width / 2}px)`,\n bottom: `calc(${y}% - ${height / 2}px)`,\n }\n\n return {\n \"aria-label\": \"Saturation and brightness thumb\",\n bg: thumbColor ?? hsvTo([h, s, v])(),\n ...pickObject(rest, formControlProperties),\n ...props,\n ref: mergeRefs(ref, thumbRef),\n tabIndex: isInteractive && focusThumbOnChange ? 0 : undefined,\n role: \"slider\",\n \"aria-valuenow\": s,\n \"aria-valuemin\": 0,\n \"aria-valuemax\": 100,\n \"aria-valuetext\": `saturation ${s}, brightness ${v}`,\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 h,\n s,\n v,\n thumbColor,\n focusThumbOnChange,\n isDragging,\n isInteractive,\n onKeyDown,\n rest,\n thumbSize,\n ],\n )\n\n return {\n value,\n overlays,\n getContainerProps,\n getInnerProps,\n getTrackProps,\n getInputProps,\n getThumbProps,\n }\n}\n\nexport type UseSaturationSliderReturn = ReturnType<typeof useSaturationSlider>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAKO;AACP,oCAAqC;AACrC,4BAA6B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AI;AAAA,QACpD,MAAM;AAAA,QACN,iBAAiB;AAAA,QACjB,iBAAiB;AAAA,QACjB,iBAAiB;AAAA,QACjB,kBAAkB,cAAc,CAAC,gBAAgB,CAAC;AAAA,QAClD,mBAAe,uBAAS,cAAc,kBAAkB;AAAA,QACxD,eAAW,yBAAWA,OAAM,WAAW,SAAS;AAAA,QAChD,aAAS,yBAAWA,OAAM,SAAS,KAAK,OAAO;AAAA,QAC/C,YAAQ,yBAAWA,OAAM,QAAQ,KAAK,MAAM;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["step","s","v","value","h","focusThumbOnChange","isInteractive","props"]}
|
1
|
+
{"version":3,"sources":["../src/use-saturation-slider.ts"],"sourcesContent":["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 useCallbackRef,\n runIfFunc,\n clampNumber,\n hsvTo,\n roundNumberToStep,\n pickObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { CSSProperties, KeyboardEvent, KeyboardEventHandler } from \"react\"\nimport { useCallback, useMemo, useRef, useState } from \"react\"\n\nexport type Hsv = [number, number, number]\ntype Overlay = HTMLUIProps<\"div\"> | ((value: Hsv) => HTMLUIProps<\"div\">)\n\nconst defaultOverlays = (withShadow: boolean): Overlay[] => {\n let overlays: Overlay[] = [\n ([h]) => ({\n bg: `hsl(${h}, 100%, 50%)`,\n bgImage:\n \"linear-gradient(0deg, #000, transparent), linear-gradient(90deg, #fff, transparent)\",\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 UseSaturationSliderOptions = {\n /**\n * The base `id` to use for the saturation 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 saturation slider.\n */\n value?: Hsv\n /**\n * The initial value of the saturation slider.\n *\n * @default \"[0, 0, 1]\"\n */\n defaultValue?: Hsv\n /**\n * Function called whenever the saturation slider value changes.\n */\n onChange?: (value: Hsv) => void\n /**\n * Function called when the user starts selecting a new value.\n */\n onChangeStart?: (value: Hsv) => void\n /**\n * Function called when the user is done selecting a new value.\n */\n onChangeEnd?: (value: Hsv) => void\n /**\n * The step in which increments or decrements have to be made.\n *\n * @default 0.01\n */\n step?: number\n /**\n * If `false`, the saturation 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 * If `true`, the slider has an inner `box-shadow`.\n *\n * @default true\n */\n withShadow?: boolean\n /**\n * The overlay used for the saturation slider.\n */\n overlays?: Overlay[]\n}\n\nexport type UseSaturationSliderProps = Omit<\n HTMLUIProps<\"div\">,\n \"defaultValue\" | \"onChange\"\n> &\n UseSaturationSliderOptions &\n FormControlOptions\n\nexport const useSaturationSlider = ({\n focusThumbOnChange = true,\n ...props\n}: UseSaturationSliderProps) => {\n if (!focusThumbOnChange) props.isReadOnly = true\n\n let {\n id,\n name,\n value: valueProp,\n defaultValue = [0, 0, 1],\n onChange: onChangeProp,\n onChangeStart: onChangeStartProp,\n onChangeEnd: onChangeEndProp,\n step = 0.01,\n thumbColor,\n required,\n disabled,\n readOnly,\n withShadow = true,\n overlays: overlaysProp = defaultOverlays(withShadow),\n ...rest\n } = useFormControlProps(props)\n\n const onChangeStart = useCallbackRef(onChangeStartProp)\n const onChangeEnd = useCallbackRef(onChangeEndProp)\n\n const [value, setValue] = useControllableState({\n value: valueProp,\n defaultValue,\n onChange: onChangeProp,\n })\n const [isDragging, setDragging] = useState(false)\n const isInteractive = !(disabled || readOnly)\n let [h, s, v] = value\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\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 step,\n isInteractive,\n eventSource: null as \"pointer\" | \"keyboard\" | null,\n focusThumbOnChange,\n })\n\n const thumbSize = useSize(thumbRef)\n\n const overlays = useMemo(\n () => overlaysProp.map((propsOrFunc) => runIfFunc(propsOrFunc, [h, s, v])),\n [overlaysProp, h, s, v],\n )\n\n const getValueFromPointer = useCallback(\n (ev: any) => {\n if (!trackRef.current) return []\n\n const { step } = latestRef.current\n\n latestRef.current.eventSource = \"pointer\"\n\n const { bottom, left, height, width } =\n trackRef.current.getBoundingClientRect()\n const { clientX, clientY } = ev.touches?.[0] ?? ev\n\n let s = clampNumber((clientX - left) / width, 0, 1)\n let v = clampNumber((bottom - clientY) / height, 0, 1)\n\n if (step) {\n s = parseFloat(roundNumberToStep(s, 0, step))\n v = parseFloat(roundNumberToStep(v, 0, step))\n }\n\n return [s, v]\n },\n [latestRef],\n )\n\n const setValueFromPointer = (ev: MouseEvent | TouchEvent | PointerEvent) => {\n const { value } = latestRef.current\n const [nextS, nextV] = getValueFromPointer(ev)\n\n if (nextS == null || nextV == null) return\n\n const [, s, v] = value\n\n if (nextS !== s || nextV !== v) setValue(([h]) => [h, nextS, nextV])\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 ([s, v]: [number, number]) => {\n const { isInteractive } = latestRef.current\n\n if (!isInteractive) return\n\n s = clampNumber(s, 0, 1)\n v = clampNumber(v, 0, 1)\n\n setValue(([h]) => [h, s, v])\n },\n [latestRef, setValue],\n )\n\n const onKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLElement>) => {\n const actions: Record<string, KeyboardEventHandler> = {\n ArrowRight: () => constrain([s + step, v]),\n ArrowUp: () => constrain([s, v + step]),\n ArrowLeft: () => constrain([s - step, v]),\n ArrowDown: () => constrain([s, v - step]),\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 [latestRef, constrain, s, v, step],\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 ...props,\n ...omitObject(rest, [\"aria-readonly\"]),\n ref: mergeRefs(ref, containerRef),\n tabIndex: -1,\n }),\n [rest],\n )\n\n const getInnerProps: 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 padding: `${w / 2}px`,\n }\n\n return {\n ...props,\n ref,\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: [h, s, v].toString(),\n required,\n disabled,\n readOnly,\n }),\n [disabled, id, name, readOnly, required, rest, h, s, v],\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 { width, height } = thumbSize ?? { width: 0, height: 0 }\n const x = s * 100\n const y = v * 100\n\n const style: CSSProperties = {\n ...props.style,\n position: \"absolute\",\n userSelect: \"none\",\n touchAction: \"none\",\n left: `calc(${x}% - ${width / 2}px)`,\n bottom: `calc(${y}% - ${height / 2}px)`,\n }\n\n return {\n \"aria-label\": \"Saturation and brightness thumb\",\n bg: thumbColor ?? hsvTo([h, s, v])(),\n ...pickObject(rest, formControlProperties),\n ...props,\n ref: mergeRefs(ref, thumbRef),\n tabIndex: isInteractive && focusThumbOnChange ? 0 : undefined,\n role: \"slider\",\n \"aria-valuenow\": s,\n \"aria-valuemin\": 0,\n \"aria-valuemax\": 100,\n \"aria-valuetext\": `saturation ${s}, brightness ${v}`,\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 h,\n s,\n v,\n thumbColor,\n focusThumbOnChange,\n isDragging,\n isInteractive,\n onKeyDown,\n rest,\n thumbSize,\n ],\n )\n\n return {\n value,\n overlays,\n getContainerProps,\n getInnerProps,\n getTrackProps,\n getInputProps,\n getThumbProps,\n }\n}\n\nexport type UseSaturationSliderReturn = ReturnType<typeof useSaturationSlider>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAKO;AACP,oCAAqC;AACrC,4BAA6B;AAC7B,2BAA4B;AAC5B,sBAAwB;AACxB,mBAYO;AAEP,mBAAuD;AAKvD,IAAM,kBAAkB,CAAC,eAAmC;AAC1D,MAAI,WAAsB;AAAA,IACxB,CAAC,CAAC,CAAC,OAAO;AAAA,MACR,IAAI,OAAO,CAAC;AAAA,MACZ,SACE;AAAA,IACJ;AAAA,EACF;AAEA,MAAI;AACF,eAAW;AAAA,MACT,GAAG;AAAA,MACH;AAAA,QACE,WAAW;AAAA,MACb;AAAA,IACF;AAEF,SAAO;AACT;AAqEO,IAAM,sBAAsB,CAAC;AAAA,EAClC,qBAAqB;AAAA,EACrB,GAAG;AACL,MAAgC;AAC9B,MAAI,CAAC,mBAAoB,OAAM,aAAa;AAE5C,MAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,eAAe,CAAC,GAAG,GAAG,CAAC;AAAA,IACvB,UAAU;AAAA,IACV,eAAe;AAAA,IACf,aAAa;AAAA,IACb,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,UAAU,eAAe,gBAAgB,UAAU;AAAA,IACnD,GAAG;AAAA,EACL,QAAI,yCAAoB,KAAK;AAE7B,QAAM,oBAAgB,6BAAe,iBAAiB;AACtD,QAAM,kBAAc,6BAAe,eAAe;AAElD,QAAM,CAAC,OAAO,QAAQ,QAAI,oDAAqB;AAAA,IAC7C,OAAO;AAAA,IACP;AAAA,IACA,UAAU;AAAA,EACZ,CAAC;AACD,QAAM,CAAC,YAAY,WAAW,QAAI,uBAAS,KAAK;AAChD,QAAM,gBAAgB,EAAE,YAAY;AACpC,MAAI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cAAc;AAAA,QACd,IAAI,sCAAc,oBAAM,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE;AAAA,QACnC,OAAG,yBAAW,MAAM,yCAAqB;AAAA,QACzC,GAAGA;AAAA,QACH,SAAK,wBAAU,KAAK,QAAQ;AAAA,QAC5B,UAAU,iBAAiB,qBAAqB,IAAI;AAAA,QACpD,MAAM;AAAA,QACN,iBAAiB;AAAA,QACjB,iBAAiB;AAAA,QACjB,iBAAiB;AAAA,QACjB,kBAAkB,cAAc,CAAC,gBAAgB,CAAC;AAAA,QAClD,mBAAe,uBAAS,cAAc,kBAAkB;AAAA,QACxD,eAAW,yBAAWA,OAAM,WAAW,SAAS;AAAA,QAChD,aAAS,yBAAWA,OAAM,SAAS,KAAK,OAAO;AAAA,QAC/C,YAAQ,yBAAWA,OAAM,QAAQ,KAAK,MAAM;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["step","s","v","value","h","focusThumbOnChange","isInteractive","props"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@yamada-ui/color-picker",
|
3
|
-
"version": "2.0.0-next-
|
3
|
+
"version": "2.0.0-next-20240615233332",
|
4
4
|
"description": "Yamada UI color picker component",
|
5
5
|
"keywords": [
|
6
6
|
"yamada",
|
@@ -36,21 +36,21 @@
|
|
36
36
|
"url": "https://github.com/yamada-ui/yamada-ui/issues"
|
37
37
|
},
|
38
38
|
"dependencies": {
|
39
|
-
"@yamada-ui/button": "2.0.0-next-
|
40
|
-
"@yamada-ui/core": "1.7.
|
41
|
-
"@yamada-ui/form-control": "2.0.0-next-
|
42
|
-
"@yamada-ui/use-disclosure": "1.0.14
|
43
|
-
"@yamada-ui/icon": "1.0.
|
44
|
-
"@yamada-ui/input": "1.0.
|
45
|
-
"@yamada-ui/popover": "2.0.0-next-
|
46
|
-
"@yamada-ui/portal": "1.0.15
|
47
|
-
"@yamada-ui/use-controllable-state": "1.0.14
|
48
|
-
"@yamada-ui/use-eye-dropper": "^1.0.12
|
39
|
+
"@yamada-ui/button": "2.0.0-next-20240615233332",
|
40
|
+
"@yamada-ui/core": "1.7.2",
|
41
|
+
"@yamada-ui/form-control": "2.0.0-next-20240615233332",
|
42
|
+
"@yamada-ui/use-disclosure": "1.0.14",
|
43
|
+
"@yamada-ui/icon": "1.0.28",
|
44
|
+
"@yamada-ui/input": "1.0.34-next-20240615233332",
|
45
|
+
"@yamada-ui/popover": "2.0.0-next-20240615233332",
|
46
|
+
"@yamada-ui/portal": "1.0.15",
|
47
|
+
"@yamada-ui/use-controllable-state": "1.0.14",
|
48
|
+
"@yamada-ui/use-eye-dropper": "^1.0.12",
|
49
49
|
"@yamada-ui/use-latest-ref": "^1.0.1",
|
50
|
-
"@yamada-ui/use-outside-click": "1.0.14
|
51
|
-
"@yamada-ui/use-pan-event": "^1.0.16
|
52
|
-
"@yamada-ui/use-size": "^1.0.14
|
53
|
-
"@yamada-ui/utils": "1.2.1
|
50
|
+
"@yamada-ui/use-outside-click": "1.0.14",
|
51
|
+
"@yamada-ui/use-pan-event": "^1.0.16",
|
52
|
+
"@yamada-ui/use-size": "^1.0.14",
|
53
|
+
"@yamada-ui/utils": "1.2.1"
|
54
54
|
},
|
55
55
|
"devDependencies": {
|
56
56
|
"clean-package": "2.2.0",
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|