@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,321 @@
|
|
|
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-slider.ts
|
|
21
|
+
var use_color_slider_exports = {};
|
|
22
|
+
__export(use_color_slider_exports, {
|
|
23
|
+
useColorSlider: () => useColorSlider
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(use_color_slider_exports);
|
|
26
|
+
var import_form_control = require("@yamada-ui/form-control");
|
|
27
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
28
|
+
var import_use_latest_ref = require("@yamada-ui/use-latest-ref");
|
|
29
|
+
var import_use_pan_event = require("@yamada-ui/use-pan-event");
|
|
30
|
+
var import_use_size = require("@yamada-ui/use-size");
|
|
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-slider.ts
|
|
71
|
+
var useColorSlider = ({
|
|
72
|
+
focusThumbOnChange = true,
|
|
73
|
+
...props
|
|
74
|
+
}) => {
|
|
75
|
+
if (!focusThumbOnChange)
|
|
76
|
+
props.isReadOnly = true;
|
|
77
|
+
let {
|
|
78
|
+
id,
|
|
79
|
+
name,
|
|
80
|
+
value: valueProp,
|
|
81
|
+
defaultValue,
|
|
82
|
+
min = 0,
|
|
83
|
+
max,
|
|
84
|
+
step = 1,
|
|
85
|
+
onChange: onChangeProp,
|
|
86
|
+
onChangeStart: onChangeStartProp,
|
|
87
|
+
onChangeEnd: onChangeEndProp,
|
|
88
|
+
thumbColor,
|
|
89
|
+
required,
|
|
90
|
+
disabled,
|
|
91
|
+
readOnly,
|
|
92
|
+
...rest
|
|
93
|
+
} = (0, import_form_control.useFormControlProps)(props);
|
|
94
|
+
const onChangeStart = (0, import_utils.useCallbackRef)(onChangeStartProp);
|
|
95
|
+
const onChangeEnd = (0, import_utils.useCallbackRef)(onChangeEndProp);
|
|
96
|
+
const [computedValue, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
97
|
+
value: valueProp,
|
|
98
|
+
defaultValue: defaultValue != null ? defaultValue : min + (max - min) / 2,
|
|
99
|
+
onChange: onChangeProp
|
|
100
|
+
});
|
|
101
|
+
const value = (0, import_utils.clampNumber)(computedValue, min, max);
|
|
102
|
+
const thumbPercent = (0, import_utils.valueToPercent)(value, min, max);
|
|
103
|
+
const [isDragging, setDragging] = (0, import_react.useState)(false);
|
|
104
|
+
const isInteractive = !(disabled || readOnly);
|
|
105
|
+
const oneStep = step || (max - min) / 100;
|
|
106
|
+
const tenStep = (max - min) / 10;
|
|
107
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
108
|
+
const trackRef = (0, import_react.useRef)(null);
|
|
109
|
+
const thumbRef = (0, import_react.useRef)(null);
|
|
110
|
+
const latestRef = (0, import_use_latest_ref.useLatestRef)({
|
|
111
|
+
value,
|
|
112
|
+
min,
|
|
113
|
+
max,
|
|
114
|
+
step,
|
|
115
|
+
isInteractive,
|
|
116
|
+
eventSource: null,
|
|
117
|
+
focusThumbOnChange
|
|
118
|
+
});
|
|
119
|
+
const thumbSize = (0, import_use_size.useSize)(thumbRef);
|
|
120
|
+
const getValueFromPointer = (0, import_react.useCallback)(
|
|
121
|
+
(ev) => {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
if (!trackRef.current)
|
|
124
|
+
return;
|
|
125
|
+
const { min: min2, max: max2, step: step2 } = latestRef.current;
|
|
126
|
+
latestRef.current.eventSource = "pointer";
|
|
127
|
+
const { left, width } = trackRef.current.getBoundingClientRect();
|
|
128
|
+
const { clientX } = (_b = (_a = ev.touches) == null ? void 0 : _a[0]) != null ? _b : ev;
|
|
129
|
+
let percent = (clientX - left) / width;
|
|
130
|
+
let nextValue = (0, import_utils.percentToValue)(percent, min2, max2);
|
|
131
|
+
if (step2)
|
|
132
|
+
nextValue = parseFloat((0, import_utils.roundNumberToStep)(nextValue, min2, step2));
|
|
133
|
+
nextValue = (0, import_utils.clampNumber)(nextValue, min2, max2);
|
|
134
|
+
return nextValue;
|
|
135
|
+
},
|
|
136
|
+
[latestRef]
|
|
137
|
+
);
|
|
138
|
+
const setValueFromPointer = (ev) => {
|
|
139
|
+
const { value: value2 } = latestRef.current;
|
|
140
|
+
const nextValue = getValueFromPointer(ev);
|
|
141
|
+
if (nextValue != null && nextValue !== value2)
|
|
142
|
+
setValue(nextValue);
|
|
143
|
+
};
|
|
144
|
+
const focusThumb = (0, import_react.useCallback)(() => {
|
|
145
|
+
const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
|
|
146
|
+
if (focusThumbOnChange2)
|
|
147
|
+
setTimeout(() => {
|
|
148
|
+
var _a;
|
|
149
|
+
return (_a = thumbRef.current) == null ? void 0 : _a.focus();
|
|
150
|
+
});
|
|
151
|
+
}, [latestRef]);
|
|
152
|
+
const constrain = (0, import_react.useCallback)(
|
|
153
|
+
(value2) => {
|
|
154
|
+
const { isInteractive: isInteractive2, min: min2, max: max2 } = latestRef.current;
|
|
155
|
+
if (!isInteractive2)
|
|
156
|
+
return;
|
|
157
|
+
value2 = parseFloat((0, import_utils.roundNumberToStep)(value2, min2, oneStep));
|
|
158
|
+
value2 = (0, import_utils.clampNumber)(value2, min2, max2);
|
|
159
|
+
setValue(value2);
|
|
160
|
+
},
|
|
161
|
+
[setValue, latestRef, oneStep]
|
|
162
|
+
);
|
|
163
|
+
const stepUp = (0, import_react.useCallback)(
|
|
164
|
+
(step2 = oneStep) => constrain(value + step2),
|
|
165
|
+
[constrain, value, oneStep]
|
|
166
|
+
);
|
|
167
|
+
const stepDown = (0, import_react.useCallback)(
|
|
168
|
+
(step2 = oneStep) => constrain(value - step2),
|
|
169
|
+
[constrain, value, oneStep]
|
|
170
|
+
);
|
|
171
|
+
const onKeyDown = (0, import_react.useCallback)(
|
|
172
|
+
(ev) => {
|
|
173
|
+
const { min: min2, max: max2 } = latestRef.current;
|
|
174
|
+
const actions = {
|
|
175
|
+
ArrowRight: () => stepUp(),
|
|
176
|
+
ArrowUp: () => stepUp(),
|
|
177
|
+
ArrowLeft: () => stepDown(),
|
|
178
|
+
ArrowDown: () => stepDown(),
|
|
179
|
+
PageUp: () => stepUp(tenStep),
|
|
180
|
+
PageDown: () => stepDown(tenStep),
|
|
181
|
+
Home: () => constrain(min2),
|
|
182
|
+
End: () => constrain(max2)
|
|
183
|
+
};
|
|
184
|
+
const action = actions[ev.key];
|
|
185
|
+
if (!action)
|
|
186
|
+
return;
|
|
187
|
+
ev.preventDefault();
|
|
188
|
+
ev.stopPropagation();
|
|
189
|
+
action(ev);
|
|
190
|
+
latestRef.current.eventSource = "keyboard";
|
|
191
|
+
},
|
|
192
|
+
[constrain, latestRef, stepDown, stepUp, tenStep]
|
|
193
|
+
);
|
|
194
|
+
(0, import_use_pan_event.usePanEvent)(containerRef, {
|
|
195
|
+
onSessionStart: (ev) => {
|
|
196
|
+
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
|
197
|
+
if (!isInteractive2)
|
|
198
|
+
return;
|
|
199
|
+
setDragging(true);
|
|
200
|
+
focusThumb();
|
|
201
|
+
setValueFromPointer(ev);
|
|
202
|
+
onChangeStart(value2);
|
|
203
|
+
},
|
|
204
|
+
onSessionEnd: () => {
|
|
205
|
+
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
|
206
|
+
if (!isInteractive2)
|
|
207
|
+
return;
|
|
208
|
+
setDragging(false);
|
|
209
|
+
onChangeEnd(value2);
|
|
210
|
+
},
|
|
211
|
+
onMove: (ev) => {
|
|
212
|
+
const { isInteractive: isInteractive2 } = latestRef.current;
|
|
213
|
+
if (!isInteractive2)
|
|
214
|
+
return;
|
|
215
|
+
setValueFromPointer(ev);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
219
|
+
const { eventSource, value: value2 } = latestRef.current;
|
|
220
|
+
if (eventSource === "keyboard")
|
|
221
|
+
onChangeEnd(value2);
|
|
222
|
+
}, [value, onChangeEnd]);
|
|
223
|
+
const getContainerProps = (0, import_react.useCallback)(
|
|
224
|
+
(props2 = {}, ref = null) => {
|
|
225
|
+
const { width: w } = thumbSize != null ? thumbSize : { width: 0 };
|
|
226
|
+
const style = {
|
|
227
|
+
...props2.style,
|
|
228
|
+
...rest.style,
|
|
229
|
+
paddingInline: `${w / 2}px`
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
...props2,
|
|
233
|
+
...(0, import_utils.omitObject)(rest, ["aria-readonly"]),
|
|
234
|
+
ref: (0, import_utils.mergeRefs)(ref, containerRef),
|
|
235
|
+
tabIndex: -1,
|
|
236
|
+
style
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
[rest, thumbSize]
|
|
240
|
+
);
|
|
241
|
+
const getInputProps = (0, import_react.useCallback)(
|
|
242
|
+
(props2 = {}, ref = null) => ({
|
|
243
|
+
...pickObject(rest, import_form_control.formControlProperties),
|
|
244
|
+
...props2,
|
|
245
|
+
id,
|
|
246
|
+
ref,
|
|
247
|
+
type: "hidden",
|
|
248
|
+
name,
|
|
249
|
+
value,
|
|
250
|
+
required,
|
|
251
|
+
disabled,
|
|
252
|
+
readOnly
|
|
253
|
+
}),
|
|
254
|
+
[disabled, id, name, readOnly, required, rest, value]
|
|
255
|
+
);
|
|
256
|
+
const getTrackProps = (0, import_react.useCallback)(
|
|
257
|
+
(props2 = {}, ref = null) => ({
|
|
258
|
+
...pickObject(
|
|
259
|
+
rest,
|
|
260
|
+
(0, import_form_control.getFormControlProperties)({ omit: ["aria-readonly"] })
|
|
261
|
+
),
|
|
262
|
+
...props2,
|
|
263
|
+
ref: (0, import_utils.mergeRefs)(ref, trackRef)
|
|
264
|
+
}),
|
|
265
|
+
[rest]
|
|
266
|
+
);
|
|
267
|
+
const getThumbProps = (0, import_react.useCallback)(
|
|
268
|
+
(props2 = {}, ref = null) => {
|
|
269
|
+
const n = thumbPercent;
|
|
270
|
+
const { width: w } = thumbSize != null ? thumbSize : { width: 0 };
|
|
271
|
+
const style = {
|
|
272
|
+
...props2.style,
|
|
273
|
+
position: "absolute",
|
|
274
|
+
userSelect: "none",
|
|
275
|
+
touchAction: "none",
|
|
276
|
+
left: `calc(${n}% - ${w / 2}px)`
|
|
277
|
+
};
|
|
278
|
+
return {
|
|
279
|
+
"aria-label": "Slider thumb",
|
|
280
|
+
bg: thumbColor != null ? thumbColor : `hsl(${value}, 100%, 50%)`,
|
|
281
|
+
...pickObject(rest, import_form_control.formControlProperties),
|
|
282
|
+
...props2,
|
|
283
|
+
ref: (0, import_utils.mergeRefs)(ref, thumbRef),
|
|
284
|
+
tabIndex: isInteractive && focusThumbOnChange ? 0 : void 0,
|
|
285
|
+
role: "slider",
|
|
286
|
+
"aria-valuenow": value,
|
|
287
|
+
"aria-valuemin": min,
|
|
288
|
+
"aria-valuemax": max,
|
|
289
|
+
"data-active": (0, import_utils.dataAttr)(isDragging && focusThumbOnChange),
|
|
290
|
+
onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, onKeyDown),
|
|
291
|
+
onFocus: (0, import_utils.handlerAll)(props2.onFocus, rest.onFocus),
|
|
292
|
+
onBlur: (0, import_utils.handlerAll)(props2.onBlur, rest.onBlur),
|
|
293
|
+
style
|
|
294
|
+
};
|
|
295
|
+
},
|
|
296
|
+
[
|
|
297
|
+
thumbColor,
|
|
298
|
+
focusThumbOnChange,
|
|
299
|
+
isDragging,
|
|
300
|
+
isInteractive,
|
|
301
|
+
min,
|
|
302
|
+
max,
|
|
303
|
+
onKeyDown,
|
|
304
|
+
rest,
|
|
305
|
+
thumbPercent,
|
|
306
|
+
thumbSize,
|
|
307
|
+
value
|
|
308
|
+
]
|
|
309
|
+
);
|
|
310
|
+
return {
|
|
311
|
+
value,
|
|
312
|
+
getContainerProps,
|
|
313
|
+
getTrackProps,
|
|
314
|
+
getInputProps,
|
|
315
|
+
getThumbProps
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
319
|
+
0 && (module.exports = {
|
|
320
|
+
useColorSlider
|
|
321
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { HTMLUIProps, UIPropGetter, CSSUIProps } from '@yamada-ui/core';
|
|
2
|
+
import { FormControlOptions } from '@yamada-ui/form-control';
|
|
3
|
+
|
|
4
|
+
type Hsv = [number, number, number];
|
|
5
|
+
type Overlay = HTMLUIProps<"div"> | ((value: Hsv) => HTMLUIProps<"div">);
|
|
6
|
+
type UseSaturationSliderOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The base `id` to use for the saturation slider.
|
|
9
|
+
*/
|
|
10
|
+
id?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The name attribute of the hidden `input` field.
|
|
13
|
+
* This is particularly useful in forms.
|
|
14
|
+
*/
|
|
15
|
+
name?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The value of the saturation slider.
|
|
18
|
+
*/
|
|
19
|
+
value?: Hsv;
|
|
20
|
+
/**
|
|
21
|
+
* The initial value of the saturation slider.
|
|
22
|
+
*
|
|
23
|
+
* @default "[0, 0, 1]"
|
|
24
|
+
*/
|
|
25
|
+
defaultValue?: Hsv;
|
|
26
|
+
/**
|
|
27
|
+
* Function called whenever the saturation slider value changes.
|
|
28
|
+
*/
|
|
29
|
+
onChange?: (value: Hsv) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Function called when the user starts selecting a new value.
|
|
32
|
+
*/
|
|
33
|
+
onChangeStart?: (value: Hsv) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Function called when the user is done selecting a new value.
|
|
36
|
+
*/
|
|
37
|
+
onChangeEnd?: (value: Hsv) => void;
|
|
38
|
+
/**
|
|
39
|
+
* The step in which increments or decrements have to be made.
|
|
40
|
+
*
|
|
41
|
+
* @default 0.01
|
|
42
|
+
*/
|
|
43
|
+
step?: number;
|
|
44
|
+
/**
|
|
45
|
+
* If `false`, the saturation slider handle will not capture focus when value changes.
|
|
46
|
+
*
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
focusThumbOnChange?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The CSS `background` property. Used in `background` of thumb element.
|
|
52
|
+
*/
|
|
53
|
+
thumbColor?: CSSUIProps["bg"];
|
|
54
|
+
/**
|
|
55
|
+
* If `true`, the slider has an inner `box-shadow`.
|
|
56
|
+
*
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
withShadow?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* The overlay used for the saturation slider.
|
|
62
|
+
*/
|
|
63
|
+
overlays?: Overlay[];
|
|
64
|
+
};
|
|
65
|
+
type UseSaturationSliderProps = Omit<HTMLUIProps<"div">, "defaultValue" | "onChange"> & UseSaturationSliderOptions & FormControlOptions;
|
|
66
|
+
declare const useSaturationSlider: ({ focusThumbOnChange, ...props }: UseSaturationSliderProps) => {
|
|
67
|
+
value: [number, number, number];
|
|
68
|
+
overlays: HTMLUIProps<"div">[];
|
|
69
|
+
getContainerProps: UIPropGetter;
|
|
70
|
+
getInnerProps: UIPropGetter;
|
|
71
|
+
getTrackProps: UIPropGetter;
|
|
72
|
+
getInputProps: UIPropGetter<"input">;
|
|
73
|
+
getThumbProps: UIPropGetter;
|
|
74
|
+
};
|
|
75
|
+
type UseSaturationSliderReturn = ReturnType<typeof useSaturationSlider>;
|
|
76
|
+
|
|
77
|
+
export { type Hsv, type UseSaturationSliderProps, type UseSaturationSliderReturn, useSaturationSlider };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { HTMLUIProps, UIPropGetter, CSSUIProps } from '@yamada-ui/core';
|
|
2
|
+
import { FormControlOptions } from '@yamada-ui/form-control';
|
|
3
|
+
|
|
4
|
+
type Hsv = [number, number, number];
|
|
5
|
+
type Overlay = HTMLUIProps<"div"> | ((value: Hsv) => HTMLUIProps<"div">);
|
|
6
|
+
type UseSaturationSliderOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The base `id` to use for the saturation slider.
|
|
9
|
+
*/
|
|
10
|
+
id?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The name attribute of the hidden `input` field.
|
|
13
|
+
* This is particularly useful in forms.
|
|
14
|
+
*/
|
|
15
|
+
name?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The value of the saturation slider.
|
|
18
|
+
*/
|
|
19
|
+
value?: Hsv;
|
|
20
|
+
/**
|
|
21
|
+
* The initial value of the saturation slider.
|
|
22
|
+
*
|
|
23
|
+
* @default "[0, 0, 1]"
|
|
24
|
+
*/
|
|
25
|
+
defaultValue?: Hsv;
|
|
26
|
+
/**
|
|
27
|
+
* Function called whenever the saturation slider value changes.
|
|
28
|
+
*/
|
|
29
|
+
onChange?: (value: Hsv) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Function called when the user starts selecting a new value.
|
|
32
|
+
*/
|
|
33
|
+
onChangeStart?: (value: Hsv) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Function called when the user is done selecting a new value.
|
|
36
|
+
*/
|
|
37
|
+
onChangeEnd?: (value: Hsv) => void;
|
|
38
|
+
/**
|
|
39
|
+
* The step in which increments or decrements have to be made.
|
|
40
|
+
*
|
|
41
|
+
* @default 0.01
|
|
42
|
+
*/
|
|
43
|
+
step?: number;
|
|
44
|
+
/**
|
|
45
|
+
* If `false`, the saturation slider handle will not capture focus when value changes.
|
|
46
|
+
*
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
focusThumbOnChange?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The CSS `background` property. Used in `background` of thumb element.
|
|
52
|
+
*/
|
|
53
|
+
thumbColor?: CSSUIProps["bg"];
|
|
54
|
+
/**
|
|
55
|
+
* If `true`, the slider has an inner `box-shadow`.
|
|
56
|
+
*
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
withShadow?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* The overlay used for the saturation slider.
|
|
62
|
+
*/
|
|
63
|
+
overlays?: Overlay[];
|
|
64
|
+
};
|
|
65
|
+
type UseSaturationSliderProps = Omit<HTMLUIProps<"div">, "defaultValue" | "onChange"> & UseSaturationSliderOptions & FormControlOptions;
|
|
66
|
+
declare const useSaturationSlider: ({ focusThumbOnChange, ...props }: UseSaturationSliderProps) => {
|
|
67
|
+
value: [number, number, number];
|
|
68
|
+
overlays: HTMLUIProps<"div">[];
|
|
69
|
+
getContainerProps: UIPropGetter;
|
|
70
|
+
getInnerProps: UIPropGetter;
|
|
71
|
+
getTrackProps: UIPropGetter;
|
|
72
|
+
getInputProps: UIPropGetter<"input">;
|
|
73
|
+
getThumbProps: UIPropGetter;
|
|
74
|
+
};
|
|
75
|
+
type UseSaturationSliderReturn = ReturnType<typeof useSaturationSlider>;
|
|
76
|
+
|
|
77
|
+
export { type Hsv, type UseSaturationSliderProps, type UseSaturationSliderReturn, useSaturationSlider };
|