@yamada-ui/color-picker 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/alpha-slider.d.mts +62 -0
- package/dist/alpha-slider.d.ts +62 -0
- package/dist/alpha-slider.js +438 -0
- package/dist/alpha-slider.mjs +8 -0
- package/dist/chunk-3EO2XBIZ.mjs +54 -0
- package/dist/chunk-3KASGDAY.mjs +122 -0
- package/dist/chunk-3N443XSV.mjs +105 -0
- package/dist/chunk-73BVTMII.mjs +73 -0
- package/dist/chunk-7QGCTVDG.mjs +66 -0
- package/dist/chunk-DTB2Z3IJ.mjs +278 -0
- package/dist/chunk-EMWFECJD.mjs +123 -0
- package/dist/chunk-HNVFOSAM.mjs +210 -0
- package/dist/chunk-KJS52X4M.mjs +330 -0
- package/dist/chunk-MAHWFXUG.mjs +294 -0
- package/dist/chunk-N2GG5L7Q.mjs +39 -0
- package/dist/chunk-NR2XCTSD.mjs +430 -0
- package/dist/chunk-PTTNJPGJ.mjs +98 -0
- package/dist/chunk-PVWIBTBL.mjs +67 -0
- package/dist/chunk-TFQ62YSQ.mjs +68 -0
- package/dist/chunk-U6OJ4TDG.mjs +127 -0
- package/dist/color-input.d.mts +79 -0
- package/dist/color-input.d.ts +79 -0
- package/dist/color-input.js +2283 -0
- package/dist/color-input.mjs +21 -0
- package/dist/color-picker-body.d.mts +38 -0
- package/dist/color-picker-body.d.ts +38 -0
- package/dist/color-picker-body.js +794 -0
- package/dist/color-picker-body.mjs +14 -0
- package/dist/color-picker-channels.d.mts +20 -0
- package/dist/color-picker-channels.d.ts +20 -0
- package/dist/color-picker-channels.js +101 -0
- package/dist/color-picker-channels.mjs +10 -0
- package/dist/color-picker-eye-dropper.d.mts +10 -0
- package/dist/color-picker-eye-dropper.d.ts +10 -0
- package/dist/color-picker-eye-dropper.js +88 -0
- package/dist/color-picker-eye-dropper.mjs +10 -0
- package/dist/color-picker-sliders.d.mts +30 -0
- package/dist/color-picker-sliders.d.ts +30 -0
- package/dist/color-picker-sliders.js +590 -0
- package/dist/color-picker-sliders.mjs +11 -0
- package/dist/color-picker-swatches.d.mts +34 -0
- package/dist/color-picker-swatches.d.ts +34 -0
- package/dist/color-picker-swatches.js +195 -0
- package/dist/color-picker-swatches.mjs +9 -0
- package/dist/color-picker.d.mts +59 -0
- package/dist/color-picker.d.ts +59 -0
- package/dist/color-picker.js +1790 -0
- package/dist/color-picker.mjs +19 -0
- package/dist/color-swatch.d.mts +36 -0
- package/dist/color-swatch.d.ts +36 -0
- package/dist/color-swatch.js +124 -0
- package/dist/color-swatch.mjs +6 -0
- package/dist/hue-slider.d.mts +56 -0
- package/dist/hue-slider.d.ts +56 -0
- package/dist/hue-slider.js +409 -0
- package/dist/hue-slider.mjs +8 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +2295 -0
- package/dist/index.mjs +36 -0
- package/dist/saturation-slider.d.mts +33 -0
- package/dist/saturation-slider.d.ts +33 -0
- package/dist/saturation-slider.js +414 -0
- package/dist/saturation-slider.mjs +7 -0
- package/dist/use-color-input.d.mts +90 -0
- package/dist/use-color-input.d.ts +90 -0
- package/dist/use-color-input.js +340 -0
- package/dist/use-color-input.mjs +10 -0
- package/dist/use-color-picker.d.mts +131 -0
- package/dist/use-color-picker.d.ts +131 -0
- package/dist/use-color-picker.js +472 -0
- package/dist/use-color-picker.mjs +11 -0
- package/dist/use-color-slider.d.mts +69 -0
- package/dist/use-color-slider.d.ts +69 -0
- package/dist/use-color-slider.js +321 -0
- package/dist/use-color-slider.mjs +7 -0
- package/dist/use-saturation-slider.d.mts +77 -0
- package/dist/use-saturation-slider.d.ts +77 -0
- package/dist/use-saturation-slider.js +302 -0
- package/dist/use-saturation-slider.mjs +6 -0
- package/package.json +88 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { HTMLUIProps, UIPropGetter, CSSUIObject, ThemeProps } from '@yamada-ui/core';
|
|
3
|
+
import { PopoverProps } from '@yamada-ui/popover';
|
|
4
|
+
import { ColorPickerProps } from './color-picker.js';
|
|
5
|
+
import { UseColorPickerBaseProps } from './use-color-picker.js';
|
|
6
|
+
import './color-picker-body.js';
|
|
7
|
+
import './color-picker-eye-dropper.js';
|
|
8
|
+
import '@yamada-ui/button';
|
|
9
|
+
import '@yamada-ui/icon';
|
|
10
|
+
import './color-picker-sliders.js';
|
|
11
|
+
import './alpha-slider.js';
|
|
12
|
+
import './use-color-slider.js';
|
|
13
|
+
import '@yamada-ui/form-control';
|
|
14
|
+
import './hue-slider.js';
|
|
15
|
+
import './color-picker-swatches.js';
|
|
16
|
+
import './color-swatch.js';
|
|
17
|
+
import './saturation-slider.js';
|
|
18
|
+
import './use-saturation-slider.js';
|
|
19
|
+
import '@yamada-ui/input';
|
|
20
|
+
import '@yamada-ui/utils';
|
|
21
|
+
|
|
22
|
+
type ColorPickerThemeProps = ThemeProps<"ColorPicker">;
|
|
23
|
+
type ColorInputContext = {
|
|
24
|
+
value: string;
|
|
25
|
+
styles: Record<string, CSSUIObject>;
|
|
26
|
+
};
|
|
27
|
+
declare const ColorInputProvider: react.Provider<ColorInputContext>;
|
|
28
|
+
declare const useColorInputContext: () => ColorInputContext;
|
|
29
|
+
type UseColorInputOptions = {
|
|
30
|
+
/**
|
|
31
|
+
* The initial value of the color picker.
|
|
32
|
+
*/
|
|
33
|
+
defaultColor?: string;
|
|
34
|
+
/**
|
|
35
|
+
* If `true`, allows input.
|
|
36
|
+
*
|
|
37
|
+
* @default true
|
|
38
|
+
*/
|
|
39
|
+
allowInput?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* A callback function to format the input entered.
|
|
42
|
+
*/
|
|
43
|
+
formatInput?: (value: string) => string;
|
|
44
|
+
/**
|
|
45
|
+
* If `true`, display the result component.
|
|
46
|
+
*
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
withResult?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* If `true` display the eye dropper component.
|
|
52
|
+
*
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
withColorPickerEyeDropper?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* If `true`, the color swatch will be closed when value is selected.
|
|
58
|
+
*/
|
|
59
|
+
closeOnSelectSwatch?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Variant for the color picker component.
|
|
62
|
+
*/
|
|
63
|
+
colorPickerVariant?: ColorPickerThemeProps["variant"];
|
|
64
|
+
/**
|
|
65
|
+
* Size for the color picker component.
|
|
66
|
+
*/
|
|
67
|
+
colorPickerSize?: ColorPickerThemeProps["size"];
|
|
68
|
+
/**
|
|
69
|
+
* ColorScheme for the color picker component.
|
|
70
|
+
*/
|
|
71
|
+
colorPickerColorScheme?: ColorPickerThemeProps["colorScheme"];
|
|
72
|
+
/**
|
|
73
|
+
* Props for color picker component.
|
|
74
|
+
*/
|
|
75
|
+
colorPickerProps?: ColorPickerProps;
|
|
76
|
+
};
|
|
77
|
+
type UseColorInputProps = Omit<HTMLUIProps<"input">, "size" | "offset" | "value" | "defaultValue" | "onChange"> & Omit<UseColorPickerBaseProps, "id" | "name"> & Omit<PopoverProps, "initialFocusRef" | "closeOnButton" | "isOpen" | "trigger" | "autoFocus" | "restoreFocus" | "openDelay" | "closeDelay"> & Pick<ColorPickerProps, "withPicker" | "withChannel" | "swatchesLabel" | "swatches" | "swatchesColumns"> & UseColorInputOptions;
|
|
78
|
+
declare const useColorInput: ({ value: valueProp, defaultValue, fallbackValue, defaultColor, onChange: onChangeProp, onChangeStart, onChangeEnd, onSwatchClick, formatInput, closeOnBlur, closeOnEsc, placement, duration, defaultIsOpen, onOpen: onOpenProp, onClose: onCloseProp, allowInput, closeOnSelectSwatch, format, swatchesLabel, swatches, swatchesColumns, withPicker, withChannel, withResult, withColorPickerEyeDropper, colorPickerVariant, colorPickerSize, colorPickerColorScheme, ...rest }: UseColorInputProps) => {
|
|
79
|
+
value: string;
|
|
80
|
+
eyeDropperSupported: boolean;
|
|
81
|
+
allowInput: boolean;
|
|
82
|
+
getPopoverProps: (props?: PopoverProps) => PopoverProps;
|
|
83
|
+
getContainerProps: UIPropGetter;
|
|
84
|
+
getFieldProps: UIPropGetter<"input">;
|
|
85
|
+
getPickerProps: (props?: ColorPickerProps) => ColorPickerProps;
|
|
86
|
+
getEyeDropperProps: UIPropGetter<"button">;
|
|
87
|
+
};
|
|
88
|
+
type UseColorInputReturn = ReturnType<typeof useColorInput>;
|
|
89
|
+
|
|
90
|
+
export { ColorInputProvider, type UseColorInputProps, type UseColorInputReturn, useColorInput, useColorInputContext };
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/use-color-input.ts
|
|
21
|
+
var use_color_input_exports = {};
|
|
22
|
+
__export(use_color_input_exports, {
|
|
23
|
+
ColorInputProvider: () => ColorInputProvider,
|
|
24
|
+
useColorInput: () => useColorInput,
|
|
25
|
+
useColorInputContext: () => useColorInputContext
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(use_color_input_exports);
|
|
28
|
+
var import_core = require("@yamada-ui/core");
|
|
29
|
+
var import_form_control = require("@yamada-ui/form-control");
|
|
30
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
31
|
+
var import_use_eye_dropper = require("@yamada-ui/use-eye-dropper");
|
|
32
|
+
var import_use_outside_click = require("@yamada-ui/use-outside-click");
|
|
33
|
+
var import_utils = require("@yamada-ui/utils");
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var [ColorInputProvider, useColorInputContext] = (0, import_utils.createContext)({
|
|
36
|
+
name: "ColorInputContext",
|
|
37
|
+
errorMessage: `useColorInputContext returned is 'undefined'. Seems you forgot to wrap the components in "<ColorInput />"`
|
|
38
|
+
});
|
|
39
|
+
var useColorInput = ({
|
|
40
|
+
value: valueProp,
|
|
41
|
+
defaultValue,
|
|
42
|
+
fallbackValue,
|
|
43
|
+
defaultColor,
|
|
44
|
+
onChange: onChangeProp,
|
|
45
|
+
onChangeStart,
|
|
46
|
+
onChangeEnd,
|
|
47
|
+
onSwatchClick,
|
|
48
|
+
formatInput = (value) => value,
|
|
49
|
+
closeOnBlur = true,
|
|
50
|
+
closeOnEsc = true,
|
|
51
|
+
placement = "bottom-start",
|
|
52
|
+
duration = 0.2,
|
|
53
|
+
defaultIsOpen,
|
|
54
|
+
onOpen: onOpenProp,
|
|
55
|
+
onClose: onCloseProp,
|
|
56
|
+
allowInput = true,
|
|
57
|
+
closeOnSelectSwatch,
|
|
58
|
+
format,
|
|
59
|
+
swatchesLabel,
|
|
60
|
+
swatches,
|
|
61
|
+
swatchesColumns,
|
|
62
|
+
withPicker,
|
|
63
|
+
withChannel,
|
|
64
|
+
withResult = false,
|
|
65
|
+
withColorPickerEyeDropper = false,
|
|
66
|
+
colorPickerVariant,
|
|
67
|
+
colorPickerSize,
|
|
68
|
+
colorPickerColorScheme,
|
|
69
|
+
...rest
|
|
70
|
+
}) => {
|
|
71
|
+
rest = (0, import_form_control.useFormControlProps)(rest);
|
|
72
|
+
const formControlProps = (0, import_utils.pickObject)(
|
|
73
|
+
rest,
|
|
74
|
+
(0, import_form_control.getFormControlProperties)({ omit: ["aria-readonly"] })
|
|
75
|
+
);
|
|
76
|
+
const { disabled, readOnly } = formControlProps;
|
|
77
|
+
const computedProps = (0, import_utils.splitObject)(rest, import_core.layoutStyleProperties);
|
|
78
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
79
|
+
const fieldRef = (0, import_react.useRef)(null);
|
|
80
|
+
const { supported: eyeDropperSupported, onOpen: onEyeDropperOpen } = (0, import_use_eye_dropper.useEyeDropper)();
|
|
81
|
+
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
82
|
+
value: valueProp,
|
|
83
|
+
defaultValue,
|
|
84
|
+
onChange: onChangeProp
|
|
85
|
+
});
|
|
86
|
+
const formatRef = (0, import_react.useRef)(format != null ? format : (0, import_utils.calcFormat)(value != null ? value : ""));
|
|
87
|
+
const isInputFocused = (0, import_react.useRef)(false);
|
|
88
|
+
const [inputValue, setInputValue] = (0, import_react.useState)(value != null ? value : "");
|
|
89
|
+
const [isOpen, setIsOpen] = (0, import_react.useState)(defaultIsOpen != null ? defaultIsOpen : false);
|
|
90
|
+
const isColorPickerFull = colorPickerSize === "full";
|
|
91
|
+
const onOpen = (0, import_react.useCallback)(() => {
|
|
92
|
+
if (disabled || readOnly)
|
|
93
|
+
return;
|
|
94
|
+
setIsOpen(true);
|
|
95
|
+
onOpenProp == null ? void 0 : onOpenProp();
|
|
96
|
+
}, [onOpenProp, disabled, readOnly]);
|
|
97
|
+
const onClose = (0, import_react.useCallback)(() => {
|
|
98
|
+
if (!isOpen)
|
|
99
|
+
return;
|
|
100
|
+
const next = (0, import_utils.convertColor)(value, fallbackValue)(formatRef.current);
|
|
101
|
+
setValue((prev) => !next || prev === next ? prev : next);
|
|
102
|
+
setInputValue(formatInput(next != null ? next : ""));
|
|
103
|
+
setIsOpen(false);
|
|
104
|
+
onCloseProp == null ? void 0 : onCloseProp();
|
|
105
|
+
}, [
|
|
106
|
+
formatRef,
|
|
107
|
+
isOpen,
|
|
108
|
+
setValue,
|
|
109
|
+
onCloseProp,
|
|
110
|
+
value,
|
|
111
|
+
formatInput,
|
|
112
|
+
setInputValue,
|
|
113
|
+
fallbackValue
|
|
114
|
+
]);
|
|
115
|
+
const onContainerClick = (0, import_react.useCallback)(() => {
|
|
116
|
+
if (isOpen)
|
|
117
|
+
return;
|
|
118
|
+
onOpen();
|
|
119
|
+
}, [isOpen, onOpen]);
|
|
120
|
+
const onInputFocus = (0, import_react.useCallback)(() => {
|
|
121
|
+
isInputFocused.current = true;
|
|
122
|
+
if (isOpen)
|
|
123
|
+
return;
|
|
124
|
+
onOpen();
|
|
125
|
+
}, [isOpen, onOpen]);
|
|
126
|
+
const onInputBlur = (0, import_react.useCallback)(() => {
|
|
127
|
+
isInputFocused.current = false;
|
|
128
|
+
}, []);
|
|
129
|
+
const onContainerBlur = (0, import_react.useCallback)(
|
|
130
|
+
(ev) => {
|
|
131
|
+
const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
|
|
132
|
+
if ((0, import_utils.isContains)(containerRef.current, relatedTarget))
|
|
133
|
+
return;
|
|
134
|
+
if (!closeOnBlur)
|
|
135
|
+
return;
|
|
136
|
+
if (isOpen)
|
|
137
|
+
onClose();
|
|
138
|
+
},
|
|
139
|
+
[closeOnBlur, isOpen, onClose]
|
|
140
|
+
);
|
|
141
|
+
const onInputKeyDown = (0, import_react.useCallback)(
|
|
142
|
+
(ev) => {
|
|
143
|
+
if (ev.key === " ")
|
|
144
|
+
ev.key = ev.code;
|
|
145
|
+
if (disabled || readOnly)
|
|
146
|
+
return;
|
|
147
|
+
const actions = {
|
|
148
|
+
Space: !isOpen ? onOpen : void 0,
|
|
149
|
+
Enter: !isOpen ? onOpen : void 0,
|
|
150
|
+
Escape: closeOnEsc ? onClose : void 0
|
|
151
|
+
};
|
|
152
|
+
const action = actions[ev.key];
|
|
153
|
+
if (!action)
|
|
154
|
+
return;
|
|
155
|
+
ev.preventDefault();
|
|
156
|
+
ev.stopPropagation();
|
|
157
|
+
action();
|
|
158
|
+
},
|
|
159
|
+
[disabled, readOnly, isOpen, onOpen, closeOnEsc, onClose]
|
|
160
|
+
);
|
|
161
|
+
const onInputChange = (0, import_react.useCallback)(
|
|
162
|
+
(ev) => {
|
|
163
|
+
const value2 = ev.target.value;
|
|
164
|
+
setInputValue(formatInput(value2));
|
|
165
|
+
setValue(value2);
|
|
166
|
+
},
|
|
167
|
+
[setInputValue, formatInput, setValue]
|
|
168
|
+
);
|
|
169
|
+
const onColorPickerChange = (0, import_react.useCallback)(
|
|
170
|
+
(value2) => {
|
|
171
|
+
setValue(value2);
|
|
172
|
+
if (!isInputFocused.current)
|
|
173
|
+
setInputValue(formatInput(value2));
|
|
174
|
+
},
|
|
175
|
+
[setValue, formatInput]
|
|
176
|
+
);
|
|
177
|
+
const onEyeDropperClick = (0, import_react.useCallback)(
|
|
178
|
+
async (ev) => {
|
|
179
|
+
var _a;
|
|
180
|
+
ev.preventDefault();
|
|
181
|
+
ev.stopPropagation();
|
|
182
|
+
try {
|
|
183
|
+
const { sRGBHex } = (_a = await onEyeDropperOpen()) != null ? _a : {};
|
|
184
|
+
if (!sRGBHex)
|
|
185
|
+
return;
|
|
186
|
+
onColorPickerChange(sRGBHex);
|
|
187
|
+
} catch {
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
[onEyeDropperOpen, onColorPickerChange]
|
|
191
|
+
);
|
|
192
|
+
(0, import_use_outside_click.useOutsideClick)({
|
|
193
|
+
ref: containerRef,
|
|
194
|
+
handler: onClose,
|
|
195
|
+
enabled: closeOnBlur
|
|
196
|
+
});
|
|
197
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
198
|
+
if (!format)
|
|
199
|
+
return;
|
|
200
|
+
formatRef.current = format;
|
|
201
|
+
const nextValue = (0, import_utils.convertColor)(value, fallbackValue)(format);
|
|
202
|
+
if (!nextValue)
|
|
203
|
+
return;
|
|
204
|
+
setInputValue(formatInput(nextValue));
|
|
205
|
+
setValue(nextValue);
|
|
206
|
+
}, [format, fallbackValue]);
|
|
207
|
+
const getPopoverProps = (0, import_react.useCallback)(
|
|
208
|
+
(props) => ({
|
|
209
|
+
matchWidth: isColorPickerFull,
|
|
210
|
+
...rest,
|
|
211
|
+
...props,
|
|
212
|
+
isOpen,
|
|
213
|
+
onOpen,
|
|
214
|
+
onClose,
|
|
215
|
+
placement,
|
|
216
|
+
duration,
|
|
217
|
+
trigger: "never",
|
|
218
|
+
closeOnButton: false
|
|
219
|
+
}),
|
|
220
|
+
[isColorPickerFull, duration, onClose, onOpen, placement, rest, isOpen]
|
|
221
|
+
);
|
|
222
|
+
const getContainerProps = (0, import_react.useCallback)(
|
|
223
|
+
(props = {}, ref = null) => ({
|
|
224
|
+
ref: (0, import_utils.mergeRefs)(containerRef, ref),
|
|
225
|
+
...computedProps[0],
|
|
226
|
+
...props,
|
|
227
|
+
...formControlProps,
|
|
228
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, rest.onClick, onContainerClick),
|
|
229
|
+
onBlur: (0, import_utils.handlerAll)(props.onBlur, rest.onBlur, onContainerBlur)
|
|
230
|
+
}),
|
|
231
|
+
[computedProps, formControlProps, onContainerBlur, onContainerClick, rest]
|
|
232
|
+
);
|
|
233
|
+
const getFieldProps = (0, import_react.useCallback)(
|
|
234
|
+
(props = {}, ref = null) => ({
|
|
235
|
+
ref: (0, import_utils.mergeRefs)(fieldRef, ref),
|
|
236
|
+
tabIndex: !allowInput ? -1 : 0,
|
|
237
|
+
...(0, import_utils.omitObject)(computedProps[1], ["aria-readonly"]),
|
|
238
|
+
...props,
|
|
239
|
+
style: {
|
|
240
|
+
...props.style,
|
|
241
|
+
...!allowInput ? { pointerEvents: "none" } : {}
|
|
242
|
+
},
|
|
243
|
+
value: inputValue,
|
|
244
|
+
"data-active": (0, import_utils.dataAttr)(isOpen),
|
|
245
|
+
"aria-expanded": (0, import_utils.dataAttr)(isOpen),
|
|
246
|
+
onFocus: (0, import_utils.handlerAll)(props.onFocus, rest.onFocus, onInputFocus),
|
|
247
|
+
onKeyDown: (0, import_utils.handlerAll)(props.onKeyDown, rest.onKeyDown, onInputKeyDown),
|
|
248
|
+
onChange: (0, import_utils.handlerAll)(props.onChange, onInputChange),
|
|
249
|
+
onBlur: (0, import_utils.handlerAll)(props.onFocus, onInputBlur)
|
|
250
|
+
}),
|
|
251
|
+
[
|
|
252
|
+
allowInput,
|
|
253
|
+
computedProps,
|
|
254
|
+
inputValue,
|
|
255
|
+
isOpen,
|
|
256
|
+
rest,
|
|
257
|
+
onInputFocus,
|
|
258
|
+
onInputKeyDown,
|
|
259
|
+
onInputChange,
|
|
260
|
+
onInputBlur
|
|
261
|
+
]
|
|
262
|
+
);
|
|
263
|
+
const getEyeDropperProps = (0, import_react.useCallback)(
|
|
264
|
+
(props = {}, ref = null) => ({
|
|
265
|
+
disabled,
|
|
266
|
+
"aria-label": "Pick a color",
|
|
267
|
+
...props,
|
|
268
|
+
ref,
|
|
269
|
+
style: { ...props.style, pointerEvents: readOnly ? "none" : void 0 },
|
|
270
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, onEyeDropperClick)
|
|
271
|
+
}),
|
|
272
|
+
[disabled, onEyeDropperClick, readOnly]
|
|
273
|
+
);
|
|
274
|
+
const getPickerProps = (0, import_react.useCallback)(
|
|
275
|
+
(props) => ({
|
|
276
|
+
...formControlProps,
|
|
277
|
+
...props,
|
|
278
|
+
value,
|
|
279
|
+
defaultValue: defaultColor,
|
|
280
|
+
fallbackValue,
|
|
281
|
+
onChange: onColorPickerChange,
|
|
282
|
+
onChangeStart,
|
|
283
|
+
onChangeEnd,
|
|
284
|
+
onSwatchClick: (0, import_utils.handlerAll)(
|
|
285
|
+
onSwatchClick,
|
|
286
|
+
closeOnSelectSwatch ? onClose : void 0
|
|
287
|
+
),
|
|
288
|
+
format: formatRef.current,
|
|
289
|
+
withPicker,
|
|
290
|
+
withChannel,
|
|
291
|
+
withResult,
|
|
292
|
+
withEyeDropper: withColorPickerEyeDropper,
|
|
293
|
+
swatchesLabel,
|
|
294
|
+
swatches,
|
|
295
|
+
swatchesColumns,
|
|
296
|
+
variant: colorPickerVariant,
|
|
297
|
+
size: colorPickerSize,
|
|
298
|
+
colorScheme: colorPickerColorScheme
|
|
299
|
+
}),
|
|
300
|
+
[
|
|
301
|
+
formControlProps,
|
|
302
|
+
value,
|
|
303
|
+
fallbackValue,
|
|
304
|
+
defaultColor,
|
|
305
|
+
onColorPickerChange,
|
|
306
|
+
onChangeStart,
|
|
307
|
+
onChangeEnd,
|
|
308
|
+
onSwatchClick,
|
|
309
|
+
onClose,
|
|
310
|
+
closeOnSelectSwatch,
|
|
311
|
+
formatRef,
|
|
312
|
+
withPicker,
|
|
313
|
+
withChannel,
|
|
314
|
+
withResult,
|
|
315
|
+
withColorPickerEyeDropper,
|
|
316
|
+
swatchesLabel,
|
|
317
|
+
swatches,
|
|
318
|
+
swatchesColumns,
|
|
319
|
+
colorPickerColorScheme,
|
|
320
|
+
colorPickerSize,
|
|
321
|
+
colorPickerVariant
|
|
322
|
+
]
|
|
323
|
+
);
|
|
324
|
+
return {
|
|
325
|
+
value,
|
|
326
|
+
eyeDropperSupported,
|
|
327
|
+
allowInput,
|
|
328
|
+
getPopoverProps,
|
|
329
|
+
getContainerProps,
|
|
330
|
+
getFieldProps,
|
|
331
|
+
getPickerProps,
|
|
332
|
+
getEyeDropperProps
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
336
|
+
0 && (module.exports = {
|
|
337
|
+
ColorInputProvider,
|
|
338
|
+
useColorInput,
|
|
339
|
+
useColorInputContext
|
|
340
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { HTMLUIProps, UIPropGetter, RequiredUIPropGetter, ThemeProps, CSSUIObject } from '@yamada-ui/core';
|
|
3
|
+
import { FormControlOptions } from '@yamada-ui/form-control';
|
|
4
|
+
import { InputProps } from '@yamada-ui/input';
|
|
5
|
+
import { Merge, ColorFormat } from '@yamada-ui/utils';
|
|
6
|
+
import { AlphaSliderProps } from './alpha-slider.mjs';
|
|
7
|
+
import { ColorSwatchProps } from './color-swatch.mjs';
|
|
8
|
+
import { HueSliderProps } from './hue-slider.mjs';
|
|
9
|
+
import { SaturationSliderProps } from './saturation-slider.mjs';
|
|
10
|
+
import './use-color-slider.mjs';
|
|
11
|
+
import './use-saturation-slider.mjs';
|
|
12
|
+
|
|
13
|
+
type Space = keyof Hsla | keyof Rgba;
|
|
14
|
+
type Hsla = {
|
|
15
|
+
h: number;
|
|
16
|
+
s: number;
|
|
17
|
+
l: number;
|
|
18
|
+
a: number;
|
|
19
|
+
};
|
|
20
|
+
type Rgba = {
|
|
21
|
+
r: number;
|
|
22
|
+
g: number;
|
|
23
|
+
b: number;
|
|
24
|
+
a: number;
|
|
25
|
+
};
|
|
26
|
+
type Hsva = {
|
|
27
|
+
h: number;
|
|
28
|
+
s: number;
|
|
29
|
+
v: number;
|
|
30
|
+
a: number;
|
|
31
|
+
};
|
|
32
|
+
type Channel = {
|
|
33
|
+
label: string;
|
|
34
|
+
space: Space;
|
|
35
|
+
value: number;
|
|
36
|
+
min: number;
|
|
37
|
+
max: number;
|
|
38
|
+
};
|
|
39
|
+
type ColorPickerContext = {
|
|
40
|
+
value: string;
|
|
41
|
+
onChange: (value: string | Partial<Hsva>) => void;
|
|
42
|
+
eyeDropperSupported: boolean;
|
|
43
|
+
withAlpha: boolean;
|
|
44
|
+
isInteractive: boolean;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
readOnly?: boolean;
|
|
47
|
+
channels: Channel[];
|
|
48
|
+
size?: ThemeProps<"ColorPicker">["size"];
|
|
49
|
+
getHueSliderProps: UIPropGetter<"input", HueSliderProps, HueSliderProps>;
|
|
50
|
+
getAlphaSliderProps: UIPropGetter<"input", AlphaSliderProps, AlphaSliderProps>;
|
|
51
|
+
getEyeDropperProps: UIPropGetter<"button">;
|
|
52
|
+
getChannelProps: RequiredUIPropGetter<"input", Merge<InputProps, {
|
|
53
|
+
space: Space;
|
|
54
|
+
}>, InputProps>;
|
|
55
|
+
getSwatchProps: UIPropGetter<"div", ColorSwatchProps, ColorSwatchProps>;
|
|
56
|
+
styles: Record<string, CSSUIObject>;
|
|
57
|
+
};
|
|
58
|
+
declare const ColorPickerProvider: react.Provider<ColorPickerContext>;
|
|
59
|
+
declare const useColorPickerContext: () => ColorPickerContext;
|
|
60
|
+
type UseColorPickerOptions = {
|
|
61
|
+
/**
|
|
62
|
+
* The base `id` to use for the color picker.
|
|
63
|
+
*/
|
|
64
|
+
id?: string;
|
|
65
|
+
/**
|
|
66
|
+
* The name attribute of the hidden `input` field.
|
|
67
|
+
* This is particularly useful in forms.
|
|
68
|
+
*/
|
|
69
|
+
name?: string;
|
|
70
|
+
/**
|
|
71
|
+
* The value of the color picker.
|
|
72
|
+
*/
|
|
73
|
+
value?: string;
|
|
74
|
+
/**
|
|
75
|
+
* The initial value of the color picker.
|
|
76
|
+
*
|
|
77
|
+
* @default "#ffffffff"
|
|
78
|
+
*/
|
|
79
|
+
defaultValue?: string;
|
|
80
|
+
/**
|
|
81
|
+
* The fallback value returned when color determination fails.
|
|
82
|
+
*/
|
|
83
|
+
fallbackValue?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Function called whenever the color picker value changes.
|
|
86
|
+
*/
|
|
87
|
+
onChange?: (value: string) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Function called when the user starts selecting a new value.
|
|
90
|
+
*/
|
|
91
|
+
onChangeStart?: (value: string) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Function called when the user is done selecting a new value.
|
|
94
|
+
*/
|
|
95
|
+
onChangeEnd?: (value: string) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Color format. For example, `hex`, `rgba`, etc.
|
|
98
|
+
*
|
|
99
|
+
* @default "hexa"
|
|
100
|
+
*/
|
|
101
|
+
format?: ColorFormat;
|
|
102
|
+
/**
|
|
103
|
+
* Function called whenever the color swatch click.
|
|
104
|
+
*/
|
|
105
|
+
onSwatchClick?: (value: string) => void;
|
|
106
|
+
};
|
|
107
|
+
type UseColorPickerBaseProps = UseColorPickerOptions & FormControlOptions;
|
|
108
|
+
type UseColorPickerProps = Omit<HTMLUIProps<"div">, "defaultValue" | "onChange" | "children"> & UseColorPickerBaseProps;
|
|
109
|
+
declare const useColorPicker: ({ isInvalid, ...props }: UseColorPickerProps) => {
|
|
110
|
+
value: string;
|
|
111
|
+
onChange: (value: string | Partial<Hsva>) => void;
|
|
112
|
+
eyeDropperSupported: boolean;
|
|
113
|
+
withAlpha: boolean;
|
|
114
|
+
isInteractive: boolean;
|
|
115
|
+
disabled: boolean | undefined;
|
|
116
|
+
readOnly: boolean | undefined;
|
|
117
|
+
channels: Channel[];
|
|
118
|
+
getContainerProps: UIPropGetter;
|
|
119
|
+
getInputProps: UIPropGetter<"input">;
|
|
120
|
+
getSaturationSliderProps: UIPropGetter<"input", SaturationSliderProps, SaturationSliderProps>;
|
|
121
|
+
getHueSliderProps: UIPropGetter<"input", HueSliderProps, HueSliderProps>;
|
|
122
|
+
getAlphaSliderProps: UIPropGetter<"input", AlphaSliderProps, AlphaSliderProps>;
|
|
123
|
+
getEyeDropperProps: UIPropGetter<"button">;
|
|
124
|
+
getChannelProps: RequiredUIPropGetter<"input", Omit<InputProps, "space"> & {
|
|
125
|
+
space: Space;
|
|
126
|
+
}, InputProps>;
|
|
127
|
+
getSwatchProps: UIPropGetter<"div", ColorSwatchProps, ColorSwatchProps>;
|
|
128
|
+
};
|
|
129
|
+
type UseColorPickerReturn = ReturnType<typeof useColorPicker>;
|
|
130
|
+
|
|
131
|
+
export { ColorPickerProvider, type UseColorPickerBaseProps, type UseColorPickerProps, type UseColorPickerReturn, useColorPicker, useColorPickerContext };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { HTMLUIProps, UIPropGetter, RequiredUIPropGetter, ThemeProps, CSSUIObject } from '@yamada-ui/core';
|
|
3
|
+
import { FormControlOptions } from '@yamada-ui/form-control';
|
|
4
|
+
import { InputProps } from '@yamada-ui/input';
|
|
5
|
+
import { Merge, ColorFormat } from '@yamada-ui/utils';
|
|
6
|
+
import { AlphaSliderProps } from './alpha-slider.js';
|
|
7
|
+
import { ColorSwatchProps } from './color-swatch.js';
|
|
8
|
+
import { HueSliderProps } from './hue-slider.js';
|
|
9
|
+
import { SaturationSliderProps } from './saturation-slider.js';
|
|
10
|
+
import './use-color-slider.js';
|
|
11
|
+
import './use-saturation-slider.js';
|
|
12
|
+
|
|
13
|
+
type Space = keyof Hsla | keyof Rgba;
|
|
14
|
+
type Hsla = {
|
|
15
|
+
h: number;
|
|
16
|
+
s: number;
|
|
17
|
+
l: number;
|
|
18
|
+
a: number;
|
|
19
|
+
};
|
|
20
|
+
type Rgba = {
|
|
21
|
+
r: number;
|
|
22
|
+
g: number;
|
|
23
|
+
b: number;
|
|
24
|
+
a: number;
|
|
25
|
+
};
|
|
26
|
+
type Hsva = {
|
|
27
|
+
h: number;
|
|
28
|
+
s: number;
|
|
29
|
+
v: number;
|
|
30
|
+
a: number;
|
|
31
|
+
};
|
|
32
|
+
type Channel = {
|
|
33
|
+
label: string;
|
|
34
|
+
space: Space;
|
|
35
|
+
value: number;
|
|
36
|
+
min: number;
|
|
37
|
+
max: number;
|
|
38
|
+
};
|
|
39
|
+
type ColorPickerContext = {
|
|
40
|
+
value: string;
|
|
41
|
+
onChange: (value: string | Partial<Hsva>) => void;
|
|
42
|
+
eyeDropperSupported: boolean;
|
|
43
|
+
withAlpha: boolean;
|
|
44
|
+
isInteractive: boolean;
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
readOnly?: boolean;
|
|
47
|
+
channels: Channel[];
|
|
48
|
+
size?: ThemeProps<"ColorPicker">["size"];
|
|
49
|
+
getHueSliderProps: UIPropGetter<"input", HueSliderProps, HueSliderProps>;
|
|
50
|
+
getAlphaSliderProps: UIPropGetter<"input", AlphaSliderProps, AlphaSliderProps>;
|
|
51
|
+
getEyeDropperProps: UIPropGetter<"button">;
|
|
52
|
+
getChannelProps: RequiredUIPropGetter<"input", Merge<InputProps, {
|
|
53
|
+
space: Space;
|
|
54
|
+
}>, InputProps>;
|
|
55
|
+
getSwatchProps: UIPropGetter<"div", ColorSwatchProps, ColorSwatchProps>;
|
|
56
|
+
styles: Record<string, CSSUIObject>;
|
|
57
|
+
};
|
|
58
|
+
declare const ColorPickerProvider: react.Provider<ColorPickerContext>;
|
|
59
|
+
declare const useColorPickerContext: () => ColorPickerContext;
|
|
60
|
+
type UseColorPickerOptions = {
|
|
61
|
+
/**
|
|
62
|
+
* The base `id` to use for the color picker.
|
|
63
|
+
*/
|
|
64
|
+
id?: string;
|
|
65
|
+
/**
|
|
66
|
+
* The name attribute of the hidden `input` field.
|
|
67
|
+
* This is particularly useful in forms.
|
|
68
|
+
*/
|
|
69
|
+
name?: string;
|
|
70
|
+
/**
|
|
71
|
+
* The value of the color picker.
|
|
72
|
+
*/
|
|
73
|
+
value?: string;
|
|
74
|
+
/**
|
|
75
|
+
* The initial value of the color picker.
|
|
76
|
+
*
|
|
77
|
+
* @default "#ffffffff"
|
|
78
|
+
*/
|
|
79
|
+
defaultValue?: string;
|
|
80
|
+
/**
|
|
81
|
+
* The fallback value returned when color determination fails.
|
|
82
|
+
*/
|
|
83
|
+
fallbackValue?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Function called whenever the color picker value changes.
|
|
86
|
+
*/
|
|
87
|
+
onChange?: (value: string) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Function called when the user starts selecting a new value.
|
|
90
|
+
*/
|
|
91
|
+
onChangeStart?: (value: string) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Function called when the user is done selecting a new value.
|
|
94
|
+
*/
|
|
95
|
+
onChangeEnd?: (value: string) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Color format. For example, `hex`, `rgba`, etc.
|
|
98
|
+
*
|
|
99
|
+
* @default "hexa"
|
|
100
|
+
*/
|
|
101
|
+
format?: ColorFormat;
|
|
102
|
+
/**
|
|
103
|
+
* Function called whenever the color swatch click.
|
|
104
|
+
*/
|
|
105
|
+
onSwatchClick?: (value: string) => void;
|
|
106
|
+
};
|
|
107
|
+
type UseColorPickerBaseProps = UseColorPickerOptions & FormControlOptions;
|
|
108
|
+
type UseColorPickerProps = Omit<HTMLUIProps<"div">, "defaultValue" | "onChange" | "children"> & UseColorPickerBaseProps;
|
|
109
|
+
declare const useColorPicker: ({ isInvalid, ...props }: UseColorPickerProps) => {
|
|
110
|
+
value: string;
|
|
111
|
+
onChange: (value: string | Partial<Hsva>) => void;
|
|
112
|
+
eyeDropperSupported: boolean;
|
|
113
|
+
withAlpha: boolean;
|
|
114
|
+
isInteractive: boolean;
|
|
115
|
+
disabled: boolean | undefined;
|
|
116
|
+
readOnly: boolean | undefined;
|
|
117
|
+
channels: Channel[];
|
|
118
|
+
getContainerProps: UIPropGetter;
|
|
119
|
+
getInputProps: UIPropGetter<"input">;
|
|
120
|
+
getSaturationSliderProps: UIPropGetter<"input", SaturationSliderProps, SaturationSliderProps>;
|
|
121
|
+
getHueSliderProps: UIPropGetter<"input", HueSliderProps, HueSliderProps>;
|
|
122
|
+
getAlphaSliderProps: UIPropGetter<"input", AlphaSliderProps, AlphaSliderProps>;
|
|
123
|
+
getEyeDropperProps: UIPropGetter<"button">;
|
|
124
|
+
getChannelProps: RequiredUIPropGetter<"input", Omit<InputProps, "space"> & {
|
|
125
|
+
space: Space;
|
|
126
|
+
}, InputProps>;
|
|
127
|
+
getSwatchProps: UIPropGetter<"div", ColorSwatchProps, ColorSwatchProps>;
|
|
128
|
+
};
|
|
129
|
+
type UseColorPickerReturn = ReturnType<typeof useColorPicker>;
|
|
130
|
+
|
|
131
|
+
export { ColorPickerProvider, type UseColorPickerBaseProps, type UseColorPickerProps, type UseColorPickerReturn, useColorPicker, useColorPickerContext };
|