@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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -0
  3. package/dist/alpha-slider.d.mts +62 -0
  4. package/dist/alpha-slider.d.ts +62 -0
  5. package/dist/alpha-slider.js +438 -0
  6. package/dist/alpha-slider.mjs +8 -0
  7. package/dist/chunk-3EO2XBIZ.mjs +54 -0
  8. package/dist/chunk-3KASGDAY.mjs +122 -0
  9. package/dist/chunk-3N443XSV.mjs +105 -0
  10. package/dist/chunk-73BVTMII.mjs +73 -0
  11. package/dist/chunk-7QGCTVDG.mjs +66 -0
  12. package/dist/chunk-DTB2Z3IJ.mjs +278 -0
  13. package/dist/chunk-EMWFECJD.mjs +123 -0
  14. package/dist/chunk-HNVFOSAM.mjs +210 -0
  15. package/dist/chunk-KJS52X4M.mjs +330 -0
  16. package/dist/chunk-MAHWFXUG.mjs +294 -0
  17. package/dist/chunk-N2GG5L7Q.mjs +39 -0
  18. package/dist/chunk-NR2XCTSD.mjs +430 -0
  19. package/dist/chunk-PTTNJPGJ.mjs +98 -0
  20. package/dist/chunk-PVWIBTBL.mjs +67 -0
  21. package/dist/chunk-TFQ62YSQ.mjs +68 -0
  22. package/dist/chunk-U6OJ4TDG.mjs +127 -0
  23. package/dist/color-input.d.mts +79 -0
  24. package/dist/color-input.d.ts +79 -0
  25. package/dist/color-input.js +2283 -0
  26. package/dist/color-input.mjs +21 -0
  27. package/dist/color-picker-body.d.mts +38 -0
  28. package/dist/color-picker-body.d.ts +38 -0
  29. package/dist/color-picker-body.js +794 -0
  30. package/dist/color-picker-body.mjs +14 -0
  31. package/dist/color-picker-channels.d.mts +20 -0
  32. package/dist/color-picker-channels.d.ts +20 -0
  33. package/dist/color-picker-channels.js +101 -0
  34. package/dist/color-picker-channels.mjs +10 -0
  35. package/dist/color-picker-eye-dropper.d.mts +10 -0
  36. package/dist/color-picker-eye-dropper.d.ts +10 -0
  37. package/dist/color-picker-eye-dropper.js +88 -0
  38. package/dist/color-picker-eye-dropper.mjs +10 -0
  39. package/dist/color-picker-sliders.d.mts +30 -0
  40. package/dist/color-picker-sliders.d.ts +30 -0
  41. package/dist/color-picker-sliders.js +590 -0
  42. package/dist/color-picker-sliders.mjs +11 -0
  43. package/dist/color-picker-swatches.d.mts +34 -0
  44. package/dist/color-picker-swatches.d.ts +34 -0
  45. package/dist/color-picker-swatches.js +195 -0
  46. package/dist/color-picker-swatches.mjs +9 -0
  47. package/dist/color-picker.d.mts +59 -0
  48. package/dist/color-picker.d.ts +59 -0
  49. package/dist/color-picker.js +1790 -0
  50. package/dist/color-picker.mjs +19 -0
  51. package/dist/color-swatch.d.mts +36 -0
  52. package/dist/color-swatch.d.ts +36 -0
  53. package/dist/color-swatch.js +124 -0
  54. package/dist/color-swatch.mjs +6 -0
  55. package/dist/hue-slider.d.mts +56 -0
  56. package/dist/hue-slider.d.ts +56 -0
  57. package/dist/hue-slider.js +409 -0
  58. package/dist/hue-slider.mjs +8 -0
  59. package/dist/index.d.mts +23 -0
  60. package/dist/index.d.ts +23 -0
  61. package/dist/index.js +2295 -0
  62. package/dist/index.mjs +36 -0
  63. package/dist/saturation-slider.d.mts +33 -0
  64. package/dist/saturation-slider.d.ts +33 -0
  65. package/dist/saturation-slider.js +414 -0
  66. package/dist/saturation-slider.mjs +7 -0
  67. package/dist/use-color-input.d.mts +90 -0
  68. package/dist/use-color-input.d.ts +90 -0
  69. package/dist/use-color-input.js +340 -0
  70. package/dist/use-color-input.mjs +10 -0
  71. package/dist/use-color-picker.d.mts +131 -0
  72. package/dist/use-color-picker.d.ts +131 -0
  73. package/dist/use-color-picker.js +472 -0
  74. package/dist/use-color-picker.mjs +11 -0
  75. package/dist/use-color-slider.d.mts +69 -0
  76. package/dist/use-color-slider.d.ts +69 -0
  77. package/dist/use-color-slider.js +321 -0
  78. package/dist/use-color-slider.mjs +7 -0
  79. package/dist/use-saturation-slider.d.mts +77 -0
  80. package/dist/use-saturation-slider.d.ts +77 -0
  81. package/dist/use-saturation-slider.js +302 -0
  82. package/dist/use-saturation-slider.mjs +6 -0
  83. package/package.json +88 -0
