@yamada-ui/color-picker 1.4.9-dev-20241109144901 → 1.4.9-dev-20241110143958
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-OJVCLBAG.mjs → chunk-CRZIBBBY.mjs} +4 -2
- package/dist/chunk-CRZIBBBY.mjs.map +1 -0
- package/dist/{chunk-MEG43CIO.mjs → chunk-Z2KAER2U.mjs} +10 -3
- package/dist/chunk-Z2KAER2U.mjs.map +1 -0
- package/dist/color-picker.js +10 -1
- package/dist/color-picker.js.map +1 -1
- package/dist/color-picker.mjs +2 -2
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/use-color-picker.d.mts +1 -0
- package/dist/use-color-picker.d.ts +1 -0
- package/dist/use-color-picker.js +8 -1
- package/dist/use-color-picker.js.map +1 -1
- package/dist/use-color-picker.mjs +1 -1
- package/package.json +7 -7
- package/dist/chunk-MEG43CIO.mjs.map +0 -1
- package/dist/chunk-OJVCLBAG.mjs.map +0 -1
package/dist/index.mjs
CHANGED
@@ -80,6 +80,7 @@ interface UseColorPickerOptions {
|
|
80
80
|
interface UseColorPickerProps extends Omit<HTMLUIProps<"input">, "animation" | "children" | "defaultValue" | "offset" | "onChange" | "size" | "value">, Omit<UseColorSelectorBaseProps, "id" | "name">, ComboBoxProps, Pick<ColorSelectorProps, "swatches" | "swatchesColumns" | "swatchesLabel" | "withChannel" | "withPicker">, UseColorPickerOptions {
|
81
81
|
}
|
82
82
|
declare const useColorPicker: (props: UseColorPickerProps) => {
|
83
|
+
id: string;
|
83
84
|
allowInput: boolean;
|
84
85
|
eyeDropperSupported: boolean;
|
85
86
|
value: string;
|
@@ -80,6 +80,7 @@ interface UseColorPickerOptions {
|
|
80
80
|
interface UseColorPickerProps extends Omit<HTMLUIProps<"input">, "animation" | "children" | "defaultValue" | "offset" | "onChange" | "size" | "value">, Omit<UseColorSelectorBaseProps, "id" | "name">, ComboBoxProps, Pick<ColorSelectorProps, "swatches" | "swatchesColumns" | "swatchesLabel" | "withChannel" | "withPicker">, UseColorPickerOptions {
|
81
81
|
}
|
82
82
|
declare const useColorPicker: (props: UseColorPickerProps) => {
|
83
|
+
id: string;
|
83
84
|
allowInput: boolean;
|
84
85
|
eyeDropperSupported: boolean;
|
85
86
|
value: string;
|
package/dist/use-color-picker.js
CHANGED
@@ -40,7 +40,8 @@ var [ColorPickerProvider, useColorPickerContext] = (0, import_utils.createContex
|
|
40
40
|
errorMessage: `useColorPickerContext returned is 'undefined'. Seems you forgot to wrap the components in "<ColorPicker />"`
|
41
41
|
});
|
42
42
|
var useColorPicker = (props) => {
|
43
|
-
|
43
|
+
let {
|
44
|
+
id,
|
44
45
|
allowInput = true,
|
45
46
|
animation,
|
46
47
|
boundary,
|
@@ -120,6 +121,8 @@ var useColorPicker = (props) => {
|
|
120
121
|
onClose: onCloseProp,
|
121
122
|
onOpen: onOpenProp
|
122
123
|
});
|
124
|
+
const uuid = (0, import_react.useId)();
|
125
|
+
id != null ? id : id = uuid;
|
123
126
|
const onOpen = (0, import_react.useCallback)(() => {
|
124
127
|
if (disabled || readOnly) return;
|
125
128
|
onInternalOpen();
|
@@ -328,6 +331,8 @@ var useColorPicker = (props) => {
|
|
328
331
|
...disabled || !allowInput ? { pointerEvents: "none" } : {}
|
329
332
|
};
|
330
333
|
return {
|
334
|
+
"aria-controls": id,
|
335
|
+
role: "combobox",
|
331
336
|
tabIndex: !allowInput ? -1 : 0,
|
332
337
|
...formControlProps,
|
333
338
|
...inputProps,
|
@@ -339,6 +344,7 @@ var useColorPicker = (props) => {
|
|
339
344
|
};
|
340
345
|
},
|
341
346
|
[
|
347
|
+
id,
|
342
348
|
inputProps,
|
343
349
|
allowInput,
|
344
350
|
disabled,
|
@@ -409,6 +415,7 @@ var useColorPicker = (props) => {
|
|
409
415
|
]
|
410
416
|
);
|
411
417
|
return {
|
418
|
+
id,
|
412
419
|
allowInput,
|
413
420
|
eyeDropperSupported,
|
414
421
|
value,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/use-color-picker.ts"],"sourcesContent":["import type {\n CSSUIObject,\n HTMLUIProps,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { ComboBoxProps, PopoverProps } from \"@yamada-ui/popover\"\nimport type { ColorFormat } from \"@yamada-ui/utils\"\nimport type {\n ChangeEvent,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n} from \"react\"\nimport type { ColorSelectorProps } from \"./color-selector\"\nimport type { UseColorSelectorBaseProps } from \"./use-color-selector\"\nimport { layoutStyleProperties } from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useDisclosure } from \"@yamada-ui/use-disclosure\"\nimport { useEyeDropper } from \"@yamada-ui/use-eye-dropper\"\nimport { useOutsideClick } from \"@yamada-ui/use-outside-click\"\nimport {\n calcFormat,\n convertColor,\n createContext,\n dataAttr,\n getEventRelatedTarget,\n handlerAll,\n isContains,\n mergeRefs,\n pickObject,\n splitObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useRef, useState } from \"react\"\n\nconst defaultFormatInput = (value: string) => value\n\ntype ColorSelectorThemeProps = ThemeProps<\"ColorSelector\">\n\ninterface ColorPickerContext {\n styles: { [key: string]: CSSUIObject | undefined }\n value: string\n}\n\nexport const [ColorPickerProvider, useColorPickerContext] =\n createContext<ColorPickerContext>({\n name: \"ColorPickerContext\",\n errorMessage: `useColorPickerContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ColorPicker />\"`,\n })\n\ninterface UseColorPickerOptions {\n /**\n * If `true`, allows input.\n *\n * @default true\n */\n allowInput?: boolean\n /**\n * If `true`, the color swatch will be closed when value is selected.\n */\n closeOnSelectSwatch?: boolean\n /**\n * ColorScheme for the color selector component.\n */\n colorSelectorColorScheme?: ColorSelectorThemeProps[\"colorScheme\"]\n /**\n * Size for the color selector component.\n */\n colorSelectorSize?: ColorSelectorThemeProps[\"size\"]\n /**\n * Variant for the color selector component.\n */\n colorSelectorVariant?: ColorSelectorThemeProps[\"variant\"]\n /**\n * The initial value of the color selector.\n */\n defaultColor?: string\n /**\n * A callback function to format the input entered.\n */\n formatInput?: (value: string) => string\n /**\n * If `true` display the eye dropper component.\n *\n * @default false\n */\n withColorSelectorEyeDropper?: boolean\n /**\n * If `true`, display the result component.\n *\n * @default false\n */\n withResult?: boolean\n /**\n * Props for color selector component.\n */\n colorSelectorProps?: ColorSelectorProps\n}\n\nexport interface UseColorPickerProps\n extends Omit<\n HTMLUIProps<\"input\">,\n | \"animation\"\n | \"children\"\n | \"defaultValue\"\n | \"offset\"\n | \"onChange\"\n | \"size\"\n | \"value\"\n >,\n Omit<UseColorSelectorBaseProps, \"id\" | \"name\">,\n ComboBoxProps,\n Pick<\n ColorSelectorProps,\n | \"swatches\"\n | \"swatchesColumns\"\n | \"swatchesLabel\"\n | \"withChannel\"\n | \"withPicker\"\n >,\n UseColorPickerOptions {}\n\nexport const useColorPicker = (props: UseColorPickerProps) => {\n const {\n allowInput = true,\n animation,\n boundary,\n closeDelay,\n closeOnBlur = true,\n closeOnEsc = true,\n closeOnSelectSwatch,\n colorSelectorColorScheme,\n colorSelectorSize,\n colorSelectorVariant,\n defaultColor,\n defaultIsOpen,\n defaultValue,\n duration = 0.2,\n eventListeners,\n fallbackValue,\n flip,\n format,\n formatInput = defaultFormatInput,\n gutter,\n isLazy,\n isOpen: isOpenProp,\n lazyBehavior,\n matchWidth = colorSelectorSize === \"full\",\n modifiers,\n offset,\n openDelay,\n placement = \"bottom-start\",\n preventOverflow,\n strategy,\n swatches,\n swatchesColumns,\n swatchesLabel,\n value: valueProp,\n withChannel,\n withColorSelectorEyeDropper = false,\n withPicker,\n withResult = false,\n onChange: onChangeProp,\n onChangeEnd,\n onChangeStart,\n onClick,\n onClose: onCloseProp,\n onKeyDown,\n onOpen: onOpenProp,\n onSwatchClick,\n ...rest\n } = useFormControlProps(props)\n const {\n \"aria-readonly\": _ariaReadonly,\n onBlur,\n onFocus,\n ...formControlProps\n } = pickObject(rest, formControlProperties)\n const { disabled, readOnly } = formControlProps\n const [containerProps, inputProps] = splitObject(rest, layoutStyleProperties)\n\n const containerRef = useRef<HTMLDivElement>(null)\n const fieldRef = useRef<HTMLInputElement>(null)\n\n const { supported: eyeDropperSupported, onOpen: onEyeDropperOpen } =\n useEyeDropper()\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const formatRef = useRef<ColorFormat>(\n format ?? calcFormat(value || defaultColor || \"\"),\n )\n const isInputFocused = useRef<boolean>(false)\n const [inputValue, setInputValue] = useState<string>(value || \"\")\n const {\n isOpen,\n onClose: onInternalClose,\n onOpen: onInternalOpen,\n } = useDisclosure({\n defaultIsOpen,\n isOpen: isOpenProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n\n const onOpen = useCallback(() => {\n if (disabled || readOnly) return\n\n onInternalOpen()\n }, [onInternalOpen, disabled, readOnly])\n\n const onClose = useCallback(() => {\n if (!isOpen) return\n\n const next = convertColor(value, fallbackValue)(formatRef.current)\n\n setValue((prev) => (!next || prev === next ? prev : next))\n setInputValue(formatInput(next ?? \"\"))\n\n onInternalClose()\n }, [\n formatRef,\n isOpen,\n setValue,\n onInternalClose,\n value,\n formatInput,\n setInputValue,\n fallbackValue,\n ])\n\n const onContainerClick = useCallback(() => {\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputFocus = useCallback(() => {\n isInputFocused.current = true\n\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputBlur = useCallback(() => {\n isInputFocused.current = false\n }, [])\n\n const onContainerBlur = useCallback(\n (ev: FocusEvent<HTMLDivElement>) => {\n const relatedTarget = getEventRelatedTarget(ev)\n\n if (isContains(containerRef.current, relatedTarget)) return\n\n if (!closeOnBlur) return\n\n if (isOpen) onClose()\n },\n [closeOnBlur, isOpen, onClose],\n )\n\n const onInputKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (ev.key === \" \") ev.key = ev.code\n\n if (disabled || readOnly) return\n\n const actions: { [key: string]: Function | undefined } = {\n Enter: !isOpen ? onOpen : undefined,\n Escape: closeOnEsc ? onClose : undefined,\n Space: !isOpen ? onOpen : undefined,\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n ev.stopPropagation()\n action()\n },\n [disabled, readOnly, isOpen, onOpen, closeOnEsc, onClose],\n )\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n const value = ev.target.value\n\n setInputValue(formatInput(value))\n setValue(value)\n },\n [setInputValue, formatInput, setValue],\n )\n\n const onColorSelectorChange = useCallback(\n (value: string) => {\n setValue(value)\n\n setTimeout(() => {\n if (!isInputFocused.current) setInputValue(formatInput(value))\n })\n },\n [setValue, formatInput],\n )\n\n const onEyeDropperClick = useCallback(\n async (ev: MouseEvent<HTMLButtonElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n try {\n const { sRGBHex } = (await onEyeDropperOpen()) ?? {}\n\n if (!sRGBHex) return\n\n onColorSelectorChange(sRGBHex)\n onChangeEnd?.(sRGBHex)\n } catch {}\n },\n [onEyeDropperOpen, onColorSelectorChange, onChangeEnd],\n )\n\n useOutsideClick({\n ref: containerRef,\n enabled: isOpen && closeOnBlur,\n handler: onClose,\n })\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) return\n\n setInputValue(formatInput(nextValue))\n setValue(nextValue)\n }, [format])\n\n useUpdateEffect(() => {\n if (isInputFocused.current || !valueProp) return\n\n setInputValue(formatInput(valueProp))\n }, [valueProp])\n\n const getPopoverProps = useCallback(\n (props?: PopoverProps): PopoverProps => ({\n animation,\n boundary,\n closeDelay,\n closeOnBlur,\n duration,\n eventListeners,\n flip,\n gutter,\n isLazy,\n lazyBehavior,\n matchWidth,\n modifiers,\n offset,\n openDelay,\n placement,\n preventOverflow,\n strategy,\n ...props,\n closeOnButton: false,\n isOpen,\n trigger: \"never\",\n onClose,\n onOpen,\n }),\n [\n closeOnBlur,\n openDelay,\n closeDelay,\n isLazy,\n lazyBehavior,\n animation,\n duration,\n offset,\n gutter,\n preventOverflow,\n flip,\n matchWidth,\n boundary,\n eventListeners,\n strategy,\n placement,\n modifiers,\n isOpen,\n onOpen,\n onClose,\n ],\n )\n\n const getContainerProps: PropGetter = useCallback(\n (props = {}, ref = null) => ({\n ref: mergeRefs(containerRef, ref),\n ...containerProps,\n ...props,\n ...formControlProps,\n onBlur: handlerAll(props.onBlur, onBlur, onContainerBlur),\n onClick: handlerAll(props.onClick, onClick, onContainerClick),\n }),\n [\n containerProps,\n formControlProps,\n onBlur,\n onClick,\n onContainerBlur,\n onContainerClick,\n ],\n )\n\n const getFieldProps: PropGetter = useCallback(\n (props = {}, ref = null) => ({\n \"aria-expanded\": dataAttr(isOpen),\n \"data-active\": dataAttr(isOpen),\n \"data-not-allowed\": dataAttr(!readOnly && !disabled && !allowInput),\n tabIndex: !allowInput ? -1 : 0,\n ...formControlProps,\n ...props,\n ref: mergeRefs(fieldRef, ref),\n onBlur: handlerAll(props.onFocus, onInputBlur),\n onFocus: handlerAll(props.onFocus, onFocus, onInputFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown, onInputKeyDown),\n }),\n [\n allowInput,\n formControlProps,\n isOpen,\n readOnly,\n disabled,\n onInputBlur,\n onFocus,\n onInputFocus,\n onKeyDown,\n onInputKeyDown,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n ...props.style,\n ...inputProps.style,\n ...(disabled || !allowInput ? { pointerEvents: \"none\" } : {}),\n }\n\n return {\n tabIndex: !allowInput ? -1 : 0,\n ...formControlProps,\n ...inputProps,\n ...props,\n ref,\n style,\n value: inputValue,\n onChange: handlerAll(props.onChange, onInputChange),\n }\n },\n [\n inputProps,\n allowInput,\n disabled,\n formControlProps,\n inputValue,\n onInputChange,\n ],\n )\n\n const getEyeDropperProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n \"aria-label\": \"Pick a color\",\n disabled,\n ...props,\n ref,\n style: { ...props.style, pointerEvents: readOnly ? \"none\" : undefined },\n onClick: handlerAll(props.onClick, onEyeDropperClick),\n }),\n [disabled, onEyeDropperClick, readOnly],\n )\n\n const getSelectorProps: PropGetter<ColorSelectorProps> = useCallback(\n (props) => ({\n ...formControlProps,\n ...props,\n colorScheme: colorSelectorColorScheme,\n size: colorSelectorSize,\n variant: colorSelectorVariant,\n defaultValue: defaultColor,\n fallbackValue,\n format: formatRef.current,\n swatches,\n swatchesColumns,\n swatchesLabel,\n value,\n withChannel,\n withEyeDropper: withColorSelectorEyeDropper,\n withPicker,\n withResult,\n onChange: onColorSelectorChange,\n onChangeEnd,\n onChangeStart,\n onSwatchClick: handlerAll(\n onSwatchClick,\n closeOnSelectSwatch ? onClose : undefined,\n ),\n }),\n [\n formControlProps,\n value,\n fallbackValue,\n defaultColor,\n onColorSelectorChange,\n onChangeStart,\n onChangeEnd,\n onSwatchClick,\n onClose,\n closeOnSelectSwatch,\n formatRef,\n withPicker,\n withChannel,\n withResult,\n withColorSelectorEyeDropper,\n swatchesLabel,\n swatches,\n swatchesColumns,\n colorSelectorColorScheme,\n colorSelectorSize,\n colorSelectorVariant,\n ],\n )\n\n return {\n allowInput,\n eyeDropperSupported,\n value,\n getContainerProps,\n getEyeDropperProps,\n getFieldProps,\n getInputProps,\n getPopoverProps,\n getSelectorProps,\n onClose,\n }\n}\n\nexport type UseColorPickerReturn = ReturnType<typeof useColorPicker>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,kBAAsC;AACtC,0BAGO;AACP,oCAAqC;AACrC,4BAA8B;AAC9B,6BAA8B;AA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ACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["value","props"]}
|
1
|
+
{"version":3,"sources":["../src/use-color-picker.ts"],"sourcesContent":["import type {\n CSSUIObject,\n HTMLUIProps,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { ComboBoxProps, PopoverProps } from \"@yamada-ui/popover\"\nimport type { ColorFormat } from \"@yamada-ui/utils\"\nimport type {\n ChangeEvent,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n} from \"react\"\nimport type { ColorSelectorProps } from \"./color-selector\"\nimport type { UseColorSelectorBaseProps } from \"./use-color-selector\"\nimport { layoutStyleProperties } from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useDisclosure } from \"@yamada-ui/use-disclosure\"\nimport { useEyeDropper } from \"@yamada-ui/use-eye-dropper\"\nimport { useOutsideClick } from \"@yamada-ui/use-outside-click\"\nimport {\n calcFormat,\n convertColor,\n createContext,\n dataAttr,\n getEventRelatedTarget,\n handlerAll,\n isContains,\n mergeRefs,\n pickObject,\n splitObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useId, useRef, useState } from \"react\"\n\nconst defaultFormatInput = (value: string) => value\n\ntype ColorSelectorThemeProps = ThemeProps<\"ColorSelector\">\n\ninterface ColorPickerContext {\n styles: { [key: string]: CSSUIObject | undefined }\n value: string\n}\n\nexport const [ColorPickerProvider, useColorPickerContext] =\n createContext<ColorPickerContext>({\n name: \"ColorPickerContext\",\n errorMessage: `useColorPickerContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ColorPicker />\"`,\n })\n\ninterface UseColorPickerOptions {\n /**\n * If `true`, allows input.\n *\n * @default true\n */\n allowInput?: boolean\n /**\n * If `true`, the color swatch will be closed when value is selected.\n */\n closeOnSelectSwatch?: boolean\n /**\n * ColorScheme for the color selector component.\n */\n colorSelectorColorScheme?: ColorSelectorThemeProps[\"colorScheme\"]\n /**\n * Size for the color selector component.\n */\n colorSelectorSize?: ColorSelectorThemeProps[\"size\"]\n /**\n * Variant for the color selector component.\n */\n colorSelectorVariant?: ColorSelectorThemeProps[\"variant\"]\n /**\n * The initial value of the color selector.\n */\n defaultColor?: string\n /**\n * A callback function to format the input entered.\n */\n formatInput?: (value: string) => string\n /**\n * If `true` display the eye dropper component.\n *\n * @default false\n */\n withColorSelectorEyeDropper?: boolean\n /**\n * If `true`, display the result component.\n *\n * @default false\n */\n withResult?: boolean\n /**\n * Props for color selector component.\n */\n colorSelectorProps?: ColorSelectorProps\n}\n\nexport interface UseColorPickerProps\n extends Omit<\n HTMLUIProps<\"input\">,\n | \"animation\"\n | \"children\"\n | \"defaultValue\"\n | \"offset\"\n | \"onChange\"\n | \"size\"\n | \"value\"\n >,\n Omit<UseColorSelectorBaseProps, \"id\" | \"name\">,\n ComboBoxProps,\n Pick<\n ColorSelectorProps,\n | \"swatches\"\n | \"swatchesColumns\"\n | \"swatchesLabel\"\n | \"withChannel\"\n | \"withPicker\"\n >,\n UseColorPickerOptions {}\n\nexport const useColorPicker = (props: UseColorPickerProps) => {\n let {\n id,\n allowInput = true,\n animation,\n boundary,\n closeDelay,\n closeOnBlur = true,\n closeOnEsc = true,\n closeOnSelectSwatch,\n colorSelectorColorScheme,\n colorSelectorSize,\n colorSelectorVariant,\n defaultColor,\n defaultIsOpen,\n defaultValue,\n duration = 0.2,\n eventListeners,\n fallbackValue,\n flip,\n format,\n formatInput = defaultFormatInput,\n gutter,\n isLazy,\n isOpen: isOpenProp,\n lazyBehavior,\n matchWidth = colorSelectorSize === \"full\",\n modifiers,\n offset,\n openDelay,\n placement = \"bottom-start\",\n preventOverflow,\n strategy,\n swatches,\n swatchesColumns,\n swatchesLabel,\n value: valueProp,\n withChannel,\n withColorSelectorEyeDropper = false,\n withPicker,\n withResult = false,\n onChange: onChangeProp,\n onChangeEnd,\n onChangeStart,\n onClick,\n onClose: onCloseProp,\n onKeyDown,\n onOpen: onOpenProp,\n onSwatchClick,\n ...rest\n } = useFormControlProps(props)\n const {\n \"aria-readonly\": _ariaReadonly,\n onBlur,\n onFocus,\n ...formControlProps\n } = pickObject(rest, formControlProperties)\n const { disabled, readOnly } = formControlProps\n const [containerProps, inputProps] = splitObject(rest, layoutStyleProperties)\n const containerRef = useRef<HTMLDivElement>(null)\n const fieldRef = useRef<HTMLInputElement>(null)\n const { supported: eyeDropperSupported, onOpen: onEyeDropperOpen } =\n useEyeDropper()\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const formatRef = useRef<ColorFormat>(\n format ?? calcFormat(value || defaultColor || \"\"),\n )\n const isInputFocused = useRef<boolean>(false)\n const [inputValue, setInputValue] = useState<string>(value || \"\")\n const {\n isOpen,\n onClose: onInternalClose,\n onOpen: onInternalOpen,\n } = useDisclosure({\n defaultIsOpen,\n isOpen: isOpenProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n const uuid = useId()\n\n id ??= uuid\n\n const onOpen = useCallback(() => {\n if (disabled || readOnly) return\n\n onInternalOpen()\n }, [onInternalOpen, disabled, readOnly])\n\n const onClose = useCallback(() => {\n if (!isOpen) return\n\n const next = convertColor(value, fallbackValue)(formatRef.current)\n\n setValue((prev) => (!next || prev === next ? prev : next))\n setInputValue(formatInput(next ?? \"\"))\n\n onInternalClose()\n }, [\n formatRef,\n isOpen,\n setValue,\n onInternalClose,\n value,\n formatInput,\n setInputValue,\n fallbackValue,\n ])\n\n const onContainerClick = useCallback(() => {\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputFocus = useCallback(() => {\n isInputFocused.current = true\n\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputBlur = useCallback(() => {\n isInputFocused.current = false\n }, [])\n\n const onContainerBlur = useCallback(\n (ev: FocusEvent<HTMLDivElement>) => {\n const relatedTarget = getEventRelatedTarget(ev)\n\n if (isContains(containerRef.current, relatedTarget)) return\n\n if (!closeOnBlur) return\n\n if (isOpen) onClose()\n },\n [closeOnBlur, isOpen, onClose],\n )\n\n const onInputKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (ev.key === \" \") ev.key = ev.code\n\n if (disabled || readOnly) return\n\n const actions: { [key: string]: Function | undefined } = {\n Enter: !isOpen ? onOpen : undefined,\n Escape: closeOnEsc ? onClose : undefined,\n Space: !isOpen ? onOpen : undefined,\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n ev.stopPropagation()\n action()\n },\n [disabled, readOnly, isOpen, onOpen, closeOnEsc, onClose],\n )\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n const value = ev.target.value\n\n setInputValue(formatInput(value))\n setValue(value)\n },\n [setInputValue, formatInput, setValue],\n )\n\n const onColorSelectorChange = useCallback(\n (value: string) => {\n setValue(value)\n\n setTimeout(() => {\n if (!isInputFocused.current) setInputValue(formatInput(value))\n })\n },\n [setValue, formatInput],\n )\n\n const onEyeDropperClick = useCallback(\n async (ev: MouseEvent<HTMLButtonElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n try {\n const { sRGBHex } = (await onEyeDropperOpen()) ?? {}\n\n if (!sRGBHex) return\n\n onColorSelectorChange(sRGBHex)\n onChangeEnd?.(sRGBHex)\n } catch {}\n },\n [onEyeDropperOpen, onColorSelectorChange, onChangeEnd],\n )\n\n useOutsideClick({\n ref: containerRef,\n enabled: isOpen && closeOnBlur,\n handler: onClose,\n })\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) return\n\n setInputValue(formatInput(nextValue))\n setValue(nextValue)\n }, [format])\n\n useUpdateEffect(() => {\n if (isInputFocused.current || !valueProp) return\n\n setInputValue(formatInput(valueProp))\n }, [valueProp])\n\n const getPopoverProps = useCallback(\n (props?: PopoverProps): PopoverProps => ({\n animation,\n boundary,\n closeDelay,\n closeOnBlur,\n duration,\n eventListeners,\n flip,\n gutter,\n isLazy,\n lazyBehavior,\n matchWidth,\n modifiers,\n offset,\n openDelay,\n placement,\n preventOverflow,\n strategy,\n ...props,\n closeOnButton: false,\n isOpen,\n trigger: \"never\",\n onClose,\n onOpen,\n }),\n [\n closeOnBlur,\n openDelay,\n closeDelay,\n isLazy,\n lazyBehavior,\n animation,\n duration,\n offset,\n gutter,\n preventOverflow,\n flip,\n matchWidth,\n boundary,\n eventListeners,\n strategy,\n placement,\n modifiers,\n isOpen,\n onOpen,\n onClose,\n ],\n )\n\n const getContainerProps: PropGetter = useCallback(\n (props = {}, ref = null) => ({\n ref: mergeRefs(containerRef, ref),\n ...containerProps,\n ...props,\n ...formControlProps,\n onBlur: handlerAll(props.onBlur, onBlur, onContainerBlur),\n onClick: handlerAll(props.onClick, onClick, onContainerClick),\n }),\n [\n containerProps,\n formControlProps,\n onBlur,\n onClick,\n onContainerBlur,\n onContainerClick,\n ],\n )\n\n const getFieldProps: PropGetter = useCallback(\n (props = {}, ref = null) => ({\n \"aria-expanded\": dataAttr(isOpen),\n \"data-active\": dataAttr(isOpen),\n \"data-not-allowed\": dataAttr(!readOnly && !disabled && !allowInput),\n tabIndex: !allowInput ? -1 : 0,\n ...formControlProps,\n ...props,\n ref: mergeRefs(fieldRef, ref),\n onBlur: handlerAll(props.onFocus, onInputBlur),\n onFocus: handlerAll(props.onFocus, onFocus, onInputFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown, onInputKeyDown),\n }),\n [\n allowInput,\n formControlProps,\n isOpen,\n readOnly,\n disabled,\n onInputBlur,\n onFocus,\n onInputFocus,\n onKeyDown,\n onInputKeyDown,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n ...props.style,\n ...inputProps.style,\n ...(disabled || !allowInput ? { pointerEvents: \"none\" } : {}),\n }\n\n return {\n \"aria-controls\": id,\n role: \"combobox\",\n tabIndex: !allowInput ? -1 : 0,\n ...formControlProps,\n ...inputProps,\n ...props,\n ref,\n style,\n value: inputValue,\n onChange: handlerAll(props.onChange, onInputChange),\n }\n },\n [\n id,\n inputProps,\n allowInput,\n disabled,\n formControlProps,\n inputValue,\n onInputChange,\n ],\n )\n\n const getEyeDropperProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n \"aria-label\": \"Pick a color\",\n disabled,\n ...props,\n ref,\n style: { ...props.style, pointerEvents: readOnly ? \"none\" : undefined },\n onClick: handlerAll(props.onClick, onEyeDropperClick),\n }),\n [disabled, onEyeDropperClick, readOnly],\n )\n\n const getSelectorProps: PropGetter<ColorSelectorProps> = useCallback(\n (props) => ({\n ...formControlProps,\n ...props,\n colorScheme: colorSelectorColorScheme,\n size: colorSelectorSize,\n variant: colorSelectorVariant,\n defaultValue: defaultColor,\n fallbackValue,\n format: formatRef.current,\n swatches,\n swatchesColumns,\n swatchesLabel,\n value,\n withChannel,\n withEyeDropper: withColorSelectorEyeDropper,\n withPicker,\n withResult,\n onChange: onColorSelectorChange,\n onChangeEnd,\n onChangeStart,\n onSwatchClick: handlerAll(\n onSwatchClick,\n closeOnSelectSwatch ? onClose : undefined,\n ),\n }),\n [\n formControlProps,\n value,\n fallbackValue,\n defaultColor,\n onColorSelectorChange,\n onChangeStart,\n onChangeEnd,\n onSwatchClick,\n onClose,\n closeOnSelectSwatch,\n formatRef,\n withPicker,\n withChannel,\n withResult,\n withColorSelectorEyeDropper,\n swatchesLabel,\n swatches,\n swatchesColumns,\n colorSelectorColorScheme,\n colorSelectorSize,\n colorSelectorVariant,\n ],\n )\n\n return {\n id,\n allowInput,\n eyeDropperSupported,\n value,\n getContainerProps,\n getEyeDropperProps,\n getFieldProps,\n getInputProps,\n getPopoverProps,\n getSelectorProps,\n onClose,\n }\n}\n\nexport type UseColorPickerReturn = ReturnType<typeof useColorPicker>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,kBAAsC;AACtC,0BAGO;AACP,oCAAqC;AACrC,4BAA8B;AAC9B,6BAA8B;AAC9B,+BAAgC;AAChC,mBAYO;AACP,mBAAqD;AAErD,IAAM,qBAAqB,CAAC,UAAkB;AASvC,IAAM,CAAC,qBAAqB,qBAAqB,QACtD,4BAAkC;AAAA,EAChC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AA0EI,IAAM,iBAAiB,CAAC,UAA+B;AAC5D,MAAI;AAAA,IACF;AAAA,IACA,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,aAAa,sBAAsB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA,8BAA8B;AAAA,IAC9B;AAAA,IACA,aAAa;AAAA,IACb,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,GAAG;AAAA,EACL,QAAI,yCAAoB,KAAK;AAC7B,QAAM;AAAA,IACJ,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,QAAI,yBAAW,MAAM,yCAAqB;AAC1C,QAAM,EAAE,UAAU,SAAS,IAAI;AAC/B,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IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,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,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["value","props"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@yamada-ui/color-picker",
|
3
|
-
"version": "1.4.9-dev-
|
3
|
+
"version": "1.4.9-dev-20241110143958",
|
4
4
|
"description": "Yamada UI color picker component",
|
5
5
|
"keywords": [
|
6
6
|
"yamada",
|
@@ -36,12 +36,12 @@
|
|
36
36
|
"url": "https://github.com/yamada-ui/yamada-ui/issues"
|
37
37
|
},
|
38
38
|
"dependencies": {
|
39
|
-
"@yamada-ui/button": "1.0.
|
40
|
-
"@yamada-ui/core": "1.15.
|
41
|
-
"@yamada-ui/form-control": "2.1.
|
42
|
-
"@yamada-ui/icon": "1.1.
|
43
|
-
"@yamada-ui/input": "1.0.
|
44
|
-
"@yamada-ui/popover": "1.4.
|
39
|
+
"@yamada-ui/button": "1.0.49-dev-20241110143958",
|
40
|
+
"@yamada-ui/core": "1.15.5-dev-20241110143958",
|
41
|
+
"@yamada-ui/form-control": "2.1.7-dev-20241110143958",
|
42
|
+
"@yamada-ui/icon": "1.1.12-dev-20241110143958",
|
43
|
+
"@yamada-ui/input": "1.0.47-dev-20241110143958",
|
44
|
+
"@yamada-ui/popover": "1.4.2-dev-20241110143958",
|
45
45
|
"@yamada-ui/portal": "1.0.24",
|
46
46
|
"@yamada-ui/use-controllable-state": "1.0.23",
|
47
47
|
"@yamada-ui/use-disclosure": "1.1.0",
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/use-color-picker.ts"],"sourcesContent":["import type {\n CSSUIObject,\n HTMLUIProps,\n PropGetter,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { ComboBoxProps, PopoverProps } from \"@yamada-ui/popover\"\nimport type { ColorFormat } from \"@yamada-ui/utils\"\nimport type {\n ChangeEvent,\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n} from \"react\"\nimport type { ColorSelectorProps } from \"./color-selector\"\nimport type { UseColorSelectorBaseProps } from \"./use-color-selector\"\nimport { layoutStyleProperties } from \"@yamada-ui/core\"\nimport {\n formControlProperties,\n useFormControlProps,\n} from \"@yamada-ui/form-control\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport { useDisclosure } from \"@yamada-ui/use-disclosure\"\nimport { useEyeDropper } from \"@yamada-ui/use-eye-dropper\"\nimport { useOutsideClick } from \"@yamada-ui/use-outside-click\"\nimport {\n calcFormat,\n convertColor,\n createContext,\n dataAttr,\n getEventRelatedTarget,\n handlerAll,\n isContains,\n mergeRefs,\n pickObject,\n splitObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useRef, useState } from \"react\"\n\nconst defaultFormatInput = (value: string) => value\n\ntype ColorSelectorThemeProps = ThemeProps<\"ColorSelector\">\n\ninterface ColorPickerContext {\n styles: { [key: string]: CSSUIObject | undefined }\n value: string\n}\n\nexport const [ColorPickerProvider, useColorPickerContext] =\n createContext<ColorPickerContext>({\n name: \"ColorPickerContext\",\n errorMessage: `useColorPickerContext returned is 'undefined'. Seems you forgot to wrap the components in \"<ColorPicker />\"`,\n })\n\ninterface UseColorPickerOptions {\n /**\n * If `true`, allows input.\n *\n * @default true\n */\n allowInput?: boolean\n /**\n * If `true`, the color swatch will be closed when value is selected.\n */\n closeOnSelectSwatch?: boolean\n /**\n * ColorScheme for the color selector component.\n */\n colorSelectorColorScheme?: ColorSelectorThemeProps[\"colorScheme\"]\n /**\n * Size for the color selector component.\n */\n colorSelectorSize?: ColorSelectorThemeProps[\"size\"]\n /**\n * Variant for the color selector component.\n */\n colorSelectorVariant?: ColorSelectorThemeProps[\"variant\"]\n /**\n * The initial value of the color selector.\n */\n defaultColor?: string\n /**\n * A callback function to format the input entered.\n */\n formatInput?: (value: string) => string\n /**\n * If `true` display the eye dropper component.\n *\n * @default false\n */\n withColorSelectorEyeDropper?: boolean\n /**\n * If `true`, display the result component.\n *\n * @default false\n */\n withResult?: boolean\n /**\n * Props for color selector component.\n */\n colorSelectorProps?: ColorSelectorProps\n}\n\nexport interface UseColorPickerProps\n extends Omit<\n HTMLUIProps<\"input\">,\n | \"animation\"\n | \"children\"\n | \"defaultValue\"\n | \"offset\"\n | \"onChange\"\n | \"size\"\n | \"value\"\n >,\n Omit<UseColorSelectorBaseProps, \"id\" | \"name\">,\n ComboBoxProps,\n Pick<\n ColorSelectorProps,\n | \"swatches\"\n | \"swatchesColumns\"\n | \"swatchesLabel\"\n | \"withChannel\"\n | \"withPicker\"\n >,\n UseColorPickerOptions {}\n\nexport const useColorPicker = (props: UseColorPickerProps) => {\n const {\n allowInput = true,\n animation,\n boundary,\n closeDelay,\n closeOnBlur = true,\n closeOnEsc = true,\n closeOnSelectSwatch,\n colorSelectorColorScheme,\n colorSelectorSize,\n colorSelectorVariant,\n defaultColor,\n defaultIsOpen,\n defaultValue,\n duration = 0.2,\n eventListeners,\n fallbackValue,\n flip,\n format,\n formatInput = defaultFormatInput,\n gutter,\n isLazy,\n isOpen: isOpenProp,\n lazyBehavior,\n matchWidth = colorSelectorSize === \"full\",\n modifiers,\n offset,\n openDelay,\n placement = \"bottom-start\",\n preventOverflow,\n strategy,\n swatches,\n swatchesColumns,\n swatchesLabel,\n value: valueProp,\n withChannel,\n withColorSelectorEyeDropper = false,\n withPicker,\n withResult = false,\n onChange: onChangeProp,\n onChangeEnd,\n onChangeStart,\n onClick,\n onClose: onCloseProp,\n onKeyDown,\n onOpen: onOpenProp,\n onSwatchClick,\n ...rest\n } = useFormControlProps(props)\n const {\n \"aria-readonly\": _ariaReadonly,\n onBlur,\n onFocus,\n ...formControlProps\n } = pickObject(rest, formControlProperties)\n const { disabled, readOnly } = formControlProps\n const [containerProps, inputProps] = splitObject(rest, layoutStyleProperties)\n\n const containerRef = useRef<HTMLDivElement>(null)\n const fieldRef = useRef<HTMLInputElement>(null)\n\n const { supported: eyeDropperSupported, onOpen: onEyeDropperOpen } =\n useEyeDropper()\n const [value, setValue] = useControllableState({\n defaultValue,\n value: valueProp,\n onChange: onChangeProp,\n })\n const formatRef = useRef<ColorFormat>(\n format ?? calcFormat(value || defaultColor || \"\"),\n )\n const isInputFocused = useRef<boolean>(false)\n const [inputValue, setInputValue] = useState<string>(value || \"\")\n const {\n isOpen,\n onClose: onInternalClose,\n onOpen: onInternalOpen,\n } = useDisclosure({\n defaultIsOpen,\n isOpen: isOpenProp,\n onClose: onCloseProp,\n onOpen: onOpenProp,\n })\n\n const onOpen = useCallback(() => {\n if (disabled || readOnly) return\n\n onInternalOpen()\n }, [onInternalOpen, disabled, readOnly])\n\n const onClose = useCallback(() => {\n if (!isOpen) return\n\n const next = convertColor(value, fallbackValue)(formatRef.current)\n\n setValue((prev) => (!next || prev === next ? prev : next))\n setInputValue(formatInput(next ?? \"\"))\n\n onInternalClose()\n }, [\n formatRef,\n isOpen,\n setValue,\n onInternalClose,\n value,\n formatInput,\n setInputValue,\n fallbackValue,\n ])\n\n const onContainerClick = useCallback(() => {\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputFocus = useCallback(() => {\n isInputFocused.current = true\n\n if (isOpen) return\n\n onOpen()\n }, [isOpen, onOpen])\n\n const onInputBlur = useCallback(() => {\n isInputFocused.current = false\n }, [])\n\n const onContainerBlur = useCallback(\n (ev: FocusEvent<HTMLDivElement>) => {\n const relatedTarget = getEventRelatedTarget(ev)\n\n if (isContains(containerRef.current, relatedTarget)) return\n\n if (!closeOnBlur) return\n\n if (isOpen) onClose()\n },\n [closeOnBlur, isOpen, onClose],\n )\n\n const onInputKeyDown = useCallback(\n (ev: KeyboardEvent<HTMLInputElement>) => {\n if (ev.key === \" \") ev.key = ev.code\n\n if (disabled || readOnly) return\n\n const actions: { [key: string]: Function | undefined } = {\n Enter: !isOpen ? onOpen : undefined,\n Escape: closeOnEsc ? onClose : undefined,\n Space: !isOpen ? onOpen : undefined,\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n ev.stopPropagation()\n action()\n },\n [disabled, readOnly, isOpen, onOpen, closeOnEsc, onClose],\n )\n\n const onInputChange = useCallback(\n (ev: ChangeEvent<HTMLInputElement>) => {\n const value = ev.target.value\n\n setInputValue(formatInput(value))\n setValue(value)\n },\n [setInputValue, formatInput, setValue],\n )\n\n const onColorSelectorChange = useCallback(\n (value: string) => {\n setValue(value)\n\n setTimeout(() => {\n if (!isInputFocused.current) setInputValue(formatInput(value))\n })\n },\n [setValue, formatInput],\n )\n\n const onEyeDropperClick = useCallback(\n async (ev: MouseEvent<HTMLButtonElement>) => {\n ev.preventDefault()\n ev.stopPropagation()\n\n try {\n const { sRGBHex } = (await onEyeDropperOpen()) ?? {}\n\n if (!sRGBHex) return\n\n onColorSelectorChange(sRGBHex)\n onChangeEnd?.(sRGBHex)\n } catch {}\n },\n [onEyeDropperOpen, onColorSelectorChange, onChangeEnd],\n )\n\n useOutsideClick({\n ref: containerRef,\n enabled: isOpen && closeOnBlur,\n handler: onClose,\n })\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) return\n\n setInputValue(formatInput(nextValue))\n setValue(nextValue)\n }, [format])\n\n useUpdateEffect(() => {\n if (isInputFocused.current || !valueProp) return\n\n setInputValue(formatInput(valueProp))\n }, [valueProp])\n\n const getPopoverProps = useCallback(\n (props?: PopoverProps): PopoverProps => ({\n animation,\n boundary,\n closeDelay,\n closeOnBlur,\n duration,\n eventListeners,\n flip,\n gutter,\n isLazy,\n lazyBehavior,\n matchWidth,\n modifiers,\n offset,\n openDelay,\n placement,\n preventOverflow,\n strategy,\n ...props,\n closeOnButton: false,\n isOpen,\n trigger: \"never\",\n onClose,\n onOpen,\n }),\n [\n closeOnBlur,\n openDelay,\n closeDelay,\n isLazy,\n lazyBehavior,\n animation,\n duration,\n offset,\n gutter,\n preventOverflow,\n flip,\n matchWidth,\n boundary,\n eventListeners,\n strategy,\n placement,\n modifiers,\n isOpen,\n onOpen,\n onClose,\n ],\n )\n\n const getContainerProps: PropGetter = useCallback(\n (props = {}, ref = null) => ({\n ref: mergeRefs(containerRef, ref),\n ...containerProps,\n ...props,\n ...formControlProps,\n onBlur: handlerAll(props.onBlur, onBlur, onContainerBlur),\n onClick: handlerAll(props.onClick, onClick, onContainerClick),\n }),\n [\n containerProps,\n formControlProps,\n onBlur,\n onClick,\n onContainerBlur,\n onContainerClick,\n ],\n )\n\n const getFieldProps: PropGetter = useCallback(\n (props = {}, ref = null) => ({\n \"aria-expanded\": dataAttr(isOpen),\n \"data-active\": dataAttr(isOpen),\n \"data-not-allowed\": dataAttr(!readOnly && !disabled && !allowInput),\n tabIndex: !allowInput ? -1 : 0,\n ...formControlProps,\n ...props,\n ref: mergeRefs(fieldRef, ref),\n onBlur: handlerAll(props.onFocus, onInputBlur),\n onFocus: handlerAll(props.onFocus, onFocus, onInputFocus),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown, onInputKeyDown),\n }),\n [\n allowInput,\n formControlProps,\n isOpen,\n readOnly,\n disabled,\n onInputBlur,\n onFocus,\n onInputFocus,\n onKeyDown,\n onInputKeyDown,\n ],\n )\n\n const getInputProps: PropGetter<\"input\"> = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n ...props.style,\n ...inputProps.style,\n ...(disabled || !allowInput ? { pointerEvents: \"none\" } : {}),\n }\n\n return {\n tabIndex: !allowInput ? -1 : 0,\n ...formControlProps,\n ...inputProps,\n ...props,\n ref,\n style,\n value: inputValue,\n onChange: handlerAll(props.onChange, onInputChange),\n }\n },\n [\n inputProps,\n allowInput,\n disabled,\n formControlProps,\n inputValue,\n onInputChange,\n ],\n )\n\n const getEyeDropperProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n \"aria-label\": \"Pick a color\",\n disabled,\n ...props,\n ref,\n style: { ...props.style, pointerEvents: readOnly ? \"none\" : undefined },\n onClick: handlerAll(props.onClick, onEyeDropperClick),\n }),\n [disabled, onEyeDropperClick, readOnly],\n )\n\n const getSelectorProps: PropGetter<ColorSelectorProps> = useCallback(\n (props) => ({\n ...formControlProps,\n ...props,\n colorScheme: colorSelectorColorScheme,\n size: colorSelectorSize,\n variant: colorSelectorVariant,\n defaultValue: defaultColor,\n fallbackValue,\n format: formatRef.current,\n swatches,\n swatchesColumns,\n swatchesLabel,\n value,\n withChannel,\n withEyeDropper: withColorSelectorEyeDropper,\n withPicker,\n withResult,\n onChange: onColorSelectorChange,\n onChangeEnd,\n onChangeStart,\n onSwatchClick: handlerAll(\n onSwatchClick,\n closeOnSelectSwatch ? onClose : undefined,\n ),\n }),\n [\n formControlProps,\n value,\n fallbackValue,\n defaultColor,\n onColorSelectorChange,\n onChangeStart,\n onChangeEnd,\n onSwatchClick,\n onClose,\n closeOnSelectSwatch,\n formatRef,\n withPicker,\n withChannel,\n withResult,\n withColorSelectorEyeDropper,\n swatchesLabel,\n swatches,\n swatchesColumns,\n colorSelectorColorScheme,\n colorSelectorSize,\n colorSelectorVariant,\n ],\n )\n\n return {\n allowInput,\n eyeDropperSupported,\n value,\n getContainerProps,\n getEyeDropperProps,\n getFieldProps,\n getInputProps,\n getPopoverProps,\n getSelectorProps,\n onClose,\n }\n}\n\nexport type UseColorPickerReturn = ReturnType<typeof useColorPicker>\n"],"mappings":";;;AAiBA,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,E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AAAA,MACA;AAAA,MACA;AAAA,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,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["value","props"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/color-picker.tsx"],"sourcesContent":["import type { CSSUIObject, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { PortalProps } from \"@yamada-ui/portal\"\nimport type { FC, ReactNode, RefAttributes } from \"react\"\nimport type { ColorSelectorProps } from \"./color-selector\"\nimport type { ColorSwatchProps } from \"./color-swatch\"\nimport type { UseColorPickerProps } from \"./use-color-picker\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport { Popover, PopoverContent, PopoverTrigger } from \"@yamada-ui/popover\"\nimport { Portal } from \"@yamada-ui/portal\"\nimport {\n cx,\n getValidChildren,\n isValidElement,\n mergeRefs,\n runIfFunc,\n} from \"@yamada-ui/utils\"\nimport { cloneElement } from \"react\"\nimport { ColorSelector } from \"./color-selector\"\nimport { EyeDropperIcon } from \"./color-selector-eye-dropper\"\nimport { ColorSwatch } from \"./color-swatch\"\nimport {\n ColorPickerProvider,\n useColorPicker,\n useColorPickerContext,\n} from \"./use-color-picker\"\n\ninterface ColorPickerOptions {\n children?: FC<{ value: string; onClose: () => void }> | ReactNode\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: string\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: string\n /**\n * If `true`, display the eye dropper component.\n *\n * @default true\n */\n withEyeDropper?: boolean\n /**\n * If `true`, display the color swatch component.\n *\n * @default true\n */\n withSwatch?: boolean\n /**\n * Props for color picker container element.\n */\n containerProps?: Omit<HTMLUIProps, \"children\">\n /**\n * Props for color eye dropper component.\n */\n eyeDropperProps?: ColorPickerEyeDropperProps\n /**\n * Props for color picker field element.\n */\n fieldProps?: Omit<ColorPickerFieldProps, \"children\" | \"inputProps\">\n /**\n * Props for color picker input element.\n */\n inputProps?: HTMLUIProps<\"input\">\n /**\n * Props to be forwarded to the portal component.\n *\n * @default '{ isDisabled: true }'\n */\n portalProps?: Omit<PortalProps, \"children\">\n /**\n * Props for color swatch component.\n */\n swatchProps?: ColorPickerSwatchProps\n}\n\nexport interface ColorPickerProps\n extends ThemeProps<\"ColorPicker\">,\n UseColorPickerProps,\n ColorPickerOptions,\n Pick<\n ColorSelectorProps,\n | \"alphaSliderProps\"\n | \"alphaSliderRef\"\n | \"channelProps\"\n | \"channelsProps\"\n | \"hueSliderProps\"\n | \"hueSliderRef\"\n | \"saturationSliderProps\"\n | \"saturationSliderRef\"\n | \"swatchesProps\"\n > {}\n\n/**\n * `ColorPicker` is a component used by the user to select a color or enter an arbitrary color value.\n *\n * @see Docs https://yamada-ui.com/components/forms/color-picker\n */\nexport const ColorPicker = forwardRef<ColorPickerProps, \"input\">(\n ({ withSwatch = true, ...props }, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"ColorPicker\", {\n withSwatch,\n ...props,\n })\n let {\n className,\n alphaSliderRef,\n children,\n color,\n h,\n height,\n hueSliderRef,\n minH,\n minHeight,\n saturationSliderRef,\n withEyeDropper = true,\n alphaSliderProps,\n channelProps,\n channelsProps,\n containerProps,\n eyeDropperProps,\n fieldProps,\n hueSliderProps,\n inputProps,\n portalProps = { isDisabled: true },\n saturationSliderProps,\n swatchesProps,\n swatchProps,\n ...computedProps\n } = omitThemeProps(mergedProps, [\"withSwatch\"])\n const {\n eyeDropperSupported,\n value,\n getContainerProps,\n getEyeDropperProps,\n getFieldProps,\n getInputProps,\n getPopoverProps,\n getSelectorProps,\n onClose,\n ...rest\n } = useColorPicker(computedProps)\n\n h ??= height\n minH ??= minHeight\n\n const css: CSSUIObject = {\n color,\n h: \"fit-content\",\n w: \"100%\",\n ...styles.container,\n }\n\n return (\n <ColorPickerProvider value={{ styles, value, ...rest }}>\n <Popover {...getPopoverProps()}>\n <ui.div\n className={cx(\"ui-color-picker\", className)}\n __css={css}\n {...getContainerProps(containerProps)}\n >\n <ui.div\n className=\"ui-color-picker__inner\"\n __css={{\n position: \"relative\",\n ...styles.inner,\n }}\n >\n {withSwatch ? <ColorPickerSwatch {...swatchProps} /> : null}\n\n <ColorPickerField\n h={h}\n minH={minH}\n {...getFieldProps(fieldProps, ref)}\n inputProps={getInputProps(inputProps)}\n />\n\n {eyeDropperSupported && withEyeDropper ? (\n <ColorPickerEyeDropper\n {...getEyeDropperProps(eyeDropperProps)}\n />\n ) : null}\n </ui.div>\n\n <Portal {...portalProps}>\n <PopoverContent\n className=\"ui-color-picker__content\"\n __css={{ ...styles.content }}\n >\n <ColorSelector\n className=\"ui-color-picker__picker\"\n {...getSelectorProps({\n alphaSliderRef,\n hueSliderRef,\n saturationSliderRef,\n alphaSliderProps,\n channelProps,\n channelsProps,\n hueSliderProps,\n saturationSliderProps,\n swatchesProps,\n })}\n >\n {runIfFunc(children, { value, onClose })}\n </ColorSelector>\n </PopoverContent>\n </Portal>\n </ui.div>\n </Popover>\n </ColorPickerProvider>\n )\n },\n)\n\nColorPicker.displayName = \"ColorPicker\"\nColorPicker.__ui__ = \"ColorPicker\"\n\ninterface ColorPickerFieldOptions {\n inputProps?: HTMLUIProps<\"input\"> & RefAttributes<HTMLInputElement>\n}\n\ninterface ColorPickerFieldProps extends HTMLUIProps, ColorPickerFieldOptions {}\n\nconst ColorPickerField = forwardRef<ColorPickerFieldProps, \"input\">(\n ({ className, h, minH, inputProps, ...rest }, ref) => {\n const { styles } = useColorPickerContext()\n const { ref: inputRef, ...computedInputProps } = inputProps ?? {}\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n display: \"flex\",\n h,\n minH,\n pe: \"2rem\",\n ps: \"2rem\",\n ...styles.field,\n }\n\n return (\n <PopoverTrigger>\n <ui.div\n className={cx(\"ui-color-picker__field\", className)}\n __css={css}\n {...rest}\n >\n <ui.input\n ref={mergeRefs(ref, inputRef)}\n className=\"ui-color-picker-picker__field__input\"\n display=\"inline-block\"\n w=\"100%\"\n {...computedInputProps}\n />\n </ui.div>\n </PopoverTrigger>\n )\n },\n)\n\nColorPickerField.displayName = \"ColorPickerField\"\nColorPickerField.__ui__ = \"ColorPickerField\"\n\ninterface ColorPickerSwatchProps extends ColorSwatchProps {}\n\nconst ColorPickerSwatch = forwardRef<ColorPickerSwatchProps, \"div\">(\n ({ className, ...rest }, ref) => {\n const { styles, value } = useColorPickerContext()\n\n const css: CSSUIObject = {\n position: \"absolute\",\n top: \"50%\",\n transform: \"translateY(-50%)\",\n zIndex: 1,\n ...styles.swatch,\n }\n\n return (\n <ColorSwatch\n ref={ref}\n className={cx(\"ui-color-picker__swatch\", className)}\n color={value}\n isRounded\n __css={css}\n {...rest}\n />\n )\n },\n)\n\nColorPickerSwatch.displayName = \"ColorPickerSwatch\"\nColorPickerSwatch.__ui__ = \"ColorPickerSwatch\"\n\ninterface ColorPickerEyeDropperProps extends HTMLUIProps<\"button\"> {}\n\nconst ColorPickerEyeDropper = forwardRef<ColorPickerEyeDropperProps, \"button\">(\n ({ className, children, ...rest }, ref) => {\n const { styles } = useColorPickerContext()\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n display: \"inline-flex\",\n justifyContent: \"center\",\n position: \"absolute\",\n top: \"50%\",\n transform: \"translateY(-50%)\",\n zIndex: 1,\n ...styles.eyeDropper,\n }\n\n const validChildren = getValidChildren(children)\n\n const cloneChildren = validChildren.map((child) =>\n cloneElement(child, {\n style: {\n color: \"currentColor\",\n maxHeight: \"1em\",\n maxWidth: \"1em\",\n },\n \"aria-hidden\": true,\n focusable: false,\n }),\n )\n\n return (\n <ui.button\n ref={ref}\n className={cx(\"ui-color-picker__eye-dropper\", className)}\n __css={css}\n {...rest}\n >\n {isValidElement(children) ? (\n cloneChildren\n ) : (\n <EyeDropperIcon className=\"ui-color-picker__eye-dropper__icon\" />\n )}\n </ui.button>\n )\n },\n)\n\nColorPickerEyeDropper.displayName = \"ColorPickerEyeDropper\"\nColorPickerEyeDropper.__ui__ = \"ColorPickerEyeDropper\"\n"],"mappings":";;;;;;;;;;;;;;;;;AAMA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,gBAAgB,sBAAsB;AACxD,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAiJjB,SAOgB,KAPhB;AA/DL,IAAM,cAAc;AAAA,EACzB,CAAC,EAAE,aAAa,MAAM,GAAG,MAAM,GAAG,QAAQ;AACxC,UAAM,CAAC,QAAQ,WAAW,IAAI,uBAAuB,eAAe;AAAA,MAClE;AAAA,MACA,GAAG;AAAA,IACL,CAAC;AACD,QAAI;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,iBAAiB;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc,EAAE,YAAY,KAAK;AAAA,MACjC;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,IAAI,eAAe,aAAa,CAAC,YAAY,CAAC;AAC9C,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,IAAI,eAAe,aAAa;AAEhC,wBAAM;AACN,iCAAS;AAET,UAAM,MAAmB;AAAA,MACvB;AAAA,MACA,GAAG;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