@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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Hirotomo Yamada
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# @yamada-ui/color-picker
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
$ pnpm add @yamada-ui/color-picker
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
$ yarn add @yamada-ui/color-picker
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
$ npm install @yamada-ui/color-picker
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Contribution
|
|
22
|
+
|
|
23
|
+
Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](./CONTRIBUTING.md) to assist you.
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
This package is licensed under the terms of the
|
|
28
|
+
[MIT license](https://github.com/hirotomoyamada/yamada-ui/blob/main/LICENSE).
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
+
import { UseColorSliderProps } from './use-color-slider.mjs';
|
|
4
|
+
import '@yamada-ui/form-control';
|
|
5
|
+
|
|
6
|
+
type AlphaSliderOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The color used for the slider.
|
|
9
|
+
*
|
|
10
|
+
* @default "#ffffff"
|
|
11
|
+
*/
|
|
12
|
+
color?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The minimum allowed value of the slider. Cannot be greater than max.
|
|
15
|
+
*
|
|
16
|
+
* @default 0
|
|
17
|
+
*/
|
|
18
|
+
min?: number;
|
|
19
|
+
/**
|
|
20
|
+
* The maximum allowed value of the slider. Cannot be less than min.
|
|
21
|
+
*
|
|
22
|
+
* @default 1
|
|
23
|
+
*/
|
|
24
|
+
max?: number;
|
|
25
|
+
/**
|
|
26
|
+
* The step in which increments or decrements have to be made.
|
|
27
|
+
*
|
|
28
|
+
* @default 0.01
|
|
29
|
+
*/
|
|
30
|
+
step?: number;
|
|
31
|
+
/**
|
|
32
|
+
* If `true`, the slider has an inner `box-shadow`.
|
|
33
|
+
*
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
withShadow?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Props for slider input element.
|
|
39
|
+
*/
|
|
40
|
+
inputProps?: HTMLUIProps<"input">;
|
|
41
|
+
/**
|
|
42
|
+
* Props for slider track element.
|
|
43
|
+
*/
|
|
44
|
+
trackProps?: HTMLUIProps<"div">;
|
|
45
|
+
/**
|
|
46
|
+
* Props for slider thumb element.
|
|
47
|
+
*/
|
|
48
|
+
thumbProps?: HTMLUIProps<"div">;
|
|
49
|
+
/**
|
|
50
|
+
* The overlay used for the slider.
|
|
51
|
+
*/
|
|
52
|
+
overlays?: HTMLUIProps<"div">[];
|
|
53
|
+
};
|
|
54
|
+
type AlphaSliderProps = ThemeProps<"AlphaSlider"> & Partial<Omit<UseColorSliderProps, "color">> & AlphaSliderOptions;
|
|
55
|
+
/**
|
|
56
|
+
* `AlphaSlider` is a component used to allow the user to select color transparency.
|
|
57
|
+
*
|
|
58
|
+
* @see Docs https://yamada-ui.com/components/forms/alpha-slider
|
|
59
|
+
*/
|
|
60
|
+
declare const AlphaSlider: _yamada_ui_core.Component<"input", AlphaSliderProps>;
|
|
61
|
+
|
|
62
|
+
export { AlphaSlider, type AlphaSliderProps };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
|
2
|
+
import { ThemeProps, HTMLUIProps } from '@yamada-ui/core';
|
|
3
|
+
import { UseColorSliderProps } from './use-color-slider.js';
|
|
4
|
+
import '@yamada-ui/form-control';
|
|
5
|
+
|
|
6
|
+
type AlphaSliderOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* The color used for the slider.
|
|
9
|
+
*
|
|
10
|
+
* @default "#ffffff"
|
|
11
|
+
*/
|
|
12
|
+
color?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The minimum allowed value of the slider. Cannot be greater than max.
|
|
15
|
+
*
|
|
16
|
+
* @default 0
|
|
17
|
+
*/
|
|
18
|
+
min?: number;
|
|
19
|
+
/**
|
|
20
|
+
* The maximum allowed value of the slider. Cannot be less than min.
|
|
21
|
+
*
|
|
22
|
+
* @default 1
|
|
23
|
+
*/
|
|
24
|
+
max?: number;
|
|
25
|
+
/**
|
|
26
|
+
* The step in which increments or decrements have to be made.
|
|
27
|
+
*
|
|
28
|
+
* @default 0.01
|
|
29
|
+
*/
|
|
30
|
+
step?: number;
|
|
31
|
+
/**
|
|
32
|
+
* If `true`, the slider has an inner `box-shadow`.
|
|
33
|
+
*
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
withShadow?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Props for slider input element.
|
|
39
|
+
*/
|
|
40
|
+
inputProps?: HTMLUIProps<"input">;
|
|
41
|
+
/**
|
|
42
|
+
* Props for slider track element.
|
|
43
|
+
*/
|
|
44
|
+
trackProps?: HTMLUIProps<"div">;
|
|
45
|
+
/**
|
|
46
|
+
* Props for slider thumb element.
|
|
47
|
+
*/
|
|
48
|
+
thumbProps?: HTMLUIProps<"div">;
|
|
49
|
+
/**
|
|
50
|
+
* The overlay used for the slider.
|
|
51
|
+
*/
|
|
52
|
+
overlays?: HTMLUIProps<"div">[];
|
|
53
|
+
};
|
|
54
|
+
type AlphaSliderProps = ThemeProps<"AlphaSlider"> & Partial<Omit<UseColorSliderProps, "color">> & AlphaSliderOptions;
|
|
55
|
+
/**
|
|
56
|
+
* `AlphaSlider` is a component used to allow the user to select color transparency.
|
|
57
|
+
*
|
|
58
|
+
* @see Docs https://yamada-ui.com/components/forms/alpha-slider
|
|
59
|
+
*/
|
|
60
|
+
declare const AlphaSlider: _yamada_ui_core.Component<"input", AlphaSliderProps>;
|
|
61
|
+
|
|
62
|
+
export { AlphaSlider, type AlphaSliderProps };
|
|
@@ -0,0 +1,438 @@
|
|
|
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/alpha-slider.tsx
|
|
21
|
+
var alpha_slider_exports = {};
|
|
22
|
+
__export(alpha_slider_exports, {
|
|
23
|
+
AlphaSlider: () => AlphaSlider
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(alpha_slider_exports);
|
|
26
|
+
var import_core = require("@yamada-ui/core");
|
|
27
|
+
var import_utils2 = require("@yamada-ui/utils");
|
|
28
|
+
|
|
29
|
+
// src/use-color-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
|
+
|
|
38
|
+
// ../../utils/src/object.ts
|
|
39
|
+
var pickObject = (obj, keys) => {
|
|
40
|
+
const result = {};
|
|
41
|
+
keys.forEach((key) => {
|
|
42
|
+
if (key in obj)
|
|
43
|
+
result[key] = obj[key];
|
|
44
|
+
});
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
var getObject = (obj, path, fallback, i) => {
|
|
48
|
+
const k = typeof path === "string" ? path.split(".") : [path];
|
|
49
|
+
for (i = 0; i < k.length; i += 1) {
|
|
50
|
+
if (!obj)
|
|
51
|
+
break;
|
|
52
|
+
obj = obj[k[i]];
|
|
53
|
+
}
|
|
54
|
+
return obj === void 0 ? fallback : obj;
|
|
55
|
+
};
|
|
56
|
+
var memoizeObject = (func) => {
|
|
57
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
58
|
+
const memoizedFunc = (obj, path, fallback, i) => {
|
|
59
|
+
if (typeof obj === "undefined")
|
|
60
|
+
return func(obj, path, fallback);
|
|
61
|
+
if (!cache.has(obj))
|
|
62
|
+
cache.set(obj, /* @__PURE__ */ new Map());
|
|
63
|
+
const map = cache.get(obj);
|
|
64
|
+
if (map.has(path))
|
|
65
|
+
return map.get(path);
|
|
66
|
+
const value = func(obj, path, fallback, i);
|
|
67
|
+
map.set(path, value);
|
|
68
|
+
return value;
|
|
69
|
+
};
|
|
70
|
+
return memoizedFunc;
|
|
71
|
+
};
|
|
72
|
+
var getMemoizedObject = memoizeObject(getObject);
|
|
73
|
+
|
|
74
|
+
// src/use-color-slider.ts
|
|
75
|
+
var useColorSlider = ({
|
|
76
|
+
focusThumbOnChange = true,
|
|
77
|
+
...props
|
|
78
|
+
}) => {
|
|
79
|
+
if (!focusThumbOnChange)
|
|
80
|
+
props.isReadOnly = true;
|
|
81
|
+
let {
|
|
82
|
+
id,
|
|
83
|
+
name,
|
|
84
|
+
value: valueProp,
|
|
85
|
+
defaultValue,
|
|
86
|
+
min = 0,
|
|
87
|
+
max,
|
|
88
|
+
step = 1,
|
|
89
|
+
onChange: onChangeProp,
|
|
90
|
+
onChangeStart: onChangeStartProp,
|
|
91
|
+
onChangeEnd: onChangeEndProp,
|
|
92
|
+
thumbColor,
|
|
93
|
+
required,
|
|
94
|
+
disabled,
|
|
95
|
+
readOnly,
|
|
96
|
+
...rest
|
|
97
|
+
} = (0, import_form_control.useFormControlProps)(props);
|
|
98
|
+
const onChangeStart = (0, import_utils.useCallbackRef)(onChangeStartProp);
|
|
99
|
+
const onChangeEnd = (0, import_utils.useCallbackRef)(onChangeEndProp);
|
|
100
|
+
const [computedValue, setValue] = (0, import_use_controllable_state.useControllableState)({
|
|
101
|
+
value: valueProp,
|
|
102
|
+
defaultValue: defaultValue != null ? defaultValue : min + (max - min) / 2,
|
|
103
|
+
onChange: onChangeProp
|
|
104
|
+
});
|
|
105
|
+
const value = (0, import_utils.clampNumber)(computedValue, min, max);
|
|
106
|
+
const thumbPercent = (0, import_utils.valueToPercent)(value, min, max);
|
|
107
|
+
const [isDragging, setDragging] = (0, import_react.useState)(false);
|
|
108
|
+
const isInteractive = !(disabled || readOnly);
|
|
109
|
+
const oneStep = step || (max - min) / 100;
|
|
110
|
+
const tenStep = (max - min) / 10;
|
|
111
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
112
|
+
const trackRef = (0, import_react.useRef)(null);
|
|
113
|
+
const thumbRef = (0, import_react.useRef)(null);
|
|
114
|
+
const latestRef = (0, import_use_latest_ref.useLatestRef)({
|
|
115
|
+
value,
|
|
116
|
+
min,
|
|
117
|
+
max,
|
|
118
|
+
step,
|
|
119
|
+
isInteractive,
|
|
120
|
+
eventSource: null,
|
|
121
|
+
focusThumbOnChange
|
|
122
|
+
});
|
|
123
|
+
const thumbSize = (0, import_use_size.useSize)(thumbRef);
|
|
124
|
+
const getValueFromPointer = (0, import_react.useCallback)(
|
|
125
|
+
(ev) => {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
if (!trackRef.current)
|
|
128
|
+
return;
|
|
129
|
+
const { min: min2, max: max2, step: step2 } = latestRef.current;
|
|
130
|
+
latestRef.current.eventSource = "pointer";
|
|
131
|
+
const { left, width } = trackRef.current.getBoundingClientRect();
|
|
132
|
+
const { clientX } = (_b = (_a = ev.touches) == null ? void 0 : _a[0]) != null ? _b : ev;
|
|
133
|
+
let percent = (clientX - left) / width;
|
|
134
|
+
let nextValue = (0, import_utils.percentToValue)(percent, min2, max2);
|
|
135
|
+
if (step2)
|
|
136
|
+
nextValue = parseFloat((0, import_utils.roundNumberToStep)(nextValue, min2, step2));
|
|
137
|
+
nextValue = (0, import_utils.clampNumber)(nextValue, min2, max2);
|
|
138
|
+
return nextValue;
|
|
139
|
+
},
|
|
140
|
+
[latestRef]
|
|
141
|
+
);
|
|
142
|
+
const setValueFromPointer = (ev) => {
|
|
143
|
+
const { value: value2 } = latestRef.current;
|
|
144
|
+
const nextValue = getValueFromPointer(ev);
|
|
145
|
+
if (nextValue != null && nextValue !== value2)
|
|
146
|
+
setValue(nextValue);
|
|
147
|
+
};
|
|
148
|
+
const focusThumb = (0, import_react.useCallback)(() => {
|
|
149
|
+
const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
|
|
150
|
+
if (focusThumbOnChange2)
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
var _a;
|
|
153
|
+
return (_a = thumbRef.current) == null ? void 0 : _a.focus();
|
|
154
|
+
});
|
|
155
|
+
}, [latestRef]);
|
|
156
|
+
const constrain = (0, import_react.useCallback)(
|
|
157
|
+
(value2) => {
|
|
158
|
+
const { isInteractive: isInteractive2, min: min2, max: max2 } = latestRef.current;
|
|
159
|
+
if (!isInteractive2)
|
|
160
|
+
return;
|
|
161
|
+
value2 = parseFloat((0, import_utils.roundNumberToStep)(value2, min2, oneStep));
|
|
162
|
+
value2 = (0, import_utils.clampNumber)(value2, min2, max2);
|
|
163
|
+
setValue(value2);
|
|
164
|
+
},
|
|
165
|
+
[setValue, latestRef, oneStep]
|
|
166
|
+
);
|
|
167
|
+
const stepUp = (0, import_react.useCallback)(
|
|
168
|
+
(step2 = oneStep) => constrain(value + step2),
|
|
169
|
+
[constrain, value, oneStep]
|
|
170
|
+
);
|
|
171
|
+
const stepDown = (0, import_react.useCallback)(
|
|
172
|
+
(step2 = oneStep) => constrain(value - step2),
|
|
173
|
+
[constrain, value, oneStep]
|
|
174
|
+
);
|
|
175
|
+
const onKeyDown = (0, import_react.useCallback)(
|
|
176
|
+
(ev) => {
|
|
177
|
+
const { min: min2, max: max2 } = latestRef.current;
|
|
178
|
+
const actions = {
|
|
179
|
+
ArrowRight: () => stepUp(),
|
|
180
|
+
ArrowUp: () => stepUp(),
|
|
181
|
+
ArrowLeft: () => stepDown(),
|
|
182
|
+
ArrowDown: () => stepDown(),
|
|
183
|
+
PageUp: () => stepUp(tenStep),
|
|
184
|
+
PageDown: () => stepDown(tenStep),
|
|
185
|
+
Home: () => constrain(min2),
|
|
186
|
+
End: () => constrain(max2)
|
|
187
|
+
};
|
|
188
|
+
const action = actions[ev.key];
|
|
189
|
+
if (!action)
|
|
190
|
+
return;
|
|
191
|
+
ev.preventDefault();
|
|
192
|
+
ev.stopPropagation();
|
|
193
|
+
action(ev);
|
|
194
|
+
latestRef.current.eventSource = "keyboard";
|
|
195
|
+
},
|
|
196
|
+
[constrain, latestRef, stepDown, stepUp, tenStep]
|
|
197
|
+
);
|
|
198
|
+
(0, import_use_pan_event.usePanEvent)(containerRef, {
|
|
199
|
+
onSessionStart: (ev) => {
|
|
200
|
+
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
|
201
|
+
if (!isInteractive2)
|
|
202
|
+
return;
|
|
203
|
+
setDragging(true);
|
|
204
|
+
focusThumb();
|
|
205
|
+
setValueFromPointer(ev);
|
|
206
|
+
onChangeStart(value2);
|
|
207
|
+
},
|
|
208
|
+
onSessionEnd: () => {
|
|
209
|
+
const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
|
|
210
|
+
if (!isInteractive2)
|
|
211
|
+
return;
|
|
212
|
+
setDragging(false);
|
|
213
|
+
onChangeEnd(value2);
|
|
214
|
+
},
|
|
215
|
+
onMove: (ev) => {
|
|
216
|
+
const { isInteractive: isInteractive2 } = latestRef.current;
|
|
217
|
+
if (!isInteractive2)
|
|
218
|
+
return;
|
|
219
|
+
setValueFromPointer(ev);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
(0, import_utils.useUpdateEffect)(() => {
|
|
223
|
+
const { eventSource, value: value2 } = latestRef.current;
|
|
224
|
+
if (eventSource === "keyboard")
|
|
225
|
+
onChangeEnd(value2);
|
|
226
|
+
}, [value, onChangeEnd]);
|
|
227
|
+
const getContainerProps = (0, import_react.useCallback)(
|
|
228
|
+
(props2 = {}, ref = null) => {
|
|
229
|
+
const { width: w } = thumbSize != null ? thumbSize : { width: 0 };
|
|
230
|
+
const style = {
|
|
231
|
+
...props2.style,
|
|
232
|
+
...rest.style,
|
|
233
|
+
paddingInline: `${w / 2}px`
|
|
234
|
+
};
|
|
235
|
+
return {
|
|
236
|
+
...props2,
|
|
237
|
+
...(0, import_utils.omitObject)(rest, ["aria-readonly"]),
|
|
238
|
+
ref: (0, import_utils.mergeRefs)(ref, containerRef),
|
|
239
|
+
tabIndex: -1,
|
|
240
|
+
style
|
|
241
|
+
};
|
|
242
|
+
},
|
|
243
|
+
[rest, thumbSize]
|
|
244
|
+
);
|
|
245
|
+
const getInputProps = (0, import_react.useCallback)(
|
|
246
|
+
(props2 = {}, ref = null) => ({
|
|
247
|
+
...pickObject(rest, import_form_control.formControlProperties),
|
|
248
|
+
...props2,
|
|
249
|
+
id,
|
|
250
|
+
ref,
|
|
251
|
+
type: "hidden",
|
|
252
|
+
name,
|
|
253
|
+
value,
|
|
254
|
+
required,
|
|
255
|
+
disabled,
|
|
256
|
+
readOnly
|
|
257
|
+
}),
|
|
258
|
+
[disabled, id, name, readOnly, required, rest, value]
|
|
259
|
+
);
|
|
260
|
+
const getTrackProps = (0, import_react.useCallback)(
|
|
261
|
+
(props2 = {}, ref = null) => ({
|
|
262
|
+
...pickObject(
|
|
263
|
+
rest,
|
|
264
|
+
(0, import_form_control.getFormControlProperties)({ omit: ["aria-readonly"] })
|
|
265
|
+
),
|
|
266
|
+
...props2,
|
|
267
|
+
ref: (0, import_utils.mergeRefs)(ref, trackRef)
|
|
268
|
+
}),
|
|
269
|
+
[rest]
|
|
270
|
+
);
|
|
271
|
+
const getThumbProps = (0, import_react.useCallback)(
|
|
272
|
+
(props2 = {}, ref = null) => {
|
|
273
|
+
const n = thumbPercent;
|
|
274
|
+
const { width: w } = thumbSize != null ? thumbSize : { width: 0 };
|
|
275
|
+
const style = {
|
|
276
|
+
...props2.style,
|
|
277
|
+
position: "absolute",
|
|
278
|
+
userSelect: "none",
|
|
279
|
+
touchAction: "none",
|
|
280
|
+
left: `calc(${n}% - ${w / 2}px)`
|
|
281
|
+
};
|
|
282
|
+
return {
|
|
283
|
+
"aria-label": "Slider thumb",
|
|
284
|
+
bg: thumbColor != null ? thumbColor : `hsl(${value}, 100%, 50%)`,
|
|
285
|
+
...pickObject(rest, import_form_control.formControlProperties),
|
|
286
|
+
...props2,
|
|
287
|
+
ref: (0, import_utils.mergeRefs)(ref, thumbRef),
|
|
288
|
+
tabIndex: isInteractive && focusThumbOnChange ? 0 : void 0,
|
|
289
|
+
role: "slider",
|
|
290
|
+
"aria-valuenow": value,
|
|
291
|
+
"aria-valuemin": min,
|
|
292
|
+
"aria-valuemax": max,
|
|
293
|
+
"data-active": (0, import_utils.dataAttr)(isDragging && focusThumbOnChange),
|
|
294
|
+
onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, onKeyDown),
|
|
295
|
+
onFocus: (0, import_utils.handlerAll)(props2.onFocus, rest.onFocus),
|
|
296
|
+
onBlur: (0, import_utils.handlerAll)(props2.onBlur, rest.onBlur),
|
|
297
|
+
style
|
|
298
|
+
};
|
|
299
|
+
},
|
|
300
|
+
[
|
|
301
|
+
thumbColor,
|
|
302
|
+
focusThumbOnChange,
|
|
303
|
+
isDragging,
|
|
304
|
+
isInteractive,
|
|
305
|
+
min,
|
|
306
|
+
max,
|
|
307
|
+
onKeyDown,
|
|
308
|
+
rest,
|
|
309
|
+
thumbPercent,
|
|
310
|
+
thumbSize,
|
|
311
|
+
value
|
|
312
|
+
]
|
|
313
|
+
);
|
|
314
|
+
return {
|
|
315
|
+
value,
|
|
316
|
+
getContainerProps,
|
|
317
|
+
getTrackProps,
|
|
318
|
+
getInputProps,
|
|
319
|
+
getThumbProps
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// src/alpha-slider.tsx
|
|
324
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
325
|
+
var defaultOverlays = (color, min, max, withShadow) => {
|
|
326
|
+
let overlays = [
|
|
327
|
+
{
|
|
328
|
+
bgImage: "linear-gradient(45deg, var(--ui-checkers) 25%, transparent 25%), linear-gradient(-45deg, var(--ui-checkers) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--ui-checkers) 75%), linear-gradient(-45deg, var(--ui-body) 75%, var(--ui-checkers) 75%)",
|
|
329
|
+
bgSize: `8px 8px`,
|
|
330
|
+
bgPosition: `0 0, 0 4px, 4px -4px, -4px 0`,
|
|
331
|
+
var: [
|
|
332
|
+
{
|
|
333
|
+
name: "checkers",
|
|
334
|
+
token: "colors",
|
|
335
|
+
value: ["blackAlpha.300", "whiteAlpha.300"]
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
name: "body",
|
|
339
|
+
token: "colors",
|
|
340
|
+
value: ["whiteAlpha.500", "blackAlpha.500"]
|
|
341
|
+
}
|
|
342
|
+
]
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
bgGradient: `linear(to-r, ${(0, import_utils2.convertColor)(color)("hex") + (0, import_utils2.alphaToHex)(min)}, ${(0, import_utils2.convertColor)(color)("hex") + (0, import_utils2.alphaToHex)(max)})`
|
|
346
|
+
}
|
|
347
|
+
];
|
|
348
|
+
if (withShadow)
|
|
349
|
+
overlays = [
|
|
350
|
+
...overlays,
|
|
351
|
+
{
|
|
352
|
+
boxShadow: `rgba(0, 0, 0, .1) 0 0 0 1px inset, rgb(0, 0, 0, .15) 0 0 4px inset`
|
|
353
|
+
}
|
|
354
|
+
];
|
|
355
|
+
return overlays;
|
|
356
|
+
};
|
|
357
|
+
var AlphaSlider = (0, import_core.forwardRef)(
|
|
358
|
+
(props, ref) => {
|
|
359
|
+
const [styles, mergedProps] = (0, import_core.useMultiComponentStyle)("AlphaSlider", props);
|
|
360
|
+
const {
|
|
361
|
+
className,
|
|
362
|
+
inputProps,
|
|
363
|
+
trackProps,
|
|
364
|
+
thumbProps,
|
|
365
|
+
color = "#ffffff",
|
|
366
|
+
min = 0,
|
|
367
|
+
max = 1,
|
|
368
|
+
withShadow = true,
|
|
369
|
+
overlays = defaultOverlays(color, min, max, withShadow),
|
|
370
|
+
__css,
|
|
371
|
+
...computedProps
|
|
372
|
+
} = (0, import_core.omitThemeProps)(mergedProps);
|
|
373
|
+
const { getContainerProps, getTrackProps, getInputProps, getThumbProps } = useColorSlider({
|
|
374
|
+
min,
|
|
375
|
+
max,
|
|
376
|
+
step: 0.01,
|
|
377
|
+
thumbColor: "transparent",
|
|
378
|
+
...computedProps
|
|
379
|
+
});
|
|
380
|
+
const css = {
|
|
381
|
+
position: "relative",
|
|
382
|
+
...styles.container,
|
|
383
|
+
...__css
|
|
384
|
+
};
|
|
385
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
386
|
+
import_core.ui.div,
|
|
387
|
+
{
|
|
388
|
+
className: (0, import_utils2.cx)("ui-alpha-slider", className),
|
|
389
|
+
__css: css,
|
|
390
|
+
...getContainerProps(),
|
|
391
|
+
children: [
|
|
392
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.input, { ...getInputProps(inputProps, ref) }),
|
|
393
|
+
overlays.map((props2, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
394
|
+
import_core.ui.div,
|
|
395
|
+
{
|
|
396
|
+
className: "ui-alpha-slider__overlay",
|
|
397
|
+
__css: {
|
|
398
|
+
position: "absolute",
|
|
399
|
+
top: 0,
|
|
400
|
+
left: 0,
|
|
401
|
+
right: 0,
|
|
402
|
+
bottom: 0,
|
|
403
|
+
...styles.overlay
|
|
404
|
+
},
|
|
405
|
+
...props2
|
|
406
|
+
},
|
|
407
|
+
index
|
|
408
|
+
)),
|
|
409
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
410
|
+
import_core.ui.div,
|
|
411
|
+
{
|
|
412
|
+
className: "ui-alpha-slider__track",
|
|
413
|
+
__css: {
|
|
414
|
+
position: "relative",
|
|
415
|
+
w: "full",
|
|
416
|
+
h: "full",
|
|
417
|
+
...styles.track
|
|
418
|
+
},
|
|
419
|
+
...getTrackProps(trackProps),
|
|
420
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
421
|
+
import_core.ui.div,
|
|
422
|
+
{
|
|
423
|
+
className: "ui-alpha-slider__thumb",
|
|
424
|
+
__css: { ...styles.thumb },
|
|
425
|
+
...getThumbProps(thumbProps)
|
|
426
|
+
}
|
|
427
|
+
)
|
|
428
|
+
}
|
|
429
|
+
)
|
|
430
|
+
]
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
);
|
|
435
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
436
|
+
0 && (module.exports = {
|
|
437
|
+
AlphaSlider
|
|
438
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useColorPickerContext
|
|
3
|
+
} from "./chunk-NR2XCTSD.mjs";
|
|
4
|
+
|
|
5
|
+
// src/color-picker-eye-dropper.tsx
|
|
6
|
+
import { IconButton } from "@yamada-ui/button";
|
|
7
|
+
import { forwardRef } from "@yamada-ui/core";
|
|
8
|
+
import { Icon } from "@yamada-ui/icon";
|
|
9
|
+
import { cx } from "@yamada-ui/utils";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
var ColorPickerEyeDropper = forwardRef(({ className, ...rest }, ref) => {
|
|
12
|
+
const { getEyeDropperProps, readOnly, size, styles } = useColorPickerContext();
|
|
13
|
+
const css = {
|
|
14
|
+
h: "auto",
|
|
15
|
+
minW: "auto",
|
|
16
|
+
pointerEvents: readOnly ? "none" : void 0,
|
|
17
|
+
...styles.eyeDropper
|
|
18
|
+
};
|
|
19
|
+
return /* @__PURE__ */ jsx(
|
|
20
|
+
IconButton,
|
|
21
|
+
{
|
|
22
|
+
className: cx("ui-color-picker__eye-dropper", className),
|
|
23
|
+
variant: "outline",
|
|
24
|
+
size,
|
|
25
|
+
__css: css,
|
|
26
|
+
...getEyeDropperProps(rest, ref),
|
|
27
|
+
children: /* @__PURE__ */ jsx(EyeDropperIcon, { className: "ui-color-picker__eye-dropper__icon" })
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
var EyeDropperIcon = ({ ...rest }) => {
|
|
32
|
+
return /* @__PURE__ */ jsxs(
|
|
33
|
+
Icon,
|
|
34
|
+
{
|
|
35
|
+
viewBox: "0 0 24 24",
|
|
36
|
+
fill: "none",
|
|
37
|
+
stroke: "currentColor",
|
|
38
|
+
strokeWidth: "2",
|
|
39
|
+
strokeLinecap: "round",
|
|
40
|
+
strokeLinejoin: "round",
|
|
41
|
+
...rest,
|
|
42
|
+
children: [
|
|
43
|
+
/* @__PURE__ */ jsx("path", { d: "m2 22 1-1h3l9-9" }),
|
|
44
|
+
/* @__PURE__ */ jsx("path", { d: "M3 21v-3l9-9" }),
|
|
45
|
+
/* @__PURE__ */ jsx("path", { d: "m15 6 3.4-3.4a2.1 2.1 0 1 1 3 3L18 9l.4.4a2.1 2.1 0 1 1-3 3l-3.8-3.8a2.1 2.1 0 1 1 3-3l.4.4Z" })
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
ColorPickerEyeDropper,
|
|
53
|
+
EyeDropperIcon
|
|
54
|
+
};
|