@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,430 @@
|
|
|
1
|
+
import {
|
|
2
|
+
pickObject
|
|
3
|
+
} from "./chunk-N2GG5L7Q.mjs";
|
|
4
|
+
|
|
5
|
+
// src/use-color-picker.ts
|
|
6
|
+
import {
|
|
7
|
+
useFormControlProps,
|
|
8
|
+
formControlProperties
|
|
9
|
+
} from "@yamada-ui/form-control";
|
|
10
|
+
import { useControllableState } from "@yamada-ui/use-controllable-state";
|
|
11
|
+
import { useEyeDropper } from "@yamada-ui/use-eye-dropper";
|
|
12
|
+
import {
|
|
13
|
+
calcFormat,
|
|
14
|
+
convertColor,
|
|
15
|
+
createContext,
|
|
16
|
+
handlerAll,
|
|
17
|
+
hsvTo,
|
|
18
|
+
isString,
|
|
19
|
+
parseToHsv,
|
|
20
|
+
useCallbackRef,
|
|
21
|
+
useUpdateEffect,
|
|
22
|
+
omitObject,
|
|
23
|
+
parseToRgba,
|
|
24
|
+
parseToHsla,
|
|
25
|
+
rgbaTo,
|
|
26
|
+
hslaTo
|
|
27
|
+
} from "@yamada-ui/utils";
|
|
28
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
29
|
+
var convertHsla = (value, fallback) => {
|
|
30
|
+
var _a;
|
|
31
|
+
let [h, s, l, a] = (_a = parseToHsla(value, fallback)) != null ? _a : [0, 0, 1, 1];
|
|
32
|
+
if (a > 1)
|
|
33
|
+
a = 1;
|
|
34
|
+
return { h, s, l, a };
|
|
35
|
+
};
|
|
36
|
+
var convertRgba = (value, fallback) => {
|
|
37
|
+
var _a;
|
|
38
|
+
let [r, g, b, a] = (_a = parseToRgba(value, fallback)) != null ? _a : [255, 255, 255, 1];
|
|
39
|
+
if (r > 255)
|
|
40
|
+
r = 255;
|
|
41
|
+
if (g > 255)
|
|
42
|
+
g = 255;
|
|
43
|
+
if (b > 255)
|
|
44
|
+
b = 255;
|
|
45
|
+
if (a > 1)
|
|
46
|
+
a = 1;
|
|
47
|
+
return { r, g, b, a };
|
|
48
|
+
};
|
|
49
|
+
var convertHsva = (value, fallback) => {
|
|
50
|
+
const [h, s, v, a] = parseToHsv(value, fallback);
|
|
51
|
+
return { h, s, v, a };
|
|
52
|
+
};
|
|
53
|
+
var [ColorPickerProvider, useColorPickerContext] = createContext({
|
|
54
|
+
name: "ColorPickerContext",
|
|
55
|
+
errorMessage: `useColorPickerContext returned is 'undefined'. Seems you forgot to wrap the components in "<ColorPicker />"`
|
|
56
|
+
});
|
|
57
|
+
var useColorPicker = ({
|
|
58
|
+
isInvalid,
|
|
59
|
+
...props
|
|
60
|
+
}) => {
|
|
61
|
+
var _a;
|
|
62
|
+
let {
|
|
63
|
+
id,
|
|
64
|
+
name,
|
|
65
|
+
value: valueProp,
|
|
66
|
+
defaultValue,
|
|
67
|
+
fallbackValue,
|
|
68
|
+
onChange: onChangeProp,
|
|
69
|
+
onChangeStart: onChangeStartProp,
|
|
70
|
+
onChangeEnd: onChangeEndProp,
|
|
71
|
+
format,
|
|
72
|
+
required,
|
|
73
|
+
disabled,
|
|
74
|
+
readOnly,
|
|
75
|
+
onSwatchClick,
|
|
76
|
+
...rest
|
|
77
|
+
} = useFormControlProps({ isInvalid, ...props });
|
|
78
|
+
const onChangeStartRef = useCallbackRef(onChangeStartProp);
|
|
79
|
+
const onChangeEndRef = useCallbackRef(onChangeEndProp);
|
|
80
|
+
const { supported: eyeDropperSupported, onOpen } = useEyeDropper();
|
|
81
|
+
const [value, setValue] = useControllableState({
|
|
82
|
+
value: valueProp,
|
|
83
|
+
defaultValue: (_a = defaultValue != null ? defaultValue : fallbackValue) != null ? _a : "#ffffffff",
|
|
84
|
+
onChange: onChangeProp
|
|
85
|
+
});
|
|
86
|
+
const timeoutId = useRef(void 0);
|
|
87
|
+
const formatRef = useRef(format != null ? format : calcFormat(value));
|
|
88
|
+
const isDraggingRef = useRef(false);
|
|
89
|
+
const [parsedValue, setParsedValue] = useState(
|
|
90
|
+
convertHsva(value, fallbackValue)
|
|
91
|
+
);
|
|
92
|
+
const { h, s, v, a } = parsedValue;
|
|
93
|
+
const withAlpha = formatRef.current.endsWith("a");
|
|
94
|
+
const isInteractive = !(disabled || readOnly);
|
|
95
|
+
const channels = useMemo(() => {
|
|
96
|
+
if (value.startsWith("hsl")) {
|
|
97
|
+
const { h: h2, s: s2, l, a: a2 } = convertHsla(value, fallbackValue);
|
|
98
|
+
let channels2 = [
|
|
99
|
+
{ label: "H", space: "h", value: Math.round(h2), min: 0, max: 360 },
|
|
100
|
+
{
|
|
101
|
+
label: "S(%)",
|
|
102
|
+
space: "s",
|
|
103
|
+
value: Math.round(s2 * 100),
|
|
104
|
+
min: 0,
|
|
105
|
+
max: 100
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
label: "L(%)",
|
|
109
|
+
space: "l",
|
|
110
|
+
value: Math.round(l * 100),
|
|
111
|
+
min: 0,
|
|
112
|
+
max: 100
|
|
113
|
+
}
|
|
114
|
+
];
|
|
115
|
+
if (withAlpha) {
|
|
116
|
+
channels2 = [
|
|
117
|
+
...channels2,
|
|
118
|
+
{
|
|
119
|
+
label: "A(%)",
|
|
120
|
+
space: "a",
|
|
121
|
+
value: Math.round(a2 * 100),
|
|
122
|
+
min: 0,
|
|
123
|
+
max: 100
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
}
|
|
127
|
+
return channels2;
|
|
128
|
+
} else {
|
|
129
|
+
const { r, g, b, a: a2 } = convertRgba(value, fallbackValue);
|
|
130
|
+
let channels2 = [
|
|
131
|
+
{ label: "R", space: "r", value: Math.round(r), min: 0, max: 255 },
|
|
132
|
+
{ label: "G", space: "g", value: Math.round(g), min: 0, max: 255 },
|
|
133
|
+
{ label: "B", space: "b", value: Math.round(b), min: 0, max: 255 }
|
|
134
|
+
];
|
|
135
|
+
if (withAlpha) {
|
|
136
|
+
channels2 = [
|
|
137
|
+
...channels2,
|
|
138
|
+
{
|
|
139
|
+
label: "A(%)",
|
|
140
|
+
space: "a",
|
|
141
|
+
value: Math.round(a2 * 100),
|
|
142
|
+
min: 0,
|
|
143
|
+
max: 100
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
return channels2;
|
|
148
|
+
}
|
|
149
|
+
}, [value, withAlpha, fallbackValue]);
|
|
150
|
+
const onChange = useCallback(
|
|
151
|
+
(value2) => {
|
|
152
|
+
if (isString(value2)) {
|
|
153
|
+
setParsedValue(convertHsva(value2, fallbackValue));
|
|
154
|
+
} else {
|
|
155
|
+
setParsedValue((prev) => ({ ...prev, ...value2 }));
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
[fallbackValue]
|
|
159
|
+
);
|
|
160
|
+
const onChangeStart = useCallback(
|
|
161
|
+
(value2) => {
|
|
162
|
+
window.clearTimeout(timeoutId.current);
|
|
163
|
+
isDraggingRef.current = true;
|
|
164
|
+
const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
|
|
165
|
+
const nextValue = hsvTo([h2, s2, v2, a2], fallbackValue)(formatRef.current);
|
|
166
|
+
if (nextValue)
|
|
167
|
+
onChangeStartRef(nextValue);
|
|
168
|
+
},
|
|
169
|
+
[formatRef, onChangeStartRef, fallbackValue, parsedValue]
|
|
170
|
+
);
|
|
171
|
+
const onChangeEnd = useCallback(
|
|
172
|
+
(value2) => {
|
|
173
|
+
window.clearTimeout(timeoutId.current);
|
|
174
|
+
timeoutId.current = window.setTimeout(() => {
|
|
175
|
+
isDraggingRef.current = false;
|
|
176
|
+
}, 200);
|
|
177
|
+
let nextValue;
|
|
178
|
+
if (isString(value2)) {
|
|
179
|
+
nextValue = convertColor(value2, fallbackValue)(formatRef.current);
|
|
180
|
+
} else {
|
|
181
|
+
const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
|
|
182
|
+
nextValue = hsvTo([h2, s2, v2, a2], fallbackValue)(formatRef.current);
|
|
183
|
+
}
|
|
184
|
+
if (nextValue)
|
|
185
|
+
onChangeEndRef(nextValue);
|
|
186
|
+
},
|
|
187
|
+
[formatRef, onChangeEndRef, fallbackValue, parsedValue]
|
|
188
|
+
);
|
|
189
|
+
const onChannelChange = useCallback(
|
|
190
|
+
(ev, space) => {
|
|
191
|
+
let n = Math.floor(parseFloat(ev.target.value));
|
|
192
|
+
if (isNaN(n))
|
|
193
|
+
n = 0;
|
|
194
|
+
if (["s", "l", "a"].includes(space))
|
|
195
|
+
n = n / 100;
|
|
196
|
+
let nextValue;
|
|
197
|
+
if (value.startsWith("hsl")) {
|
|
198
|
+
const { h: h2, s: s2, l, a: a2 } = Object.assign(
|
|
199
|
+
convertHsla(value, fallbackValue),
|
|
200
|
+
{ [space]: n }
|
|
201
|
+
);
|
|
202
|
+
nextValue = hslaTo([h2, s2, l, a2], fallbackValue)(formatRef.current);
|
|
203
|
+
} else {
|
|
204
|
+
const { r, g, b, a: a2 } = Object.assign(
|
|
205
|
+
convertRgba(value, fallbackValue),
|
|
206
|
+
{ [space]: n }
|
|
207
|
+
);
|
|
208
|
+
nextValue = rgbaTo([r, g, b, a2], fallbackValue)(formatRef.current);
|
|
209
|
+
}
|
|
210
|
+
if (!nextValue)
|
|
211
|
+
return;
|
|
212
|
+
onChange(nextValue);
|
|
213
|
+
onChangeEnd(nextValue);
|
|
214
|
+
},
|
|
215
|
+
[value, onChange, onChangeEnd, formatRef, fallbackValue]
|
|
216
|
+
);
|
|
217
|
+
const onEyeDropperClick = useCallback(async () => {
|
|
218
|
+
var _a2;
|
|
219
|
+
try {
|
|
220
|
+
const { sRGBHex } = (_a2 = await onOpen()) != null ? _a2 : {};
|
|
221
|
+
if (!sRGBHex)
|
|
222
|
+
return;
|
|
223
|
+
onChange(sRGBHex);
|
|
224
|
+
onChangeEnd(sRGBHex);
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
}, [onOpen, onChange, onChangeEnd]);
|
|
228
|
+
useUpdateEffect(() => {
|
|
229
|
+
const value2 = hsvTo([h, s, v, a], fallbackValue)(formatRef.current);
|
|
230
|
+
if (value2)
|
|
231
|
+
setValue(value2);
|
|
232
|
+
}, [h, s, v, a, fallbackValue]);
|
|
233
|
+
useUpdateEffect(() => {
|
|
234
|
+
if (isDraggingRef.current)
|
|
235
|
+
return;
|
|
236
|
+
if (valueProp)
|
|
237
|
+
setParsedValue(convertHsva(valueProp, fallbackValue));
|
|
238
|
+
}, [valueProp]);
|
|
239
|
+
useUpdateEffect(() => {
|
|
240
|
+
if (!format)
|
|
241
|
+
return;
|
|
242
|
+
formatRef.current = format;
|
|
243
|
+
const nextValue = convertColor(value, fallbackValue)(format);
|
|
244
|
+
if (nextValue)
|
|
245
|
+
setValue(nextValue);
|
|
246
|
+
}, [format, fallbackValue]);
|
|
247
|
+
const getContainerProps = (props2 = {}, ref = null) => ({
|
|
248
|
+
...props2,
|
|
249
|
+
ref,
|
|
250
|
+
...omitObject(rest, ["aria-readonly"])
|
|
251
|
+
});
|
|
252
|
+
const getInputProps = useCallback(
|
|
253
|
+
(props2 = {}, ref = null) => ({
|
|
254
|
+
...pickObject(rest, formControlProperties),
|
|
255
|
+
...props2,
|
|
256
|
+
id,
|
|
257
|
+
ref,
|
|
258
|
+
type: "hidden",
|
|
259
|
+
name,
|
|
260
|
+
value,
|
|
261
|
+
required,
|
|
262
|
+
disabled,
|
|
263
|
+
readOnly
|
|
264
|
+
}),
|
|
265
|
+
[disabled, id, name, readOnly, required, rest, value]
|
|
266
|
+
);
|
|
267
|
+
const getSaturationSliderProps = useCallback(
|
|
268
|
+
(props2 = {}, ref = null) => ({
|
|
269
|
+
required,
|
|
270
|
+
disabled,
|
|
271
|
+
readOnly,
|
|
272
|
+
isInvalid,
|
|
273
|
+
...props2,
|
|
274
|
+
ref,
|
|
275
|
+
value: [h, s, v],
|
|
276
|
+
onChange: handlerAll(props2.onChange, ([, s2, v2]) => onChange({ s: s2, v: v2 })),
|
|
277
|
+
onChangeStart: handlerAll(
|
|
278
|
+
props2.onChangeStart,
|
|
279
|
+
([, s2, v2]) => onChangeStart({ s: s2, v: v2 })
|
|
280
|
+
),
|
|
281
|
+
onChangeEnd: handlerAll(
|
|
282
|
+
props2.onChangeEnd,
|
|
283
|
+
([, s2, v2]) => onChangeEnd({ s: s2, v: v2 })
|
|
284
|
+
)
|
|
285
|
+
}),
|
|
286
|
+
[
|
|
287
|
+
required,
|
|
288
|
+
disabled,
|
|
289
|
+
readOnly,
|
|
290
|
+
isInvalid,
|
|
291
|
+
h,
|
|
292
|
+
s,
|
|
293
|
+
v,
|
|
294
|
+
onChange,
|
|
295
|
+
onChangeStart,
|
|
296
|
+
onChangeEnd
|
|
297
|
+
]
|
|
298
|
+
);
|
|
299
|
+
const getHueSliderProps = useCallback(
|
|
300
|
+
(props2 = {}, ref = null) => ({
|
|
301
|
+
required,
|
|
302
|
+
disabled,
|
|
303
|
+
readOnly,
|
|
304
|
+
isInvalid,
|
|
305
|
+
...props2,
|
|
306
|
+
ref,
|
|
307
|
+
value: h,
|
|
308
|
+
onChange: handlerAll(props2.onChange, (h2) => onChange({ h: h2 })),
|
|
309
|
+
onChangeStart: handlerAll(
|
|
310
|
+
props2.onChangeStart,
|
|
311
|
+
(h2) => onChangeStart({ h: h2 })
|
|
312
|
+
),
|
|
313
|
+
onChangeEnd: handlerAll(props2.onChangeEnd, (h2) => onChangeEnd({ h: h2 }))
|
|
314
|
+
}),
|
|
315
|
+
[
|
|
316
|
+
required,
|
|
317
|
+
disabled,
|
|
318
|
+
readOnly,
|
|
319
|
+
isInvalid,
|
|
320
|
+
h,
|
|
321
|
+
onChange,
|
|
322
|
+
onChangeStart,
|
|
323
|
+
onChangeEnd
|
|
324
|
+
]
|
|
325
|
+
);
|
|
326
|
+
const getAlphaSliderProps = useCallback(
|
|
327
|
+
(props2 = {}, ref = null) => ({
|
|
328
|
+
required,
|
|
329
|
+
disabled,
|
|
330
|
+
readOnly,
|
|
331
|
+
isInvalid,
|
|
332
|
+
...props2,
|
|
333
|
+
ref,
|
|
334
|
+
value: a,
|
|
335
|
+
color: hsvTo([h, s, v, a], fallbackValue)(formatRef.current),
|
|
336
|
+
onChange: handlerAll(props2.onChange, (a2) => onChange({ a: a2 })),
|
|
337
|
+
onChangeStart: handlerAll(
|
|
338
|
+
props2.onChangeStart,
|
|
339
|
+
(a2) => onChangeStart({ a: a2 })
|
|
340
|
+
),
|
|
341
|
+
onChangeEnd: handlerAll(props2.onChangeEnd, (a2) => onChangeEnd({ a: a2 }))
|
|
342
|
+
}),
|
|
343
|
+
[
|
|
344
|
+
fallbackValue,
|
|
345
|
+
required,
|
|
346
|
+
disabled,
|
|
347
|
+
readOnly,
|
|
348
|
+
isInvalid,
|
|
349
|
+
formatRef,
|
|
350
|
+
h,
|
|
351
|
+
s,
|
|
352
|
+
v,
|
|
353
|
+
a,
|
|
354
|
+
onChange,
|
|
355
|
+
onChangeStart,
|
|
356
|
+
onChangeEnd
|
|
357
|
+
]
|
|
358
|
+
);
|
|
359
|
+
const getChannelProps = useCallback(
|
|
360
|
+
({ space, ...props2 }, ref = null) => {
|
|
361
|
+
return {
|
|
362
|
+
required,
|
|
363
|
+
disabled,
|
|
364
|
+
readOnly,
|
|
365
|
+
isInvalid,
|
|
366
|
+
...props2,
|
|
367
|
+
ref,
|
|
368
|
+
type: "number",
|
|
369
|
+
step: 1,
|
|
370
|
+
onChange: handlerAll(
|
|
371
|
+
props2.onChange,
|
|
372
|
+
(ev) => onChannelChange(ev, space)
|
|
373
|
+
)
|
|
374
|
+
};
|
|
375
|
+
},
|
|
376
|
+
[required, disabled, readOnly, isInvalid, onChannelChange]
|
|
377
|
+
);
|
|
378
|
+
const getEyeDropperProps = useCallback(
|
|
379
|
+
(props2 = {}, ref = null) => ({
|
|
380
|
+
disabled,
|
|
381
|
+
"aria-label": "Pick a color",
|
|
382
|
+
...props2,
|
|
383
|
+
ref,
|
|
384
|
+
onClick: handlerAll(props2.onClick, onEyeDropperClick)
|
|
385
|
+
}),
|
|
386
|
+
[disabled, onEyeDropperClick]
|
|
387
|
+
);
|
|
388
|
+
const getSwatchProps = useCallback(
|
|
389
|
+
({ color, ...props2 } = {}, ref = null) => ({
|
|
390
|
+
"aria-label": `select ${color} as the color`,
|
|
391
|
+
disabled,
|
|
392
|
+
readOnly,
|
|
393
|
+
...props2,
|
|
394
|
+
ref,
|
|
395
|
+
color,
|
|
396
|
+
onClick: handlerAll(props2.onClick, () => {
|
|
397
|
+
if (!color)
|
|
398
|
+
return;
|
|
399
|
+
onSwatchClick == null ? void 0 : onSwatchClick(color);
|
|
400
|
+
onChange(color);
|
|
401
|
+
onChangeEnd(color);
|
|
402
|
+
})
|
|
403
|
+
}),
|
|
404
|
+
[disabled, readOnly, onSwatchClick, onChange, onChangeEnd]
|
|
405
|
+
);
|
|
406
|
+
return {
|
|
407
|
+
value,
|
|
408
|
+
onChange,
|
|
409
|
+
eyeDropperSupported,
|
|
410
|
+
withAlpha,
|
|
411
|
+
isInteractive,
|
|
412
|
+
disabled,
|
|
413
|
+
readOnly,
|
|
414
|
+
channels,
|
|
415
|
+
getContainerProps,
|
|
416
|
+
getInputProps,
|
|
417
|
+
getSaturationSliderProps,
|
|
418
|
+
getHueSliderProps,
|
|
419
|
+
getAlphaSliderProps,
|
|
420
|
+
getEyeDropperProps,
|
|
421
|
+
getChannelProps,
|
|
422
|
+
getSwatchProps
|
|
423
|
+
};
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
export {
|
|
427
|
+
ColorPickerProvider,
|
|
428
|
+
useColorPickerContext,
|
|
429
|
+
useColorPicker
|
|
430
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useColorSlider
|
|
3
|
+
} from "./chunk-DTB2Z3IJ.mjs";
|
|
4
|
+
|
|
5
|
+
// src/hue-slider.tsx
|
|
6
|
+
import {
|
|
7
|
+
ui,
|
|
8
|
+
forwardRef,
|
|
9
|
+
omitThemeProps,
|
|
10
|
+
useMultiComponentStyle
|
|
11
|
+
} from "@yamada-ui/core";
|
|
12
|
+
import { cx } from "@yamada-ui/utils";
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
var defaultOverlays = (min, max, withShadow) => {
|
|
15
|
+
let overlays = [
|
|
16
|
+
{
|
|
17
|
+
bgGradient: `linear(to-r, ${[...Array(7)].map(
|
|
18
|
+
(_, index) => `hsl(${Math.round(min + (max - min) / 6 * index)}, 100%, 50%)`
|
|
19
|
+
).join(", ")})`
|
|
20
|
+
}
|
|
21
|
+
];
|
|
22
|
+
if (withShadow)
|
|
23
|
+
overlays = [
|
|
24
|
+
...overlays,
|
|
25
|
+
{
|
|
26
|
+
boxShadow: `rgba(0, 0, 0, .1) 0 0 0 1px inset, rgb(0, 0, 0, .15) 0 0 4px inset`
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
return overlays;
|
|
30
|
+
};
|
|
31
|
+
var HueSlider = forwardRef((props, ref) => {
|
|
32
|
+
const [styles, mergedProps] = useMultiComponentStyle("HueSlider", props);
|
|
33
|
+
const {
|
|
34
|
+
className,
|
|
35
|
+
inputProps,
|
|
36
|
+
trackProps,
|
|
37
|
+
thumbProps,
|
|
38
|
+
min = 0,
|
|
39
|
+
max = 360,
|
|
40
|
+
withShadow = true,
|
|
41
|
+
overlays = defaultOverlays(min, max, withShadow),
|
|
42
|
+
__css,
|
|
43
|
+
...computedProps
|
|
44
|
+
} = omitThemeProps(mergedProps);
|
|
45
|
+
const { getContainerProps, getTrackProps, getInputProps, getThumbProps } = useColorSlider({ min, max, step: 1, ...computedProps });
|
|
46
|
+
const css = {
|
|
47
|
+
position: "relative",
|
|
48
|
+
...styles.container,
|
|
49
|
+
...__css
|
|
50
|
+
};
|
|
51
|
+
return /* @__PURE__ */ jsxs(
|
|
52
|
+
ui.div,
|
|
53
|
+
{
|
|
54
|
+
className: cx("ui-hue-slider", className),
|
|
55
|
+
__css: css,
|
|
56
|
+
...getContainerProps(),
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsx(ui.input, { ...getInputProps(inputProps, ref) }),
|
|
59
|
+
overlays.map((props2, index) => /* @__PURE__ */ jsx(
|
|
60
|
+
ui.div,
|
|
61
|
+
{
|
|
62
|
+
className: "ui-hue-slider__overlay",
|
|
63
|
+
__css: {
|
|
64
|
+
position: "absolute",
|
|
65
|
+
top: 0,
|
|
66
|
+
left: 0,
|
|
67
|
+
right: 0,
|
|
68
|
+
bottom: 0,
|
|
69
|
+
...styles.overlay
|
|
70
|
+
},
|
|
71
|
+
...props2
|
|
72
|
+
},
|
|
73
|
+
index
|
|
74
|
+
)),
|
|
75
|
+
/* @__PURE__ */ jsx(
|
|
76
|
+
ui.div,
|
|
77
|
+
{
|
|
78
|
+
className: "ui-hue-slider__track",
|
|
79
|
+
__css: { position: "relative", w: "full", h: "full", ...styles.track },
|
|
80
|
+
...getTrackProps(trackProps),
|
|
81
|
+
children: /* @__PURE__ */ jsx(
|
|
82
|
+
ui.div,
|
|
83
|
+
{
|
|
84
|
+
className: "ui-hue-slider__thumb",
|
|
85
|
+
__css: { ...styles.thumb },
|
|
86
|
+
...getThumbProps(thumbProps)
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
)
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export {
|
|
97
|
+
HueSlider
|
|
98
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useColorPickerContext
|
|
3
|
+
} from "./chunk-NR2XCTSD.mjs";
|
|
4
|
+
|
|
5
|
+
// src/color-picker-channels.tsx
|
|
6
|
+
import { forwardRef, ui } from "@yamada-ui/core";
|
|
7
|
+
import { Input } from "@yamada-ui/input";
|
|
8
|
+
import { cx } from "@yamada-ui/utils";
|
|
9
|
+
import { useId } from "react";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
var ColorPickerChannels = forwardRef(
|
|
12
|
+
({ className, channelProps, ...rest }, ref) => {
|
|
13
|
+
const { withAlpha, channels, getChannelProps, styles } = useColorPickerContext();
|
|
14
|
+
const css = {
|
|
15
|
+
display: "grid",
|
|
16
|
+
gridTemplateColumns: `repeat(${withAlpha ? "4" : "3"}, 1fr)`,
|
|
17
|
+
...styles.channels
|
|
18
|
+
};
|
|
19
|
+
return /* @__PURE__ */ jsx(
|
|
20
|
+
ui.div,
|
|
21
|
+
{
|
|
22
|
+
ref,
|
|
23
|
+
className: cx("ui-color-picker__channels", className),
|
|
24
|
+
__css: css,
|
|
25
|
+
...rest,
|
|
26
|
+
children: channels.map(({ label, space, value, min, max }) => /* @__PURE__ */ jsx(
|
|
27
|
+
ColorPickerChannel,
|
|
28
|
+
{
|
|
29
|
+
channelLabel: label,
|
|
30
|
+
...getChannelProps({ ...channelProps, space, value, min, max })
|
|
31
|
+
},
|
|
32
|
+
label
|
|
33
|
+
))
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
var ColorPickerChannel = forwardRef(
|
|
39
|
+
({ className, channelLabel, ...rest }, ref) => {
|
|
40
|
+
const id = useId();
|
|
41
|
+
let { size, disabled, readOnly, styles } = useColorPickerContext();
|
|
42
|
+
if (size === "full")
|
|
43
|
+
size = "lg";
|
|
44
|
+
const css = { ...styles.channel };
|
|
45
|
+
return /* @__PURE__ */ jsxs(ui.div, { className: cx("ui-color-picker__channel", className), children: [
|
|
46
|
+
channelLabel ? /* @__PURE__ */ jsx(
|
|
47
|
+
ui.label,
|
|
48
|
+
{
|
|
49
|
+
htmlFor: id,
|
|
50
|
+
style: { cursor: disabled ? "not-allowed" : void 0 },
|
|
51
|
+
__css: {
|
|
52
|
+
display: "block",
|
|
53
|
+
pointerEvents: readOnly ? "none" : void 0,
|
|
54
|
+
...styles.channelLabel
|
|
55
|
+
},
|
|
56
|
+
children: channelLabel
|
|
57
|
+
}
|
|
58
|
+
) : null,
|
|
59
|
+
/* @__PURE__ */ jsx(Input, { ref, id, size, __css: css, ...rest })
|
|
60
|
+
] });
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
ColorPickerChannels,
|
|
66
|
+
ColorPickerChannel
|
|
67
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ColorSwatch
|
|
3
|
+
} from "./chunk-3N443XSV.mjs";
|
|
4
|
+
import {
|
|
5
|
+
useColorPickerContext
|
|
6
|
+
} from "./chunk-NR2XCTSD.mjs";
|
|
7
|
+
|
|
8
|
+
// src/color-picker-swatches.tsx
|
|
9
|
+
import { forwardRef, ui } from "@yamada-ui/core";
|
|
10
|
+
import { cx, replaceObject } from "@yamada-ui/utils";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
var ColorPickerSwatches = forwardRef(
|
|
13
|
+
({
|
|
14
|
+
className,
|
|
15
|
+
swatchesLabel,
|
|
16
|
+
swatches,
|
|
17
|
+
swatchesContainerProps,
|
|
18
|
+
swatchProps,
|
|
19
|
+
swatchesColumns,
|
|
20
|
+
...rest
|
|
21
|
+
}, ref) => {
|
|
22
|
+
const { getSwatchProps, readOnly, styles } = useColorPickerContext();
|
|
23
|
+
const css = {
|
|
24
|
+
display: "grid",
|
|
25
|
+
gridTemplateColumns: replaceObject(
|
|
26
|
+
swatchesColumns,
|
|
27
|
+
(value) => value != null ? `repeat(${value}, minmax(0, 1fr))` : void 0
|
|
28
|
+
),
|
|
29
|
+
...styles.swatches
|
|
30
|
+
};
|
|
31
|
+
return (swatches == null ? void 0 : swatches.length) ? /* @__PURE__ */ jsxs(ui.div, { ...swatchesContainerProps, children: [
|
|
32
|
+
swatchesLabel ? /* @__PURE__ */ jsx(
|
|
33
|
+
ui.p,
|
|
34
|
+
{
|
|
35
|
+
className: "ui-color-picker__swatches__label",
|
|
36
|
+
__css: { ...styles.swatchesLabel },
|
|
37
|
+
children: swatchesLabel
|
|
38
|
+
}
|
|
39
|
+
) : null,
|
|
40
|
+
/* @__PURE__ */ jsx(
|
|
41
|
+
ui.div,
|
|
42
|
+
{
|
|
43
|
+
ref,
|
|
44
|
+
className: cx("ui-color-picker__swatches", className),
|
|
45
|
+
__css: css,
|
|
46
|
+
...rest,
|
|
47
|
+
children: swatches.map((color) => /* @__PURE__ */ jsx(
|
|
48
|
+
ColorSwatch,
|
|
49
|
+
{
|
|
50
|
+
as: "button",
|
|
51
|
+
__css: {
|
|
52
|
+
boxSize: "full",
|
|
53
|
+
pointerEvents: readOnly ? "none" : void 0,
|
|
54
|
+
...styles.swatch
|
|
55
|
+
},
|
|
56
|
+
...getSwatchProps({ color, ...swatchProps })
|
|
57
|
+
},
|
|
58
|
+
color
|
|
59
|
+
))
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
] }) : null;
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
ColorPickerSwatches
|
|
68
|
+
};
|