@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,302 @@
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-saturation-slider.ts
21
+ var use_saturation_slider_exports = {};
22
+ __export(use_saturation_slider_exports, {
23
+ useSaturationSlider: () => useSaturationSlider
24
+ });
25
+ module.exports = __toCommonJS(use_saturation_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
+ var defaultOverlays = (withShadow) => {
34
+ let overlays = [
35
+ ([h]) => ({
36
+ bg: `hsl(${h}, 100%, 50%)`,
37
+ bgImage: "linear-gradient(0deg, #000, transparent), linear-gradient(90deg, #fff, transparent)"
38
+ })
39
+ ];
40
+ if (withShadow)
41
+ overlays = [
42
+ ...overlays,
43
+ {
44
+ boxShadow: `rgba(0, 0, 0, .1) 0 0 0 1px inset, rgb(0, 0, 0, .15) 0 0 4px inset`
45
+ }
46
+ ];
47
+ return overlays;
48
+ };
49
+ var useSaturationSlider = ({
50
+ focusThumbOnChange = true,
51
+ ...props
52
+ }) => {
53
+ if (!focusThumbOnChange)
54
+ props.isReadOnly = true;
55
+ let {
56
+ id,
57
+ name,
58
+ value: valueProp,
59
+ defaultValue = [0, 0, 1],
60
+ onChange: onChangeProp,
61
+ onChangeStart: onChangeStartProp,
62
+ onChangeEnd: onChangeEndProp,
63
+ step = 0.01,
64
+ thumbColor,
65
+ required,
66
+ disabled,
67
+ readOnly,
68
+ withShadow = true,
69
+ overlays: overlaysProp = defaultOverlays(withShadow),
70
+ ...rest
71
+ } = (0, import_form_control.useFormControlProps)(props);
72
+ const onChangeStart = (0, import_utils.useCallbackRef)(onChangeStartProp);
73
+ const onChangeEnd = (0, import_utils.useCallbackRef)(onChangeEndProp);
74
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
75
+ value: valueProp,
76
+ defaultValue,
77
+ onChange: onChangeProp
78
+ });
79
+ const [isDragging, setDragging] = (0, import_react.useState)(false);
80
+ const isInteractive = !(disabled || readOnly);
81
+ let [h, s, v] = value;
82
+ s = (0, import_utils.clampNumber)(s, 0, 1);
83
+ v = (0, import_utils.clampNumber)(v, 0, 1);
84
+ const containerRef = (0, import_react.useRef)(null);
85
+ const trackRef = (0, import_react.useRef)(null);
86
+ const thumbRef = (0, import_react.useRef)(null);
87
+ const latestRef = (0, import_use_latest_ref.useLatestRef)({
88
+ value,
89
+ step,
90
+ isInteractive,
91
+ eventSource: null,
92
+ focusThumbOnChange
93
+ });
94
+ const thumbSize = (0, import_use_size.useSize)(thumbRef);
95
+ const overlays = (0, import_react.useMemo)(
96
+ () => overlaysProp.map((propsOrFunc) => (0, import_utils.runIfFunc)(propsOrFunc, [h, s, v])),
97
+ [overlaysProp, h, s, v]
98
+ );
99
+ const getValueFromPointer = (0, import_react.useCallback)(
100
+ (ev) => {
101
+ var _a, _b;
102
+ if (!trackRef.current)
103
+ return [];
104
+ const { step: step2 } = latestRef.current;
105
+ latestRef.current.eventSource = "pointer";
106
+ const { bottom, left, height, width } = trackRef.current.getBoundingClientRect();
107
+ const { clientX, clientY } = (_b = (_a = ev.touches) == null ? void 0 : _a[0]) != null ? _b : ev;
108
+ let s2 = (0, import_utils.clampNumber)((clientX - left) / width, 0, 1);
109
+ let v2 = (0, import_utils.clampNumber)((bottom - clientY) / height, 0, 1);
110
+ if (step2) {
111
+ s2 = parseFloat((0, import_utils.roundNumberToStep)(s2, 0, step2));
112
+ v2 = parseFloat((0, import_utils.roundNumberToStep)(v2, 0, step2));
113
+ }
114
+ return [s2, v2];
115
+ },
116
+ [latestRef]
117
+ );
118
+ const setValueFromPointer = (ev) => {
119
+ const { value: value2 } = latestRef.current;
120
+ const [nextS, nextV] = getValueFromPointer(ev);
121
+ if (nextS == null || nextV == null)
122
+ return;
123
+ const [, s2, v2] = value2;
124
+ if (nextS !== s2 || nextV !== v2)
125
+ setValue(([h2]) => [h2, nextS, nextV]);
126
+ };
127
+ const focusThumb = (0, import_react.useCallback)(() => {
128
+ const { focusThumbOnChange: focusThumbOnChange2 } = latestRef.current;
129
+ if (focusThumbOnChange2)
130
+ setTimeout(() => {
131
+ var _a;
132
+ return (_a = thumbRef.current) == null ? void 0 : _a.focus();
133
+ });
134
+ }, [latestRef]);
135
+ const constrain = (0, import_react.useCallback)(
136
+ ([s2, v2]) => {
137
+ const { isInteractive: isInteractive2 } = latestRef.current;
138
+ if (!isInteractive2)
139
+ return;
140
+ s2 = (0, import_utils.clampNumber)(s2, 0, 1);
141
+ v2 = (0, import_utils.clampNumber)(v2, 0, 1);
142
+ setValue(([h2]) => [h2, s2, v2]);
143
+ },
144
+ [latestRef, setValue]
145
+ );
146
+ const onKeyDown = (0, import_react.useCallback)(
147
+ (ev) => {
148
+ const actions = {
149
+ ArrowRight: () => constrain([s + step, v]),
150
+ ArrowUp: () => constrain([s, v + step]),
151
+ ArrowLeft: () => constrain([s - step, v]),
152
+ ArrowDown: () => constrain([s, v - step])
153
+ };
154
+ const action = actions[ev.key];
155
+ if (!action)
156
+ return;
157
+ ev.preventDefault();
158
+ ev.stopPropagation();
159
+ action(ev);
160
+ latestRef.current.eventSource = "keyboard";
161
+ },
162
+ [latestRef, constrain, s, v, step]
163
+ );
164
+ (0, import_use_pan_event.usePanEvent)(containerRef, {
165
+ onSessionStart: (ev) => {
166
+ const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
167
+ if (!isInteractive2)
168
+ return;
169
+ setDragging(true);
170
+ focusThumb();
171
+ setValueFromPointer(ev);
172
+ onChangeStart(value2);
173
+ },
174
+ onSessionEnd: () => {
175
+ const { isInteractive: isInteractive2, value: value2 } = latestRef.current;
176
+ if (!isInteractive2)
177
+ return;
178
+ setDragging(false);
179
+ onChangeEnd(value2);
180
+ },
181
+ onMove: (ev) => {
182
+ const { isInteractive: isInteractive2 } = latestRef.current;
183
+ if (!isInteractive2)
184
+ return;
185
+ setValueFromPointer(ev);
186
+ }
187
+ });
188
+ (0, import_utils.useUpdateEffect)(() => {
189
+ const { eventSource, value: value2 } = latestRef.current;
190
+ if (eventSource === "keyboard")
191
+ onChangeEnd(value2);
192
+ }, [value, onChangeEnd]);
193
+ const getContainerProps = (0, import_react.useCallback)(
194
+ (props2 = {}, ref = null) => ({
195
+ ...props2,
196
+ ...(0, import_utils.omitObject)(rest, ["aria-readonly"]),
197
+ ref: (0, import_utils.mergeRefs)(ref, containerRef),
198
+ tabIndex: -1
199
+ }),
200
+ [rest]
201
+ );
202
+ const getInnerProps = (0, import_react.useCallback)(
203
+ (props2 = {}, ref = null) => {
204
+ const { width: w } = thumbSize != null ? thumbSize : { width: 0 };
205
+ const style = {
206
+ ...props2.style,
207
+ ...rest.style,
208
+ padding: `${w / 2}px`
209
+ };
210
+ return {
211
+ ...props2,
212
+ ref,
213
+ style
214
+ };
215
+ },
216
+ [rest, thumbSize]
217
+ );
218
+ const getInputProps = (0, import_react.useCallback)(
219
+ (props2 = {}, ref = null) => ({
220
+ ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
221
+ ...props2,
222
+ id,
223
+ ref,
224
+ type: "hidden",
225
+ name,
226
+ value: [h, s, v].toString(),
227
+ required,
228
+ disabled,
229
+ readOnly
230
+ }),
231
+ [disabled, id, name, readOnly, required, rest, h, s, v]
232
+ );
233
+ const getTrackProps = (0, import_react.useCallback)(
234
+ (props2 = {}, ref = null) => ({
235
+ ...(0, import_utils.pickObject)(
236
+ rest,
237
+ (0, import_form_control.getFormControlProperties)({ omit: ["aria-readonly"] })
238
+ ),
239
+ ...props2,
240
+ ref: (0, import_utils.mergeRefs)(ref, trackRef)
241
+ }),
242
+ [rest]
243
+ );
244
+ const getThumbProps = (0, import_react.useCallback)(
245
+ (props2 = {}, ref = null) => {
246
+ const { width, height } = thumbSize != null ? thumbSize : { width: 0, height: 0 };
247
+ const x = s * 100;
248
+ const y = v * 100;
249
+ const style = {
250
+ ...props2.style,
251
+ position: "absolute",
252
+ userSelect: "none",
253
+ touchAction: "none",
254
+ left: `calc(${x}% - ${width / 2}px)`,
255
+ bottom: `calc(${y}% - ${height / 2}px)`
256
+ };
257
+ return {
258
+ "aria-label": "Saturation and brightness thumb",
259
+ bg: thumbColor != null ? thumbColor : (0, import_utils.hsvTo)([h, s, v])(),
260
+ ...(0, import_utils.pickObject)(rest, import_form_control.formControlProperties),
261
+ ...props2,
262
+ ref: (0, import_utils.mergeRefs)(ref, thumbRef),
263
+ tabIndex: isInteractive && focusThumbOnChange ? 0 : void 0,
264
+ role: "slider",
265
+ "aria-valuenow": s,
266
+ "aria-valuemin": 0,
267
+ "aria-valuemax": 100,
268
+ "aria-valuetext": `saturation ${s}, brightness ${v}`,
269
+ "data-active": (0, import_utils.dataAttr)(isDragging && focusThumbOnChange),
270
+ onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, onKeyDown),
271
+ onFocus: (0, import_utils.handlerAll)(props2.onFocus, rest.onFocus),
272
+ onBlur: (0, import_utils.handlerAll)(props2.onBlur, rest.onBlur),
273
+ style
274
+ };
275
+ },
276
+ [
277
+ h,
278
+ s,
279
+ v,
280
+ thumbColor,
281
+ focusThumbOnChange,
282
+ isDragging,
283
+ isInteractive,
284
+ onKeyDown,
285
+ rest,
286
+ thumbSize
287
+ ]
288
+ );
289
+ return {
290
+ value,
291
+ overlays,
292
+ getContainerProps,
293
+ getInnerProps,
294
+ getTrackProps,
295
+ getInputProps,
296
+ getThumbProps
297
+ };
298
+ };
299
+ // Annotate the CommonJS export names for ESM import in node:
300
+ 0 && (module.exports = {
301
+ useSaturationSlider
302
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ useSaturationSlider
3
+ } from "./chunk-MAHWFXUG.mjs";
4
+ export {
5
+ useSaturationSlider
6
+ };
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@yamada-ui/color-picker",
3
+ "version": "1.0.0",
4
+ "description": "Yamada UI color picker component",
5
+ "keywords": [
6
+ "yamada",
7
+ "yamada ui",
8
+ "react",
9
+ "emotion",
10
+ "component",
11
+ "accordion",
12
+ "ui",
13
+ "uikit",
14
+ "styled",
15
+ "style-props",
16
+ "styled-component",
17
+ "css-in-js"
18
+ ],
19
+ "author": "Hirotomo Yamada <hirotomo.yamada@avap.co.jp>",
20
+ "license": "MIT",
21
+ "main": "dist/index.js",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "sideEffects": false,
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "homepage": "https://yamada-ui.com",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/hirotomoyamada/yamada-ui",
33
+ "directory": "packages/components/color-picker"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/hirotomoyamada/yamada-ui/issues"
37
+ },
38
+ "dependencies": {
39
+ "@yamada-ui/button": "1.0.5",
40
+ "@yamada-ui/core": "1.1.3",
41
+ "@yamada-ui/form-control": "1.0.6",
42
+ "@yamada-ui/icon": "1.0.4",
43
+ "@yamada-ui/input": "1.0.6",
44
+ "@yamada-ui/portal": "1.0.1",
45
+ "@yamada-ui/popover": "1.0.4",
46
+ "@yamada-ui/use-controllable-state": "1.0.1",
47
+ "@yamada-ui/use-eye-dropper": "^1.0.0",
48
+ "@yamada-ui/use-latest-ref": "^1.0.0",
49
+ "@yamada-ui/use-outside-click": "1.0.1",
50
+ "@yamada-ui/use-pan-event": "^1.0.1",
51
+ "@yamada-ui/use-size": "^1.0.1",
52
+ "@yamada-ui/utils": "1.0.1"
53
+ },
54
+ "devDependencies": {
55
+ "clean-package": "2.2.0",
56
+ "react": "^18.0.0"
57
+ },
58
+ "peerDependencies": {
59
+ "react": ">=18"
60
+ },
61
+ "clean-package": "../../../clean-package.config.json",
62
+ "tsup": {
63
+ "clean": true,
64
+ "target": "es2019",
65
+ "format": [
66
+ "cjs",
67
+ "esm"
68
+ ]
69
+ },
70
+ "module": "dist/index.mjs",
71
+ "types": "dist/index.d.ts",
72
+ "exports": {
73
+ ".": {
74
+ "types": "./dist/index.d.ts",
75
+ "import": "./dist/index.mjs",
76
+ "require": "./dist/index.js"
77
+ },
78
+ "./package.json": "./package.json"
79
+ },
80
+ "scripts": {
81
+ "dev": "pnpm build:fast -- --watch",
82
+ "build": "tsup src --dts",
83
+ "build:fast": "tsup src",
84
+ "clean": "rimraf dist .turbo",
85
+ "typecheck": "tsc --noEmit",
86
+ "gen:docs": "tsx ../../../scripts/generate-docs"
87
+ }
88
+ }