@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
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ColorInput
|
|
3
|
+
} from "./chunk-HNVFOSAM.mjs";
|
|
4
|
+
import "./chunk-KJS52X4M.mjs";
|
|
5
|
+
import {
|
|
6
|
+
ColorPicker
|
|
7
|
+
} from "./chunk-EMWFECJD.mjs";
|
|
8
|
+
import {
|
|
9
|
+
SaturationSlider
|
|
10
|
+
} from "./chunk-3KASGDAY.mjs";
|
|
11
|
+
import "./chunk-MAHWFXUG.mjs";
|
|
12
|
+
import "./chunk-73BVTMII.mjs";
|
|
13
|
+
import "./chunk-PVWIBTBL.mjs";
|
|
14
|
+
import "./chunk-3EO2XBIZ.mjs";
|
|
15
|
+
import "./chunk-7QGCTVDG.mjs";
|
|
16
|
+
import {
|
|
17
|
+
HueSlider
|
|
18
|
+
} from "./chunk-PTTNJPGJ.mjs";
|
|
19
|
+
import {
|
|
20
|
+
AlphaSlider
|
|
21
|
+
} from "./chunk-U6OJ4TDG.mjs";
|
|
22
|
+
import "./chunk-DTB2Z3IJ.mjs";
|
|
23
|
+
import "./chunk-TFQ62YSQ.mjs";
|
|
24
|
+
import {
|
|
25
|
+
ColorSwatch
|
|
26
|
+
} from "./chunk-3N443XSV.mjs";
|
|
27
|
+
import "./chunk-NR2XCTSD.mjs";
|
|
28
|
+
import "./chunk-N2GG5L7Q.mjs";
|
|
29
|
+
export {
|
|
30
|
+
AlphaSlider,
|
|
31
|
+
ColorInput,
|
|
32
|
+
ColorPicker,
|
|
33
|
+
ColorSwatch,
|
|
34
|
+
HueSlider,
|
|
35
|
+
SaturationSlider
|
|
36
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { ThemeProps, Token, HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
+
import { UseSaturationSliderProps } from './use-saturation-slider.mjs';
|
|
4
|
+
import '@yamada-ui/form-control';
|
|
5
|
+
|
|
6
|
+
type SaturationSliderOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The aspect ratio of the saturation slider.
|
|
9
|
+
*
|
|
10
|
+
* @default '16 / 9'
|
|
11
|
+
*/
|
|
12
|
+
ratio?: Token<number>;
|
|
13
|
+
/**
|
|
14
|
+
* Props for saturation slider inner element.
|
|
15
|
+
*/
|
|
16
|
+
innerProps?: HTMLUIProps<"div">;
|
|
17
|
+
/**
|
|
18
|
+
* Props for saturation slider input element.
|
|
19
|
+
*/
|
|
20
|
+
inputProps?: HTMLUIProps<"input">;
|
|
21
|
+
/**
|
|
22
|
+
* Props for saturation slider track element.
|
|
23
|
+
*/
|
|
24
|
+
trackProps?: HTMLUIProps<"div">;
|
|
25
|
+
/**
|
|
26
|
+
* Props for saturation slider thumb element.
|
|
27
|
+
*/
|
|
28
|
+
thumbProps?: HTMLUIProps<"div">;
|
|
29
|
+
};
|
|
30
|
+
type SaturationSliderProps = ThemeProps<"SaturationSlider"> & UseSaturationSliderProps & SaturationSliderOptions;
|
|
31
|
+
declare const SaturationSlider: _yamada_ui_core.Component<"input", SaturationSliderProps>;
|
|
32
|
+
|
|
33
|
+
export { SaturationSlider, type SaturationSliderProps };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { ThemeProps, Token, HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
+
import { UseSaturationSliderProps } from './use-saturation-slider.js';
|
|
4
|
+
import '@yamada-ui/form-control';
|
|
5
|
+
|
|
6
|
+
type SaturationSliderOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The aspect ratio of the saturation slider.
|
|
9
|
+
*
|
|
10
|
+
* @default '16 / 9'
|
|
11
|
+
*/
|
|
12
|
+
ratio?: Token<number>;
|
|
13
|
+
/**
|
|
14
|
+
* Props for saturation slider inner element.
|
|
15
|
+
*/
|
|
16
|
+
innerProps?: HTMLUIProps<"div">;
|
|
17
|
+
/**
|
|
18
|
+
* Props for saturation slider input element.
|
|
19
|
+
*/
|
|
20
|
+
inputProps?: HTMLUIProps<"input">;
|
|
21
|
+
/**
|
|
22
|
+
* Props for saturation slider track element.
|
|
23
|
+
*/
|
|
24
|
+
trackProps?: HTMLUIProps<"div">;
|
|
25
|
+
/**
|
|
26
|
+
* Props for saturation slider thumb element.
|
|
27
|
+
*/
|
|
28
|
+
thumbProps?: HTMLUIProps<"div">;
|
|
29
|
+
};
|
|
30
|
+
type SaturationSliderProps = ThemeProps<"SaturationSlider"> & UseSaturationSliderProps & SaturationSliderOptions;
|
|
31
|
+
declare const SaturationSlider: _yamada_ui_core.Component<"input", SaturationSliderProps>;
|
|
32
|
+
|
|
33
|
+
export { SaturationSlider, type SaturationSliderProps };
|
|
@@ -0,0 +1,414 @@
|
|
|
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/saturation-slider.tsx
|
|
21
|
+
var saturation_slider_exports = {};
|
|
22
|
+
__export(saturation_slider_exports, {
|
|
23
|
+
SaturationSlider: () => SaturationSlider
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(saturation_slider_exports);
|
|
26
|
+
var import_core = require("@yamada-ui/core");
|
|
27
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
28
|
+
|
|
29
|
+
// src/use-saturation-slider.ts
|
|
30
|
+
var import_form_control = require("@yamada-ui/form-control");
|
|
31
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
|
32
|
+
var import_use_latest_ref = require("@yamada-ui/use-latest-ref");
|
|
33
|
+
var import_use_pan_event = require("@yamada-ui/use-pan-event");
|
|
34
|
+
var import_use_size = require("@yamada-ui/use-size");
|
|
35
|
+
var import_utils = require("@yamada-ui/utils");
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var defaultOverlays = (withShadow) => {
|
|
38
|
+
let overlays = [
|
|
39
|
+
([h]) => ({
|
|
40
|
+
bg: `hsl(${h}, 100%, 50%)`,
|
|
41
|
+
bgImage: "linear-gradient(0deg, #000, transparent), linear-gradient(90deg, #fff, transparent)"
|
|
42
|
+
})
|
|
43
|
+
];
|
|
44
|
+
if (withShadow)
|
|
45
|
+
overlays = [
|
|
46
|
+
...overlays,
|
|
47
|
+
{
|
|
48
|
+
boxShadow: `rgba(0, 0, 0, .1) 0 0 0 1px inset, rgb(0, 0, 0, .15) 0 0 4px inset`
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
return overlays;
|
|
52
|
+
};
|
|
53
|
+
var useSaturationSlider = ({
|
|
54
|
+
focusThumbOnChange = true,
|
|
55
|
+
...props
|
|
56
|
+
}) => {
|
|
57
|
+
if (!focusThumbOnChange)
|
|
58
|
+
props.isReadOnly = true;
|
|
59
|
+
let {
|
|
60
|
+
id,
|
|
61
|
+
name,
|
|
62
|
+
value: valueProp,
|
|
63
|
+
defaultValue = [0, 0, 1],
|
|
64
|
+
onChange: onChangeProp,
|
|
65
|
+
onChangeStart: onChangeStartProp,
|
|
66
|
+
onChangeEnd: onChangeEndProp,
|
|
67
|
+
step = 0.01,
|
|
68
|
+
thumbColor,
|
|
69
|
+
required,
|
|
70
|
+
disabled,
|
|
71
|
+
readOnly,
|
|
72
|
+
withShadow = true,
|
|
73
|
+
overlays: overlaysProp = defaultOverlays(withShadow),
|
|
74
|
+
...rest
|
|
75
|
+
} = (0, import_form_control.useFormControlProps)(props);
|
|
76
|
+
const onChangeStart = (0, import_utils.useCallbackRef)(onChangeStartProp);
|
|
77
|
+
const onChangeEnd = (0, import_utils.useCallbackRef)(onChangeEndProp);
|
|
78
|
+
const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
79
|
+
value: valueProp,
|
|
80
|
+
defaultValue,
|
|
81
|
+
onChange: onChangeProp
|
|
82
|
+
});
|
|
83
|
+
const [isDragging, setDragging] = (0, import_react.useState)(false);
|
|
84
|
+
const isInteractive = !(disabled || readOnly);
|
|
85
|
+
let [h, s, v] = value;
|
|
86
|
+
s = (0, import_utils.clampNumber)(s, 0, 1);
|
|
87
|
+
v = (0, import_utils.clampNumber)(v, 0, 1);
|
|
88
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
89
|
+
const trackRef = (0, import_react.useRef)(null);
|
|
90
|
+
const thumbRef = (0, import_react.useRef)(null);
|
|
91
|
+
const latestRef = (0, import_use_latest_ref.useLatestRef)({
|
|
92
|
+
value,
|
|
93
|
+
step,
|
|
94
|
+
isInteractive,
|
|
95
|
+
eventSource: null,
|
|
96
|
+
focusThumbOnChange
|
|
97
|
+
});
|
|
98
|
+
const thumbSize = (0, import_use_size.useSize)(thumbRef);
|
|
99
|
+
const overlays = (0, import_react.useMemo)(
|
|
100
|
+
() => overlaysProp.map((propsOrFunc) => (0, import_utils.runIfFunc)(propsOrFunc, [h, s, v])),
|
|
101
|
+
[overlaysProp, h, s, v]
|
|
102
|
+
);
|
|
103
|
+
const getValueFromPointer = (0, import_react.useCallback)(
|
|
104
|
+
(ev) => {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
if (!trackRef.current)
|
|
107
|
+
return [];
|
|
108
|
+
const { step: step2 } = latestRef.current;
|
|
109
|
+
latestRef.current.eventSource = "pointer";
|
|
110
|
+
const { bottom, left, height, width } = trackRef.current.getBoundingClientRect();
|
|
111
|
+
const { clientX, clientY } = (_b = (_a = ev.touches) == null ? void 0 : _a[0]) != null ? _b : ev;
|
|
112
|
+
let s2 = (0, import_utils.clampNumber)((clientX - left) / width, 0, 1);
|
|
113
|
+
let v2 = (0, import_utils.clampNumber)((bottom - clientY) / height, 0, 1);
|
|
114
|
+
if (step2) {
|
|
115
|
+
s2 = parseFloat((0, import_utils.roundNumberToStep)(s2, 0, step2));
|
|
116
|
+
v2 = parseFloat((0, import_utils.roundNumberToStep)(v2, 0, step2));
|
|
117
|
+
}
|
|
118
|
+
return [s2, v2];
|
|
119
|
+
},
|
|
120
|
+
[latestRef]
|
|
121
|
+
);
|
|
122
|
+
const setValueFromPointer = (ev) => {
|
|
123
|
+
const { value: value2 } = latestRef.current;
|
|
124
|
+
const [nextS, nextV] = getValueFromPointer(ev);
|
|
125
|
+
if (nextS == null || nextV == null)
|
|
126
|
+
return;
|
|
127
|
+
const [, s2, v2] = value2;
|
|
128
|
+
if (nextS !== s2 || nextV !== v2)
|
|
129
|
+
setValue(([h2]) => [h2, nextS, nextV]);
|
|
130
|
+
};
|
|
131
|
+
const focusThumb = (0, import_react.useCallback)(() => {
|
|
132
|
+
const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
|
|
133
|
+
if (focusThumbOnChange2)
|
|
134
|
+
setTimeout(() => {
|
|
135
|
+
var _a;
|
|
136
|
+
return (_a = thumbRef.current) == null ? void 0 : _a.focus();
|
|
137
|
+
});
|
|
138
|
+
}, [latestRef]);
|
|
139
|
+
const constrain = (0, import_react.useCallback)(
|
|
140
|
+
([s2, v2]) => {
|
|
141
|
+
const { isInteractive: isInteractive2 } = latestRef.current;
|
|
142
|
+
if (!isInteractive2)
|
|
143
|
+
return;
|
|
144
|
+
s2 = (0, import_utils.clampNumber)(s2, 0, 1);
|
|
145
|
+
v2 = (0, import_utils.clampNumber)(v2, 0, 1);
|
|
146
|
+
setValue(([h2]) => [h2, s2, v2]);
|
|
147
|
+
},
|
|
148
|
+
[latestRef, setValue]
|
|
149
|
+
);
|
|
150
|
+
const onKeyDown = (0, import_react.useCallback)(
|
|
151
|
+
(ev) => {
|
|
152
|
+
const actions = {
|
|
153
|
+
ArrowRight: () => constrain([s + step, v]),
|
|
154
|
+
ArrowUp: () => constrain([s, v + step]),
|
|
155
|
+
ArrowLeft: () => constrain([s - step, v]),
|
|
156
|
+
ArrowDown: () => constrain([s, v - step])
|
|
157
|
+
};
|
|
158
|
+
const action = actions[ev.key];
|
|
159
|
+
if (!action)
|
|
160
|
+
return;
|
|
161
|
+
ev.preventDefault();
|
|
162
|
+
ev.stopPropagation();
|
|
163
|
+
action(ev);
|
|
164
|
+
latestRef.current.eventSource = "keyboard";
|
|
165
|
+
},
|
|
166
|
+
[latestRef, constrain, s, v, step]
|
|
167
|
+
);
|
|
168
|
+
(0, import_use_pan_event.usePanEvent)(containerRef, {
|
|
169
|
+
onSessionStart: (ev) => {
|
|
170
|
+
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
|
171
|
+
if (!isInteractive2)
|
|
172
|
+
return;
|
|
173
|
+
setDragging(true);
|
|
174
|
+
focusThumb();
|
|
175
|
+
setValueFromPointer(ev);
|
|
176
|
+
onChangeStart(value2);
|
|
177
|
+
},
|
|
178
|
+
onSessionEnd: () => {
|
|
179
|
+
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
|
180
|
+
if (!isInteractive2)
|
|
181
|
+
return;
|
|
182
|
+
setDragging(false);
|
|
183
|
+
onChangeEnd(value2);
|
|
184
|
+
},
|
|
185
|
+
onMove: (ev) => {
|
|
186
|
+
const { isInteractive: isInteractive2 } = latestRef.current;
|
|
187
|
+
if (!isInteractive2)
|
|
188
|
+
return;
|
|
189
|
+
setValueFromPointer(ev);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
193
|
+
const { eventSource, value: value2 } = latestRef.current;
|
|
194
|
+
if (eventSource === "keyboard")
|
|
195
|
+
onChangeEnd(value2);
|
|
196
|
+
}, [value, onChangeEnd]);
|
|
197
|
+
const getContainerProps = (0, import_react.useCallback)(
|
|
198
|
+
(props2 = {}, ref = null) => ({
|
|
199
|
+
...props2,
|
|
200
|
+
...(0, import_utils.omitObject)(rest, ["aria-readonly"]),
|
|
201
|
+
ref: (0, import_utils.mergeRefs)(ref, containerRef),
|
|
202
|
+
tabIndex: -1
|
|
203
|
+
}),
|
|
204
|
+
[rest]
|
|
205
|
+
);
|
|
206
|
+
const getInnerProps = (0, import_react.useCallback)(
|
|
207
|
+
(props2 = {}, ref = null) => {
|
|
208
|
+
const { width: w } = thumbSize != null ? thumbSize : { width: 0 };
|
|
209
|
+
const style = {
|
|
210
|
+
...props2.style,
|
|
211
|
+
...rest.style,
|
|
212
|
+
padding: `${w / 2}px`
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
...props2,
|
|
216
|
+
ref,
|
|
217
|
+
style
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
[rest, thumbSize]
|
|
221
|
+
);
|
|
222
|
+
const getInputProps = (0, import_react.useCallback)(
|
|
223
|
+
(props2 = {}, ref = null) => ({
|
|
224
|
+
...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
|
|
225
|
+
...props2,
|
|
226
|
+
id,
|
|
227
|
+
ref,
|
|
228
|
+
type: "hidden",
|
|
229
|
+
name,
|
|
230
|
+
value: [h, s, v].toString(),
|
|
231
|
+
required,
|
|
232
|
+
disabled,
|
|
233
|
+
readOnly
|
|
234
|
+
}),
|
|
235
|
+
[disabled, id, name, readOnly, required, rest, h, s, v]
|
|
236
|
+
);
|
|
237
|
+
const getTrackProps = (0, import_react.useCallback)(
|
|
238
|
+
(props2 = {}, ref = null) => ({
|
|
239
|
+
...(0, import_utils.pickObject)(
|
|
240
|
+
rest,
|
|
241
|
+
(0, import_form_control.getFormControlProperties)({ omit: ["aria-readonly"] })
|
|
242
|
+
),
|
|
243
|
+
...props2,
|
|
244
|
+
ref: (0, import_utils.mergeRefs)(ref, trackRef)
|
|
245
|
+
}),
|
|
246
|
+
[rest]
|
|
247
|
+
);
|
|
248
|
+
const getThumbProps = (0, import_react.useCallback)(
|
|
249
|
+
(props2 = {}, ref = null) => {
|
|
250
|
+
const { width, height } = thumbSize != null ? thumbSize : { width: 0, height: 0 };
|
|
251
|
+
const x = s * 100;
|
|
252
|
+
const y = v * 100;
|
|
253
|
+
const style = {
|
|
254
|
+
...props2.style,
|
|
255
|
+
position: "absolute",
|
|
256
|
+
userSelect: "none",
|
|
257
|
+
touchAction: "none",
|
|
258
|
+
left: `calc(${x}% - ${width / 2}px)`,
|
|
259
|
+
bottom: `calc(${y}% - ${height / 2}px)`
|
|
260
|
+
};
|
|
261
|
+
return {
|
|
262
|
+
"aria-label": "Saturation and brightness thumb",
|
|
263
|
+
bg: thumbColor != null ? thumbColor : (0, import_utils.hsvTo)([h, s, v])(),
|
|
264
|
+
...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
|
|
265
|
+
...props2,
|
|
266
|
+
ref: (0, import_utils.mergeRefs)(ref, thumbRef),
|
|
267
|
+
tabIndex: isInteractive && focusThumbOnChange ? 0 : void 0,
|
|
268
|
+
role: "slider",
|
|
269
|
+
"aria-valuenow": s,
|
|
270
|
+
"aria-valuemin": 0,
|
|
271
|
+
"aria-valuemax": 100,
|
|
272
|
+
"aria-valuetext": `saturation ${s}, brightness ${v}`,
|
|
273
|
+
"data-active": (0, import_utils.dataAttr)(isDragging && focusThumbOnChange),
|
|
274
|
+
onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, onKeyDown),
|
|
275
|
+
onFocus: (0, import_utils.handlerAll)(props2.onFocus, rest.onFocus),
|
|
276
|
+
onBlur: (0, import_utils.handlerAll)(props2.onBlur, rest.onBlur),
|
|
277
|
+
style
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
[
|
|
281
|
+
h,
|
|
282
|
+
s,
|
|
283
|
+
v,
|
|
284
|
+
thumbColor,
|
|
285
|
+
focusThumbOnChange,
|
|
286
|
+
isDragging,
|
|
287
|
+
isInteractive,
|
|
288
|
+
onKeyDown,
|
|
289
|
+
rest,
|
|
290
|
+
thumbSize
|
|
291
|
+
]
|
|
292
|
+
);
|
|
293
|
+
return {
|
|
294
|
+
value,
|
|
295
|
+
overlays,
|
|
296
|
+
getContainerProps,
|
|
297
|
+
getInnerProps,
|
|
298
|
+
getTrackProps,
|
|
299
|
+
getInputProps,
|
|
300
|
+
getThumbProps
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// src/saturation-slider.tsx
|
|
305
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
306
|
+
var SaturationSlider = (0, import_core.forwardRef)(
|
|
307
|
+
(props, ref) => {
|
|
308
|
+
const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)(
|
|
309
|
+
"SaturationSlider",
|
|
310
|
+
props
|
|
311
|
+
);
|
|
312
|
+
const {
|
|
313
|
+
className,
|
|
314
|
+
ratio = 16 / 9,
|
|
315
|
+
innerProps,
|
|
316
|
+
inputProps,
|
|
317
|
+
trackProps,
|
|
318
|
+
thumbProps,
|
|
319
|
+
__css,
|
|
320
|
+
...computedProps
|
|
321
|
+
} = (0, import_core.omitThemeProps)(mergedProps);
|
|
322
|
+
const {
|
|
323
|
+
overlays,
|
|
324
|
+
getContainerProps,
|
|
325
|
+
getInnerProps,
|
|
326
|
+
getTrackProps,
|
|
327
|
+
getInputProps,
|
|
328
|
+
getThumbProps
|
|
329
|
+
} = useSaturationSlider(computedProps);
|
|
330
|
+
const css = {
|
|
331
|
+
position: "relative",
|
|
332
|
+
_before: {
|
|
333
|
+
content: `""`,
|
|
334
|
+
display: "block",
|
|
335
|
+
h: 0,
|
|
336
|
+
pb: (0, import_utils2.replaceObject)(ratio, (r) => `${1 / r * 100}%`)
|
|
337
|
+
},
|
|
338
|
+
"& > *": {
|
|
339
|
+
position: "absolute",
|
|
340
|
+
top: "0",
|
|
341
|
+
right: "0",
|
|
342
|
+
bottom: "0",
|
|
343
|
+
left: "0",
|
|
344
|
+
display: "flex",
|
|
345
|
+
justifyContent: "center",
|
|
346
|
+
alignItems: "center",
|
|
347
|
+
w: "100%",
|
|
348
|
+
h: "100%"
|
|
349
|
+
},
|
|
350
|
+
...styles.container,
|
|
351
|
+
...__css
|
|
352
|
+
};
|
|
353
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
354
|
+
import_core.ui.div,
|
|
355
|
+
{
|
|
356
|
+
className: (0, import_utils2.cx)("ui-saturation-slider", className),
|
|
357
|
+
__css: css,
|
|
358
|
+
...getContainerProps(),
|
|
359
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
360
|
+
import_core.ui.div,
|
|
361
|
+
{
|
|
362
|
+
className: (0, import_utils2.cx)("ui-saturation-slider__inner", className),
|
|
363
|
+
__css: { ...styles.inner },
|
|
364
|
+
...getInnerProps(innerProps),
|
|
365
|
+
children: [
|
|
366
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.input, { ...getInputProps(inputProps, ref) }),
|
|
367
|
+
overlays.map((props2, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
368
|
+
import_core.ui.div,
|
|
369
|
+
{
|
|
370
|
+
className: "ui-saturation-slider__overlay",
|
|
371
|
+
__css: {
|
|
372
|
+
position: "absolute",
|
|
373
|
+
top: 0,
|
|
374
|
+
left: 0,
|
|
375
|
+
right: 0,
|
|
376
|
+
bottom: 0,
|
|
377
|
+
...styles.overlay
|
|
378
|
+
},
|
|
379
|
+
...props2
|
|
380
|
+
},
|
|
381
|
+
index
|
|
382
|
+
)),
|
|
383
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
384
|
+
import_core.ui.div,
|
|
385
|
+
{
|
|
386
|
+
className: "ui-saturation-slider__track",
|
|
387
|
+
__css: {
|
|
388
|
+
position: "relative",
|
|
389
|
+
w: "full",
|
|
390
|
+
h: "full",
|
|
391
|
+
...styles.track
|
|
392
|
+
},
|
|
393
|
+
...getTrackProps(trackProps),
|
|
394
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
395
|
+
import_core.ui.div,
|
|
396
|
+
{
|
|
397
|
+
className: "ui-saturation-slider__thumb",
|
|
398
|
+
__css: { ...styles.thumb },
|
|
399
|
+
...getThumbProps(thumbProps)
|
|
400
|
+
}
|
|
401
|
+
)
|
|
402
|
+
}
|
|
403
|
+
)
|
|
404
|
+
]
|
|
405
|
+
}
|
|
406
|
+
)
|
|
407
|
+
}
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
);
|
|
411
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
412
|
+
0 && (module.exports = {
|
|
413
|
+
SaturationSlider
|
|
414
|
+
});
|
|
@@ -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.mjs';
|
|
5
|
+
import { UseColorPickerBaseProps } from './use-color-picker.mjs';
|
|
6
|
+
import './color-picker-body.mjs';
|
|
7
|
+
import './color-picker-eye-dropper.mjs';
|
|
8
|
+
import '@yamada-ui/button';
|
|
9
|
+
import '@yamada-ui/icon';
|
|
10
|
+
import './color-picker-sliders.mjs';
|
|
11
|
+
import './alpha-slider.mjs';
|
|
12
|
+
import './use-color-slider.mjs';
|
|
13
|
+
import '@yamada-ui/form-control';
|
|
14
|
+
import './hue-slider.mjs';
|
|
15
|
+
import './color-picker-swatches.mjs';
|
|
16
|
+
import './color-swatch.mjs';
|
|
17
|
+
import './saturation-slider.mjs';
|
|
18
|
+
import './use-saturation-slider.mjs';
|
|
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 };
|