@@ -0,0 +1,472 @@
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-picker.ts
21
+ var use_color_picker_exports = {};
22
+ __export(use_color_picker_exports, {
23
+ ColorPickerProvider: () => ColorPickerProvider,
24
+ useColorPicker: () => useColorPicker,
25
+ useColorPickerContext: () => useColorPickerContext
26
+ });
27
+ module.exports = __toCommonJS(use_color_picker_exports);
28
+ var import_form_control = require("@yamada-ui/form-control");
29
+ var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
30
+ var import_use_eye_dropper = require("@yamada-ui/use-eye-dropper");
31
+ var import_utils = require("@yamada-ui/utils");
32
+ var import_react = require("react");
33
+
34
+ // ../../utils/src/object.ts
35
+ var pickObject = (obj, keys) => {
36
+ const result = {};
37
+ keys.forEach((key) => {
38
+ if (key in obj)
39
+ result[key] = obj[key];
40
+ });
41
+ return result;
42
+ };
43
+ var getObject = (obj, path, fallback, i) => {
44
+ const k = typeof path === "string" ? path.split(".") : [path];
45
+ for (i = 0; i < k.length; i += 1) {
46
+ if (!obj)
47
+ break;
48
+ obj = obj[k[i]];
49
+ }
50
+ return obj === void 0 ? fallback : obj;
51
+ };
52
+ var memoizeObject = (func) => {
53
+ const cache = /* @__PURE__ */ new WeakMap();
54
+ const memoizedFunc = (obj, path, fallback, i) => {
55
+ if (typeof obj === "undefined")
56
+ return func(obj, path, fallback);
57
+ if (!cache.has(obj))
58
+ cache.set(obj, /* @__PURE__ */ new Map());
59
+ const map = cache.get(obj);
60
+ if (map.has(path))
61
+ return map.get(path);
62
+ const value = func(obj, path, fallback, i);
63
+ map.set(path, value);
64
+ return value;
65
+ };
66
+ return memoizedFunc;
67
+ };
68
+ var getMemoizedObject = memoizeObject(getObject);
69
+
70
+ // src/use-color-picker.ts
71
+ var convertHsla = (value, fallback) => {
72
+ var _a;
73
+ let [h, s, l, a] = (_a = (0, import_utils.parseToHsla)(value, fallback)) != null ? _a : [0, 0, 1, 1];
74
+ if (a > 1)
75
+ a = 1;
76
+ return { h, s, l, a };
77
+ };
78
+ var convertRgba = (value, fallback) => {
79
+ var _a;
80
+ let [r, g, b, a] = (_a = (0, import_utils.parseToRgba)(value, fallback)) != null ? _a : [255, 255, 255, 1];
81
+ if (r > 255)
82
+ r = 255;
83
+ if (g > 255)
84
+ g = 255;
85
+ if (b > 255)
86
+ b = 255;
87
+ if (a > 1)
88
+ a = 1;
89
+ return { r, g, b, a };
90
+ };
91
+ var convertHsva = (value, fallback) => {
92
+ const [h, s, v, a] = (0, import_utils.parseToHsv)(value, fallback);
93
+ return { h, s, v, a };
94
+ };
95
+ var [ColorPickerProvider, useColorPickerContext] = (0, import_utils.createContext)({
96
+ name: "ColorPickerContext",
97
+ errorMessage: `useColorPickerContext returned is 'undefined'. Seems you forgot to wrap the components in "<ColorPicker />"`
98
+ });
99
+ var useColorPicker = ({
100
+ isInvalid,
101
+ ...props
102
+ }) => {
103
+ var _a;
104
+ let {
105
+ id,
106
+ name,
107
+ value: valueProp,
108
+ defaultValue,
109
+ fallbackValue,
110
+ onChange: onChangeProp,
111
+ onChangeStart: onChangeStartProp,
112
+ onChangeEnd: onChangeEndProp,
113
+ format,
114
+ required,
115
+ disabled,
116
+ readOnly,
117
+ onSwatchClick,
118
+ ...rest
119
+ } = (0, import_form_control.useFormControlProps)({ isInvalid, ...props });
120
+ const onChangeStartRef = (0, import_utils.useCallbackRef)(onChangeStartProp);
121
+ const onChangeEndRef = (0, import_utils.useCallbackRef)(onChangeEndProp);
122
+ const { supported: eyeDropperSupported, onOpen } = (0, import_use_eye_dropper.useEyeDropper)();
123
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
124
+ value: valueProp,
125
+ defaultValue: (_a = defaultValue != null ? defaultValue : fallbackValue) != null ? _a : "#ffffffff",
126
+ onChange: onChangeProp
127
+ });
128
+ const timeoutId = (0, import_react.useRef)(void 0);
129
+ const formatRef = (0, import_react.useRef)(format != null ? format : (0, import_utils.calcFormat)(value));
130
+ const isDraggingRef = (0, import_react.useRef)(false);
131
+ const [parsedValue, setParsedValue] = (0, import_react.useState)(
132
+ convertHsva(value, fallbackValue)
133
+ );
134
+ const { h, s, v, a } = parsedValue;
135
+ const withAlpha = formatRef.current.endsWith("a");
136
+ const isInteractive = !(disabled || readOnly);
137
+ const channels = (0, import_react.useMemo)(() => {
138
+ if (value.startsWith("hsl")) {
139
+ const { h: h2, s: s2, l, a: a2 } = convertHsla(value, fallbackValue);
140
+ let channels2 = [
141
+ { label: "H", space: "h", value: Math.round(h2), min: 0, max: 360 },
142
+ {
143
+ label: "S(%)",
144
+ space: "s",
145
+ value: Math.round(s2 * 100),
146
+ min: 0,
147
+ max: 100
148
+ },
149
+ {
150
+ label: "L(%)",
151
+ space: "l",
152
+ value: Math.round(l * 100),
153
+ min: 0,
154
+ max: 100
155
+ }
156
+ ];
157
+ if (withAlpha) {
158
+ channels2 = [
159
+ ...channels2,
160
+ {
161
+ label: "A(%)",
162
+ space: "a",
163
+ value: Math.round(a2 * 100),
164
+ min: 0,
165
+ max: 100
166
+ }
167
+ ];
168
+ }
169
+ return channels2;
170
+ } else {
171
+ const { r, g, b, a: a2 } = convertRgba(value, fallbackValue);
172
+ let channels2 = [
173
+ { label: "R", space: "r", value: Math.round(r), min: 0, max: 255 },
174
+ { label: "G", space: "g", value: Math.round(g), min: 0, max: 255 },
175
+ { label: "B", space: "b", value: Math.round(b), min: 0, max: 255 }
176
+ ];
177
+ if (withAlpha) {
178
+ channels2 = [
179
+ ...channels2,
180
+ {
181
+ label: "A(%)",
182
+ space: "a",
183
+ value: Math.round(a2 * 100),
184
+ min: 0,
185
+ max: 100
186
+ }
187
+ ];
188
+ }
189
+ return channels2;
190
+ }
191
+ }, [value, withAlpha, fallbackValue]);
192
+ const onChange = (0, import_react.useCallback)(
193
+ (value2) => {
194
+ if ((0, import_utils.isString)(value2)) {
195
+ setParsedValue(convertHsva(value2, fallbackValue));
196
+ } else {
197
+ setParsedValue((prev) => ({ ...prev, ...value2 }));
198
+ }
199
+ },
200
+ [fallbackValue]
201
+ );
202
+ const onChangeStart = (0, import_react.useCallback)(
203
+ (value2) => {
204
+ window.clearTimeout(timeoutId.current);
205
+ isDraggingRef.current = true;
206
+ const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
207
+ const nextValue = (0, import_utils.hsvTo)([h2, s2, v2, a2], fallbackValue)(formatRef.current);
208
+ if (nextValue)
209
+ onChangeStartRef(nextValue);
210
+ },
211
+ [formatRef, onChangeStartRef, fallbackValue, parsedValue]
212
+ );
213
+ const onChangeEnd = (0, import_react.useCallback)(
214
+ (value2) => {
215
+ window.clearTimeout(timeoutId.current);
216
+ timeoutId.current = window.setTimeout(() => {
217
+ isDraggingRef.current = false;
218
+ }, 200);
219
+ let nextValue;
220
+ if ((0, import_utils.isString)(value2)) {
221
+ nextValue = (0, import_utils.convertColor)(value2, fallbackValue)(formatRef.current);
222
+ } else {
223
+ const { h: h2, s: s2, v: v2, a: a2 } = { ...parsedValue, ...value2 };
224
+ nextValue = (0, import_utils.hsvTo)([h2, s2, v2, a2], fallbackValue)(formatRef.current);
225
+ }
226
+ if (nextValue)
227
+ onChangeEndRef(nextValue);
228
+ },
229
+ [formatRef, onChangeEndRef, fallbackValue, parsedValue]
230
+ );
231
+ const onChannelChange = (0, import_react.useCallback)(
232
+ (ev, space) => {
233
+ let n = Math.floor(parseFloat(ev.target.value));
234
+ if (isNaN(n))
235
+ n = 0;
236
+ if (["s", "l", "a"].includes(space))
237
+ n = n / 100;
238
+ let nextValue;
239
+ if (value.startsWith("hsl")) {
240
+ const { h: h2, s: s2, l, a: a2 } = Object.assign(
241
+ convertHsla(value, fallbackValue),
242
+ { [space]: n }
243
+ );
244
+ nextValue = (0, import_utils.hslaTo)([h2, s2, l, a2], fallbackValue)(formatRef.current);
245
+ } else {
246
+ const { r, g, b, a: a2 } = Object.assign(
247
+ convertRgba(value, fallbackValue),
248
+ { [space]: n }
249
+ );
250
+ nextValue = (0, import_utils.rgbaTo)([r, g, b, a2], fallbackValue)(formatRef.current);
251
+ }
252
+ if (!nextValue)
253
+ return;
254
+ onChange(nextValue);
255
+ onChangeEnd(nextValue);
256
+ },
257
+ [value, onChange, onChangeEnd, formatRef, fallbackValue]
258
+ );
259
+ const onEyeDropperClick = (0, import_react.useCallback)(async () => {
260
+ var _a2;
261
+ try {
262
+ const { sRGBHex } = (_a2 = await onOpen()) != null ? _a2 : {};
263
+ if (!sRGBHex)
264
+ return;
265
+ onChange(sRGBHex);
266
+ onChangeEnd(sRGBHex);
267
+ } catch {
268
+ }
269
+ }, [onOpen, onChange, onChangeEnd]);
270
+ (0, import_utils.useUpdateEffect)(() => {
271
+ const value2 = (0, import_utils.hsvTo)([h, s, v, a], fallbackValue)(formatRef.current);
272
+ if (value2)
273
+ setValue(value2);
274
+ }, [h, s, v, a, fallbackValue]);
275
+ (0, import_utils.useUpdateEffect)(() => {
276
+ if (isDraggingRef.current)
277
+ return;
278
+ if (valueProp)
279
+ setParsedValue(convertHsva(valueProp, fallbackValue));
280
+ }, [valueProp]);
281
+ (0, import_utils.useUpdateEffect)(() => {
282
+ if (!format)
283
+ return;
284
+ formatRef.current = format;
285
+ const nextValue = (0, import_utils.convertColor)(value, fallbackValue)(format);
286
+ if (nextValue)
287
+ setValue(nextValue);
288
+ }, [format, fallbackValue]);
289
+ const getContainerProps = (props2 = {}, ref = null) => ({
290
+ ...props2,
291
+ ref,
292
+ ...(0, import_utils.omitObject)(rest, ["aria-readonly"])
293
+ });
294
+ const getInputProps = (0, import_react.useCallback)(
295
+ (props2 = {}, ref = null) => ({
296
+ ...pickObject(rest, import_form_control.formControlProperties),
297
+ ...props2,
298
+ id,
299
+ ref,
300
+ type: "hidden",
301
+ name,
302
+ value,
303
+ required,
304
+ disabled,
305
+ readOnly
306
+ }),
307
+ [disabled, id, name, readOnly, required, rest, value]
308
+ );
309
+ const getSaturationSliderProps = (0, import_react.useCallback)(
310
+ (props2 = {}, ref = null) => ({
311
+ required,
312
+ disabled,
313
+ readOnly,
314
+ isInvalid,
315
+ ...props2,
316
+ ref,
317
+ value: [h, s, v],
318
+ onChange: (0, import_utils.handlerAll)(props2.onChange, ([, s2, v2]) => onChange({ s: s2, v: v2 })),
319
+ onChangeStart: (0, import_utils.handlerAll)(
320
+ props2.onChangeStart,
321
+ ([, s2, v2]) => onChangeStart({ s: s2, v: v2 })
322
+ ),
323
+ onChangeEnd: (0, import_utils.handlerAll)(
324
+ props2.onChangeEnd,
325
+ ([, s2, v2]) => onChangeEnd({ s: s2, v: v2 })
326
+ )
327
+ }),
328
+ [
329
+ required,
330
+ disabled,
331
+ readOnly,
332
+ isInvalid,
333
+ h,
334
+ s,
335
+ v,
336
+ onChange,
337
+ onChangeStart,
338
+ onChangeEnd
339
+ ]
340
+ );
341
+ const getHueSliderProps = (0, import_react.useCallback)(
342
+ (props2 = {}, ref = null) => ({
343
+ required,
344
+ disabled,
345
+ readOnly,
346
+ isInvalid,
347
+ ...props2,
348
+ ref,
349
+ value: h,
350
+ onChange: (0, import_utils.handlerAll)(props2.onChange, (h2) => onChange({ h: h2 })),
351
+ onChangeStart: (0, import_utils.handlerAll)(
352
+ props2.onChangeStart,
353
+ (h2) => onChangeStart({ h: h2 })
354
+ ),
355
+ onChangeEnd: (0, import_utils.handlerAll)(props2.onChangeEnd, (h2) => onChangeEnd({ h: h2 }))
356
+ }),
357
+ [
358
+ required,
359
+ disabled,
360
+ readOnly,
361
+ isInvalid,
362
+ h,
363
+ onChange,
364
+ onChangeStart,
365
+ onChangeEnd
366
+ ]
367
+ );
368
+ const getAlphaSliderProps = (0, import_react.useCallback)(
369
+ (props2 = {}, ref = null) => ({
370
+ required,
371
+ disabled,
372
+ readOnly,
373
+ isInvalid,
374
+ ...props2,
375
+ ref,
376
+ value: a,
377
+ color: (0, import_utils.hsvTo)([h, s, v, a], fallbackValue)(formatRef.current),
378
+ onChange: (0, import_utils.handlerAll)(props2.onChange, (a2) => onChange({ a: a2 })),
379
+ onChangeStart: (0, import_utils.handlerAll)(
380
+ props2.onChangeStart,
381
+ (a2) => onChangeStart({ a: a2 })
382
+ ),
383
+ onChangeEnd: (0, import_utils.handlerAll)(props2.onChangeEnd, (a2) => onChangeEnd({ a: a2 }))
384
+ }),
385
+ [
386
+ fallbackValue,
387
+ required,
388
+ disabled,
389
+ readOnly,
390
+ isInvalid,
391
+ formatRef,
392
+ h,
393
+ s,
394
+ v,
395
+ a,
396
+ onChange,
397
+ onChangeStart,
398
+ onChangeEnd
399
+ ]
400
+ );
401
+ const getChannelProps = (0, import_react.useCallback)(
402
+ ({ space, ...props2 }, ref = null) => {
403
+ return {
404
+ required,
405
+ disabled,
406
+ readOnly,
407
+ isInvalid,
408
+ ...props2,
409
+ ref,
410
+ type: "number",
411
+ step: 1,
412
+ onChange: (0, import_utils.handlerAll)(
413
+ props2.onChange,
414
+ (ev) => onChannelChange(ev, space)
415
+ )
416
+ };
417
+ },
418
+ [required, disabled, readOnly, isInvalid, onChannelChange]
419
+ );
420
+ const getEyeDropperProps = (0, import_react.useCallback)(
421
+ (props2 = {}, ref = null) => ({
422
+ disabled,
423
+ "aria-label": "Pick a color",
424
+ ...props2,
425
+ ref,
426
+ onClick: (0, import_utils.handlerAll)(props2.onClick, onEyeDropperClick)
427
+ }),
428
+ [disabled, onEyeDropperClick]
429
+ );
430
+ const getSwatchProps = (0, import_react.useCallback)(
431
+ ({ color, ...props2 } = {}, ref = null) => ({
432
+ "aria-label": `select ${color} as the color`,
433
+ disabled,
434
+ readOnly,
435
+ ...props2,
436
+ ref,
437
+ color,
438
+ onClick: (0, import_utils.handlerAll)(props2.onClick, () => {
439
+ if (!color)
440
+ return;
441
+ onSwatchClick == null ? void 0 : onSwatchClick(color);
442
+ onChange(color);
443
+ onChangeEnd(color);
444
+ })
445
+ }),
446
+ [disabled, readOnly, onSwatchClick, onChange, onChangeEnd]
447
+ );
448
+ return {
449
+ value,
450
+ onChange,
451
+ eyeDropperSupported,
452
+ withAlpha,
453
+ isInteractive,
454
+ disabled,
455
+ readOnly,
456
+ channels,
457
+ getContainerProps,
458
+ getInputProps,
459
+ getSaturationSliderProps,
460
+ getHueSliderProps,
461
+ getAlphaSliderProps,
462
+ getEyeDropperProps,
463
+ getChannelProps,
464
+ getSwatchProps
465
+ };
466
+ };
467
+ // Annotate the CommonJS export names for ESM import in node:
468
+ 0 && (module.exports = {
469
+ ColorPickerProvider,
470
+ useColorPicker,
471
+ useColorPickerContext
472
+ });
@@ -0,0 +1,11 @@
1
+ import {
2
+ ColorPickerProvider,
3
+ useColorPicker,
4
+ useColorPickerContext
5
+ } from "./chunk-NR2XCTSD.mjs";
6
+ import "./chunk-N2GG5L7Q.mjs";
7
+ export {
8
+ ColorPickerProvider,
9
+ useColorPicker,
10
+ useColorPickerContext
11
+ };
@@ -0,0 +1,69 @@
1
+ import { HTMLUIProps, UIPropGetter, CSSUIProps } from '@yamada-ui/core';
2
+ import { FormControlOptions } from '@yamada-ui/form-control';
3
+
4
+ type UseColorSliderOptions = {
5
+ /**
6
+ * The base `id` to use for the slider.
7
+ */
8
+ id?: string;
9
+ /**
10
+ * The name attribute of the hidden `input` field.
11
+ * This is particularly useful in forms.
12
+ */
13
+ name?: string;
14
+ /**
15
+ * The value of the slider.
16
+ */
17
+ value?: number;
18
+ /**
19
+ * The initial value of the slider.
20
+ */
21
+ defaultValue?: number;
22
+ /**
23
+ * The minimum allowed value of the slider. Cannot be greater than max.
24
+ */
25
+ min: number;
26
+ /**
27
+ * The maximum allowed value of the slider. Cannot be less than min.
28
+ */
29
+ max: number;
30
+ /**
31
+ * The step in which increments or decrements have to be made.
32
+ *
33
+ * @default 1
34
+ */
35
+ step?: number;
36
+ /**
37
+ * Function called whenever the slider value changes.
38
+ */
39
+ onChange?: (value: number) => void;
40
+ /**
41
+ * Function called when the user starts selecting a new value.
42
+ */
43
+ onChangeStart?: (value: number) => void;
44
+ /**
45
+ * Function called when the user is done selecting a new value.
46
+ */
47
+ onChangeEnd?: (value: number) => void;
48
+ /**
49
+ * If `false`, the slider handle will not capture focus when value changes.
50
+ *
51
+ * @default true
52
+ */
53
+ focusThumbOnChange?: boolean;
54
+ /**
55
+ * The CSS `background` property. Used in `background` of thumb element.
56
+ */
57
+ thumbColor?: CSSUIProps["bg"];
58
+ };
59
+ type UseColorSliderProps = Omit<HTMLUIProps<"div">, "defaultValue" | "onChange"> & UseColorSliderOptions & FormControlOptions;
60
+ declare const useColorSlider: ({ focusThumbOnChange, ...props }: UseColorSliderProps) => {
61
+ value: number;
62
+ getContainerProps: UIPropGetter;
63
+ getTrackProps: UIPropGetter;
64
+ getInputProps: UIPropGetter<"input">;
65
+ getThumbProps: UIPropGetter;
66
+ };
67
+ type UseColorSliderReturn = ReturnType<typeof useColorSlider>;
68
+
69
+ export { type UseColorSliderProps, type UseColorSliderReturn, useColorSlider };
@@ -0,0 +1,69 @@
1
+ import { HTMLUIProps, UIPropGetter, CSSUIProps } from '@yamada-ui/core';
2
+ import { FormControlOptions } from '@yamada-ui/form-control';
3
+
4
+ type UseColorSliderOptions = {
5
+ /**
6
+ * The base `id` to use for the slider.
7
+ */
8
+ id?: string;
9
+ /**
10
+ * The name attribute of the hidden `input` field.
11
+ * This is particularly useful in forms.
12
+ */
13
+ name?: string;
14
+ /**
15
+ * The value of the slider.
16
+ */
17
+ value?: number;
18
+ /**
19
+ * The initial value of the slider.
20
+ */
21
+ defaultValue?: number;
22
+ /**
23
+ * The minimum allowed value of the slider. Cannot be greater than max.
24
+ */
25
+ min: number;
26
+ /**
27
+ * The maximum allowed value of the slider. Cannot be less than min.
28
+ */
29
+ max: number;
30
+ /**
31
+ * The step in which increments or decrements have to be made.
32
+ *
33
+ * @default 1
34
+ */
35
+ step?: number;
36
+ /**
37
+ * Function called whenever the slider value changes.
38
+ */
39
+ onChange?: (value: number) => void;
40
+ /**
41
+ * Function called when the user starts selecting a new value.
42
+ */
43
+ onChangeStart?: (value: number) => void;
44
+ /**
45
+ * Function called when the user is done selecting a new value.
46
+ */
47
+ onChangeEnd?: (value: number) => void;
48
+ /**
49
+ * If `false`, the slider handle will not capture focus when value changes.
50
+ *
51
+ * @default true
52
+ */
53
+ focusThumbOnChange?: boolean;
54
+ /**
55
+ * The CSS `background` property. Used in `background` of thumb element.
56
+ */
57
+ thumbColor?: CSSUIProps["bg"];
58
+ };
59
+ type UseColorSliderProps = Omit<HTMLUIProps<"div">, "defaultValue" | "onChange"> & UseColorSliderOptions & FormControlOptions;
60
+ declare const useColorSlider: ({ focusThumbOnChange, ...props }: UseColorSliderProps) => {
61
+ value: number;
62
+ getContainerProps: UIPropGetter;
63
+ getTrackProps: UIPropGetter;
64
+ getInputProps: UIPropGetter<"input">;
65
+ getThumbProps: UIPropGetter;
66
+ };
67
+ type UseColorSliderReturn = ReturnType<typeof useColorSlider>;
68
+
69
+ export { type UseColorSliderProps, type UseColorSliderReturn, useColorSlider };