@sanity/color-input 2.30.2-shopify.0 → 3.0.0-studio-v3.1
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/README.md +61 -6
- package/lib/cjs/index.js +606 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/esm/index.js +594 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/types/index.d.ts +84 -0
- package/lib/types/index.d.ts.map +1 -0
- package/package.json +65 -20
- package/sanity.json +2 -26
- package/src/ColorInput.tsx +110 -0
- package/src/ColorPicker.tsx +139 -0
- package/src/ColorPickerFields.tsx +144 -0
- package/src/index.ts +16 -0
- package/src/schemas/color.tsx +79 -0
- package/src/schemas/hslaColor.ts +11 -0
- package/src/schemas/hsvaColor.ts +11 -0
- package/src/schemas/rgbaColor.ts +11 -0
- package/v2-incompatible.js +11 -0
- package/lib/ColorInput.js +0 -144
- package/lib/ColorPicker.js +0 -159
- package/lib/ColorPickerFields.js +0 -138
- package/lib/schemas/color.js +0 -81
- package/lib/schemas/hslaColor.js +0 -29
- package/lib/schemas/hsvaColor.js +0 -29
- package/lib/schemas/rgbaColor.js +0 -29
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
import {createPlugin as $gGrEF$createPlugin} from "sanity";
|
|
2
|
+
import {jsx as $gGrEF$jsx, Fragment as $gGrEF$Fragment, jsxs as $gGrEF$jsxs} from "react/jsx-runtime";
|
|
3
|
+
import {useRef as $gGrEF$useRef, useState as $gGrEF$useState, useEffect as $gGrEF$useEffect, useCallback as $gGrEF$useCallback, useMemo as $gGrEF$useMemo} from "react";
|
|
4
|
+
import {set as $gGrEF$set, setIfMissing as $gGrEF$setIfMissing, unset as $gGrEF$unset} from "sanity/form";
|
|
5
|
+
import {debounce as $gGrEF$debounce} from "lodash";
|
|
6
|
+
import {Button as $gGrEF$Button, Box as $gGrEF$Box, Flex as $gGrEF$Flex, Card as $gGrEF$Card, Stack as $gGrEF$Stack, Text as $gGrEF$Text, Inline as $gGrEF$Inline, useTheme as $gGrEF$useTheme} from "@sanity/ui";
|
|
7
|
+
import {AddIcon as $gGrEF$AddIcon, TrashIcon as $gGrEF$TrashIcon} from "@sanity/icons";
|
|
8
|
+
import {Saturation as $gGrEF$Saturation, Hue as $gGrEF$Hue, Alpha as $gGrEF$Alpha, Checkboard as $gGrEF$Checkboard, EditableInput as $gGrEF$EditableInput} from "react-color/lib/components/common";
|
|
9
|
+
import {CustomPicker as $gGrEF$CustomPicker} from "react-color";
|
|
10
|
+
import $gGrEF$styledcomponents from "styled-components";
|
|
11
|
+
import {isValidHex as $gGrEF$isValidHex} from "react-color/lib/helpers/color";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const $88b170db27d5e6f3$export$4e4b8c12b77623c0 = {
|
|
15
|
+
title: "Hue Saturation Lightness",
|
|
16
|
+
name: "hslaColor",
|
|
17
|
+
type: "object",
|
|
18
|
+
fields: [
|
|
19
|
+
{
|
|
20
|
+
name: "h",
|
|
21
|
+
type: "number",
|
|
22
|
+
title: "Hue"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "s",
|
|
26
|
+
type: "number",
|
|
27
|
+
title: "Saturation"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "l",
|
|
31
|
+
type: "number",
|
|
32
|
+
title: "Lightness"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "a",
|
|
36
|
+
type: "number",
|
|
37
|
+
title: "Alpha"
|
|
38
|
+
},
|
|
39
|
+
]
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const $37ec22070cd01c8b$export$cc215b4b2c268dfd = {
|
|
44
|
+
title: "Red Green Blue (rgb)",
|
|
45
|
+
name: "rgbaColor",
|
|
46
|
+
type: "object",
|
|
47
|
+
fields: [
|
|
48
|
+
{
|
|
49
|
+
name: "r",
|
|
50
|
+
type: "number",
|
|
51
|
+
title: "Red"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "g",
|
|
55
|
+
type: "number",
|
|
56
|
+
title: "Green"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: "b",
|
|
60
|
+
type: "number",
|
|
61
|
+
title: "Blue"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "a",
|
|
65
|
+
type: "number",
|
|
66
|
+
title: "Alpha"
|
|
67
|
+
},
|
|
68
|
+
]
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
const $69987db005d80051$export$5367735792921e7d = ({ onChange: onChange , rgb: rgb , hsl: hsl , hex: hex , disableAlpha: disableAlpha })=>{
|
|
93
|
+
const { sanity: sanity } = (0, $gGrEF$useTheme)();
|
|
94
|
+
const inputStyles = (0, $gGrEF$useMemo)(()=>({
|
|
95
|
+
input: {
|
|
96
|
+
width: "80%",
|
|
97
|
+
padding: "4px 10% 3px",
|
|
98
|
+
border: "none",
|
|
99
|
+
boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,
|
|
100
|
+
color: sanity.color.input.default.enabled.fg,
|
|
101
|
+
backgroundColor: sanity.color.input.default.enabled.bg,
|
|
102
|
+
fontSize: sanity.fonts.text.sizes[0].fontSize,
|
|
103
|
+
textAlign: "center"
|
|
104
|
+
},
|
|
105
|
+
label: {
|
|
106
|
+
display: "block",
|
|
107
|
+
textAlign: "center",
|
|
108
|
+
fontSize: sanity.fonts.label.sizes[0].fontSize,
|
|
109
|
+
color: sanity.color.base.fg,
|
|
110
|
+
paddingTop: "3px",
|
|
111
|
+
paddingBottom: "4px",
|
|
112
|
+
textTransform: "capitalize"
|
|
113
|
+
}
|
|
114
|
+
}), [
|
|
115
|
+
sanity
|
|
116
|
+
]);
|
|
117
|
+
const handleChange = (0, $gGrEF$useCallback)((data)=>{
|
|
118
|
+
if ("hex" in data && data.hex && (0, $gGrEF$isValidHex)(data.hex)) onChange({
|
|
119
|
+
hex: data.hex,
|
|
120
|
+
source: "hex"
|
|
121
|
+
});
|
|
122
|
+
else if (rgb && ("r" in data && data.r || "g" in data && data.g || "b" in data && data.b)) onChange({
|
|
123
|
+
r: Number(data.r) || rgb.r,
|
|
124
|
+
g: Number(data.g) || rgb.g,
|
|
125
|
+
b: Number(data.b) || rgb.b,
|
|
126
|
+
a: rgb.a,
|
|
127
|
+
source: "rgb"
|
|
128
|
+
});
|
|
129
|
+
else if (hsl && "a" in data && data.a) {
|
|
130
|
+
let alpha = Number(data.a);
|
|
131
|
+
if (alpha < 0) alpha = 0;
|
|
132
|
+
else if (alpha > 100) alpha = 100;
|
|
133
|
+
alpha /= 100;
|
|
134
|
+
onChange({
|
|
135
|
+
h: hsl.h,
|
|
136
|
+
s: hsl.s,
|
|
137
|
+
l: hsl.l,
|
|
138
|
+
a: alpha,
|
|
139
|
+
source: "hsl"
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}, [
|
|
143
|
+
onChange,
|
|
144
|
+
hsl,
|
|
145
|
+
rgb
|
|
146
|
+
]);
|
|
147
|
+
return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Flex), {
|
|
148
|
+
children: [
|
|
149
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
150
|
+
flex: 2,
|
|
151
|
+
marginRight: 1,
|
|
152
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$EditableInput), {
|
|
153
|
+
style: inputStyles,
|
|
154
|
+
label: "hex",
|
|
155
|
+
value: hex?.replace("#", ""),
|
|
156
|
+
onChange: handleChange
|
|
157
|
+
})
|
|
158
|
+
}),
|
|
159
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
160
|
+
flex: 1,
|
|
161
|
+
marginRight: 1,
|
|
162
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$EditableInput), {
|
|
163
|
+
style: inputStyles,
|
|
164
|
+
label: "r",
|
|
165
|
+
value: rgb?.r,
|
|
166
|
+
onChange: handleChange,
|
|
167
|
+
dragLabel: true,
|
|
168
|
+
dragMax: 255
|
|
169
|
+
})
|
|
170
|
+
}),
|
|
171
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
172
|
+
flex: 1,
|
|
173
|
+
marginRight: 1,
|
|
174
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$EditableInput), {
|
|
175
|
+
style: inputStyles,
|
|
176
|
+
label: "g",
|
|
177
|
+
value: rgb?.g,
|
|
178
|
+
onChange: handleChange,
|
|
179
|
+
dragLabel: true,
|
|
180
|
+
dragMax: 255
|
|
181
|
+
})
|
|
182
|
+
}),
|
|
183
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
184
|
+
flex: 1,
|
|
185
|
+
marginRight: 1,
|
|
186
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$EditableInput), {
|
|
187
|
+
style: inputStyles,
|
|
188
|
+
label: "b",
|
|
189
|
+
value: rgb?.b,
|
|
190
|
+
onChange: handleChange,
|
|
191
|
+
dragLabel: true,
|
|
192
|
+
dragMax: 255
|
|
193
|
+
})
|
|
194
|
+
}),
|
|
195
|
+
!disableAlpha && /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
196
|
+
flex: 1,
|
|
197
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$EditableInput), {
|
|
198
|
+
style: inputStyles,
|
|
199
|
+
label: "a",
|
|
200
|
+
value: Math.round((rgb?.a ?? 1) * 100),
|
|
201
|
+
onChange: handleChange,
|
|
202
|
+
dragLabel: true,
|
|
203
|
+
dragMax: 100
|
|
204
|
+
})
|
|
205
|
+
})
|
|
206
|
+
]
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
const $167ca0588b34aece$var$ColorBox = (0, $gGrEF$styledcomponents)((0, $gGrEF$Box))`
|
|
212
|
+
position: absolute;
|
|
213
|
+
top: 0;
|
|
214
|
+
left: 0;
|
|
215
|
+
width: 100%;
|
|
216
|
+
height: 100%;
|
|
217
|
+
`;
|
|
218
|
+
const $167ca0588b34aece$var$ReadOnlyContainer = (0, $gGrEF$styledcomponents)((0, $gGrEF$Flex))`
|
|
219
|
+
margin-top: 6rem;
|
|
220
|
+
background-color: var(--card-bg-color);
|
|
221
|
+
position: relative;
|
|
222
|
+
width: 100%;
|
|
223
|
+
`;
|
|
224
|
+
const $167ca0588b34aece$var$ColorPickerInner = (props)=>{
|
|
225
|
+
const { width: width , color: { rgb: rgb , hex: hex , hsv: hsv , hsl: hsl } , onChange: onChange , onUnset: onUnset , disableAlpha: disableAlpha , readOnly: readOnly , } = props;
|
|
226
|
+
return /*#__PURE__*/ (0, $gGrEF$jsx)("div", {
|
|
227
|
+
style: {
|
|
228
|
+
width: width
|
|
229
|
+
},
|
|
230
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
|
|
231
|
+
padding: 1,
|
|
232
|
+
border: true,
|
|
233
|
+
radius: 1,
|
|
234
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
235
|
+
space: 2,
|
|
236
|
+
children: [
|
|
237
|
+
!readOnly && /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Fragment), {
|
|
238
|
+
children: [
|
|
239
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
|
|
240
|
+
overflow: "hidden",
|
|
241
|
+
style: {
|
|
242
|
+
position: "relative",
|
|
243
|
+
height: "5em"
|
|
244
|
+
},
|
|
245
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Saturation), {
|
|
246
|
+
onChange: onChange,
|
|
247
|
+
hsl: hsl,
|
|
248
|
+
hsv: hsv
|
|
249
|
+
})
|
|
250
|
+
}),
|
|
251
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
|
|
252
|
+
shadow: 1,
|
|
253
|
+
radius: 3,
|
|
254
|
+
overflow: "hidden",
|
|
255
|
+
style: {
|
|
256
|
+
position: "relative",
|
|
257
|
+
height: "10px"
|
|
258
|
+
},
|
|
259
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Hue), {
|
|
260
|
+
hsl: hsl,
|
|
261
|
+
onChange: !readOnly && onChange
|
|
262
|
+
})
|
|
263
|
+
}),
|
|
264
|
+
!disableAlpha && /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Card), {
|
|
265
|
+
shadow: 1,
|
|
266
|
+
radius: 3,
|
|
267
|
+
overflow: "hidden",
|
|
268
|
+
style: {
|
|
269
|
+
position: "relative",
|
|
270
|
+
height: "10px"
|
|
271
|
+
},
|
|
272
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Alpha), {
|
|
273
|
+
rgb: rgb,
|
|
274
|
+
hsl: hsl,
|
|
275
|
+
onChange: onChange
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
]
|
|
279
|
+
}),
|
|
280
|
+
/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Flex), {
|
|
281
|
+
children: [
|
|
282
|
+
/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Card), {
|
|
283
|
+
flex: 1,
|
|
284
|
+
radius: 2,
|
|
285
|
+
overflow: "hidden",
|
|
286
|
+
style: {
|
|
287
|
+
position: "relative",
|
|
288
|
+
minWidth: "4em"
|
|
289
|
+
},
|
|
290
|
+
children: [
|
|
291
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Checkboard), {}),
|
|
292
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)($167ca0588b34aece$var$ColorBox, {
|
|
293
|
+
style: {
|
|
294
|
+
backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`
|
|
295
|
+
}
|
|
296
|
+
}),
|
|
297
|
+
readOnly && /*#__PURE__*/ (0, $gGrEF$jsx)($167ca0588b34aece$var$ReadOnlyContainer, {
|
|
298
|
+
padding: 2,
|
|
299
|
+
paddingBottom: 1,
|
|
300
|
+
sizing: "border",
|
|
301
|
+
justify: "space-between",
|
|
302
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
|
|
303
|
+
space: 3,
|
|
304
|
+
marginTop: 1,
|
|
305
|
+
children: [
|
|
306
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Text), {
|
|
307
|
+
size: 3,
|
|
308
|
+
weight: "bold",
|
|
309
|
+
children: hex
|
|
310
|
+
}),
|
|
311
|
+
/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Inline), {
|
|
312
|
+
space: 3,
|
|
313
|
+
children: [
|
|
314
|
+
/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Text), {
|
|
315
|
+
size: 1,
|
|
316
|
+
children: [
|
|
317
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)("strong", {
|
|
318
|
+
children: "RGB: "
|
|
319
|
+
}),
|
|
320
|
+
rgb?.r,
|
|
321
|
+
" ",
|
|
322
|
+
rgb?.g,
|
|
323
|
+
" ",
|
|
324
|
+
rgb?.b
|
|
325
|
+
]
|
|
326
|
+
}),
|
|
327
|
+
/*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Text), {
|
|
328
|
+
size: 1,
|
|
329
|
+
children: [
|
|
330
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)("strong", {
|
|
331
|
+
children: "HSL: "
|
|
332
|
+
}),
|
|
333
|
+
" ",
|
|
334
|
+
Math.round(hsl?.h ?? 0),
|
|
335
|
+
" ",
|
|
336
|
+
Math.round(hsl?.s ?? 0),
|
|
337
|
+
"%",
|
|
338
|
+
" ",
|
|
339
|
+
Math.round(hsl?.l ?? 0)
|
|
340
|
+
]
|
|
341
|
+
})
|
|
342
|
+
]
|
|
343
|
+
})
|
|
344
|
+
]
|
|
345
|
+
})
|
|
346
|
+
})
|
|
347
|
+
]
|
|
348
|
+
}),
|
|
349
|
+
!readOnly && /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Flex), {
|
|
350
|
+
align: "flex-start",
|
|
351
|
+
marginLeft: 2,
|
|
352
|
+
children: [
|
|
353
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
354
|
+
style: {
|
|
355
|
+
width: 200
|
|
356
|
+
},
|
|
357
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $69987db005d80051$export$5367735792921e7d), {
|
|
358
|
+
rgb: rgb,
|
|
359
|
+
hsl: hsl,
|
|
360
|
+
hex: hex,
|
|
361
|
+
onChange: onChange,
|
|
362
|
+
disableAlpha: disableAlpha
|
|
363
|
+
})
|
|
364
|
+
}),
|
|
365
|
+
/*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
|
|
366
|
+
marginLeft: 2,
|
|
367
|
+
children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
|
|
368
|
+
onClick: onUnset,
|
|
369
|
+
title: "Delete color",
|
|
370
|
+
icon: (0, $gGrEF$TrashIcon),
|
|
371
|
+
tone: "critical"
|
|
372
|
+
})
|
|
373
|
+
})
|
|
374
|
+
]
|
|
375
|
+
})
|
|
376
|
+
]
|
|
377
|
+
})
|
|
378
|
+
]
|
|
379
|
+
})
|
|
380
|
+
})
|
|
381
|
+
});
|
|
382
|
+
};
|
|
383
|
+
const $167ca0588b34aece$export$9feb1bc2e5f1ccb3 = (0, $gGrEF$CustomPicker)($167ca0588b34aece$var$ColorPickerInner);
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
const $9a1b799aa4bfa9c5$var$DEFAULT_COLOR = {
|
|
387
|
+
hex: "#24a3e3",
|
|
388
|
+
hsl: {
|
|
389
|
+
h: 200,
|
|
390
|
+
s: 0.7732,
|
|
391
|
+
l: 0.5156,
|
|
392
|
+
a: 1
|
|
393
|
+
},
|
|
394
|
+
hsv: {
|
|
395
|
+
h: 200,
|
|
396
|
+
s: 0.8414,
|
|
397
|
+
v: 0.8901,
|
|
398
|
+
a: 1
|
|
399
|
+
},
|
|
400
|
+
rgb: {
|
|
401
|
+
r: 46,
|
|
402
|
+
g: 163,
|
|
403
|
+
b: 227,
|
|
404
|
+
a: 1
|
|
405
|
+
},
|
|
406
|
+
source: "hex"
|
|
407
|
+
};
|
|
408
|
+
function $9a1b799aa4bfa9c5$export$5a1d7ca0a925d9c2(props) {
|
|
409
|
+
const { onChange: onChange , schemaType: type , readOnly: readOnly , value: value } = props;
|
|
410
|
+
const focusRef = (0, $gGrEF$useRef)(null);
|
|
411
|
+
// use local state so we can have instant ui updates while debouncing patch emits
|
|
412
|
+
const [color, setColor] = (0, $gGrEF$useState)(value);
|
|
413
|
+
(0, $gGrEF$useEffect)(()=>setColor(value), [
|
|
414
|
+
value
|
|
415
|
+
]);
|
|
416
|
+
const emitSetColor = (0, $gGrEF$useCallback)((nextColor)=>{
|
|
417
|
+
const fieldPatches = type.fields.filter((field)=>field.name in nextColor).map((field)=>{
|
|
418
|
+
const nextFieldValue = nextColor[field.name];
|
|
419
|
+
const isObject = field.type.jsonType === "object";
|
|
420
|
+
return (0, $gGrEF$set)(isObject ? Object.assign({
|
|
421
|
+
_type: field.type.name
|
|
422
|
+
}, nextFieldValue) : nextFieldValue, [
|
|
423
|
+
field.name
|
|
424
|
+
]);
|
|
425
|
+
});
|
|
426
|
+
onChange([
|
|
427
|
+
(0, $gGrEF$setIfMissing)({
|
|
428
|
+
_type: type.name
|
|
429
|
+
}),
|
|
430
|
+
(0, $gGrEF$set)(type.name, [
|
|
431
|
+
"_type"
|
|
432
|
+
]),
|
|
433
|
+
(0, $gGrEF$set)(nextColor.rgb?.a, [
|
|
434
|
+
"alpha"
|
|
435
|
+
]),
|
|
436
|
+
...fieldPatches,
|
|
437
|
+
]);
|
|
438
|
+
}, [
|
|
439
|
+
onChange,
|
|
440
|
+
type
|
|
441
|
+
]);
|
|
442
|
+
// The color picker emits onChange events continuously while the user is sliding the
|
|
443
|
+
// hue/saturation/alpha selectors. This debounces the event to avoid excessive patches
|
|
444
|
+
const debouncedColorChange = (0, $gGrEF$useMemo)(()=>(0, $gGrEF$debounce)(emitSetColor, 100), [
|
|
445
|
+
emitSetColor
|
|
446
|
+
]);
|
|
447
|
+
const handleColorChange = (0, $gGrEF$useCallback)((nextColor)=>{
|
|
448
|
+
setColor(nextColor);
|
|
449
|
+
debouncedColorChange(nextColor);
|
|
450
|
+
}, [
|
|
451
|
+
debouncedColorChange,
|
|
452
|
+
setColor
|
|
453
|
+
]);
|
|
454
|
+
const handleCreateColor = (0, $gGrEF$useCallback)(()=>{
|
|
455
|
+
setColor($9a1b799aa4bfa9c5$var$DEFAULT_COLOR);
|
|
456
|
+
emitSetColor($9a1b799aa4bfa9c5$var$DEFAULT_COLOR);
|
|
457
|
+
}, [
|
|
458
|
+
emitSetColor
|
|
459
|
+
]);
|
|
460
|
+
const handleUnset = (0, $gGrEF$useCallback)(()=>{
|
|
461
|
+
setColor(undefined);
|
|
462
|
+
onChange((0, $gGrEF$unset)());
|
|
463
|
+
}, [
|
|
464
|
+
onChange
|
|
465
|
+
]);
|
|
466
|
+
return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Fragment), {
|
|
467
|
+
children: value ? /*#__PURE__*/ (0, $gGrEF$jsx)((0, $167ca0588b34aece$export$9feb1bc2e5f1ccb3), {
|
|
468
|
+
/* ref={this.focusRef}*/ color: color,
|
|
469
|
+
onChange: handleColorChange,
|
|
470
|
+
readOnly: readOnly || typeof type.readOnly === "boolean" && type.readOnly,
|
|
471
|
+
disableAlpha: type.options?.disableAlpha,
|
|
472
|
+
onUnset: handleUnset
|
|
473
|
+
}) : /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
|
|
474
|
+
icon: (0, $gGrEF$AddIcon),
|
|
475
|
+
mode: "ghost",
|
|
476
|
+
text: "Create color",
|
|
477
|
+
ref: focusRef,
|
|
478
|
+
disabled: Boolean(readOnly),
|
|
479
|
+
onClick: handleCreateColor
|
|
480
|
+
})
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
const $771ddc1e2be43f68$var$round = (val = 1)=>Math.round(val * 100);
|
|
486
|
+
const $771ddc1e2be43f68$export$35e9368ef982300f = {
|
|
487
|
+
name: "color",
|
|
488
|
+
type: "object",
|
|
489
|
+
title: "Color",
|
|
490
|
+
components: {
|
|
491
|
+
input: (0, $9a1b799aa4bfa9c5$export$5a1d7ca0a925d9c2)
|
|
492
|
+
},
|
|
493
|
+
fields: [
|
|
494
|
+
{
|
|
495
|
+
title: "Hex",
|
|
496
|
+
name: "hex",
|
|
497
|
+
type: "string"
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
title: "Alpha",
|
|
501
|
+
name: "alpha",
|
|
502
|
+
type: "number"
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
title: "Hue Saturation Lightness",
|
|
506
|
+
name: "hsl",
|
|
507
|
+
type: "hslaColor"
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
title: "Hue Saturation Value",
|
|
511
|
+
name: "hsv",
|
|
512
|
+
type: "hsvaColor"
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
title: "Red Green Blue (rgb)",
|
|
516
|
+
name: "rgb",
|
|
517
|
+
type: "rgbaColor"
|
|
518
|
+
},
|
|
519
|
+
],
|
|
520
|
+
preview: {
|
|
521
|
+
select: {
|
|
522
|
+
title: "hex",
|
|
523
|
+
alpha: "alpha",
|
|
524
|
+
hex: "hex",
|
|
525
|
+
hsl: "hsl"
|
|
526
|
+
},
|
|
527
|
+
prepare ({ title: title , hex: hex , hsl: hsl , alpha: alpha }) {
|
|
528
|
+
let subtitle = hex || "No color set";
|
|
529
|
+
if (hsl) subtitle = `H:${$771ddc1e2be43f68$var$round(hsl.h)} S:${$771ddc1e2be43f68$var$round(hsl.s)} L:${$771ddc1e2be43f68$var$round(hsl.l)} A:${$771ddc1e2be43f68$var$round(alpha)}`;
|
|
530
|
+
return {
|
|
531
|
+
title: title,
|
|
532
|
+
subtitle: subtitle,
|
|
533
|
+
media: ()=>/*#__PURE__*/ (0, $gGrEF$jsx)("div", {
|
|
534
|
+
style: {
|
|
535
|
+
backgroundColor: hex ?? "#000",
|
|
536
|
+
opacity: alpha ?? 1,
|
|
537
|
+
position: "absolute",
|
|
538
|
+
height: "100%",
|
|
539
|
+
width: "100%",
|
|
540
|
+
top: "0",
|
|
541
|
+
left: "0"
|
|
542
|
+
}
|
|
543
|
+
})
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
const $b26c91ff9252c28d$export$633851ea6f85c81b = {
|
|
551
|
+
title: "Hue Saturation Value",
|
|
552
|
+
name: "hsvaColor",
|
|
553
|
+
type: "object",
|
|
554
|
+
fields: [
|
|
555
|
+
{
|
|
556
|
+
name: "h",
|
|
557
|
+
type: "number",
|
|
558
|
+
title: "Hue"
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
name: "s",
|
|
562
|
+
type: "number",
|
|
563
|
+
title: "Saturation"
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
name: "v",
|
|
567
|
+
type: "number",
|
|
568
|
+
title: "Value"
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
name: "a",
|
|
572
|
+
type: "number",
|
|
573
|
+
title: "Alpha"
|
|
574
|
+
},
|
|
575
|
+
]
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
const $df9eabe9bda49ea8$export$1d1c20ca26e20eb8 = (0, $gGrEF$createPlugin)({
|
|
581
|
+
name: "@sanity/color-input",
|
|
582
|
+
schema: {
|
|
583
|
+
types: [
|
|
584
|
+
(0, $88b170db27d5e6f3$export$4e4b8c12b77623c0),
|
|
585
|
+
(0, $b26c91ff9252c28d$export$633851ea6f85c81b),
|
|
586
|
+
(0, $37ec22070cd01c8b$export$cc215b4b2c268dfd),
|
|
587
|
+
(0, $771ddc1e2be43f68$export$35e9368ef982300f)
|
|
588
|
+
]
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
export {$df9eabe9bda49ea8$export$1d1c20ca26e20eb8 as colorInput, $88b170db27d5e6f3$export$4e4b8c12b77623c0 as hslaColor, $37ec22070cd01c8b$export$cc215b4b2c268dfd as rgbaColor, $771ddc1e2be43f68$export$35e9368ef982300f as color, $b26c91ff9252c28d$export$633851ea6f85c81b as hsvaColor, $9a1b799aa4bfa9c5$export$5a1d7ca0a925d9c2 as ColorInput};
|
|
594
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;ACAO,MAAM,yCAAS,GAAG;IACvB,KAAK,EAAE,0BAA0B;IACjC,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE;QACN;YAAC,IAAI,EAAE,GAAG;YAAE,IAAI,EAAE,QAAQ;YAAE,KAAK,EAAE,KAAK;SAAC;QACzC;YAAC,IAAI,EAAE,GAAG;YAAE,IAAI,EAAE,QAAQ;YAAE,KAAK,EAAE,YAAY;SAAC;QAChD;YAAC,I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;IACd,MAAM,EAAE;QACN;YAAC,IAAI,EAAE,GAAG;YAAE,IAAI,EAAE,QAAQ;YAAE,KAAK,EAAE,KAAK;SAAC;QACzC;YAAC,IAAI,EAAE,GAAG;YAAE,IAAI,EAAE,QAAQ;YAAE,KAAK,EAAE,YAAY;SAAC;QAChD;YAAC,IAAI,EAAE,GAAG;YAAE,IAAI,EAAE,QAAQ;YAAE,KAAK,EAAE,OAAO;SAAC;QAC3C;YAAC,IAAI,EAAE,GAAG;YAAE,IAAI,EAAE,QAAQ;YAAE,KAAK,EAAE,OAAO;SAAC;KAC5C;CACF;;;;APJM,MAAM,yCAAU,GAAG,CAAA,GAAA,mBAAY,CAAA,CAAC;IACrC,IAAI,EAAE,qBAAqB;IAC3B,MAAM,EAAE;QACN,KAAK,EAAE;YAAC,CAAA,GAAA,yCAAS,CAAA;YAAE,CAAA,GAAA,yCAAS,CAAA;YAAE,CAAA,GAAA,yCAAS,CAAA;YAAE,CAAA,GAAA,yCAAK,CAAA;SAAC;KAChD;CACF,CAAC","sources":["src/index.ts","src/schemas/hslaColor.ts","src/schemas/rgbaColor.ts","src/schemas/color.tsx","src/ColorInput.tsx","src/ColorPicker.tsx","src/ColorPickerFields.tsx","src/schemas/hsvaColor.ts"],"sourcesContent":["import {createPlugin} from 'sanity'\nimport {hslaColor} from './schemas/hslaColor'\nimport {rgbaColor} from './schemas/rgbaColor'\nimport {color} from './schemas/color'\nimport {hsvaColor} from './schemas/hsvaColor'\n\nexport const colorInput = createPlugin({\n name: '@sanity/color-input',\n schema: {\n types: [hslaColor, hsvaColor, rgbaColor, color],\n },\n})\n\nexport {hslaColor, rgbaColor, color, hsvaColor}\nexport {ColorInput} from './ColorInput'\nexport type {ColorValue, ColorInputProps, ColorOptions, ColorSchemaType} from './ColorInput'\n","export const hslaColor = {\n title: 'Hue Saturation Lightness',\n name: 'hslaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'l', type: 'number', title: 'Lightness'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n}\n","export const rgbaColor = {\n title: 'Red Green Blue (rgb)',\n name: 'rgbaColor',\n type: 'object',\n fields: [\n {name: 'r', type: 'number', title: 'Red'},\n {name: 'g', type: 'number', title: 'Green'},\n {name: 'b', type: 'number', title: 'Blue'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n}\n","import React from 'react'\nimport {ColorInput} from '../ColorInput'\n\nconst round = (val: number = 1) => Math.round(val * 100)\n\nexport const color = {\n name: 'color',\n type: 'object',\n title: 'Color',\n components: {input: ColorInput},\n fields: [\n {\n title: 'Hex',\n name: 'hex',\n type: 'string',\n },\n {\n title: 'Alpha',\n name: 'alpha',\n type: 'number',\n },\n {\n title: 'Hue Saturation Lightness',\n name: 'hsl',\n type: 'hslaColor',\n },\n {\n title: 'Hue Saturation Value',\n name: 'hsv',\n type: 'hsvaColor',\n },\n {\n title: 'Red Green Blue (rgb)',\n name: 'rgb',\n type: 'rgbaColor',\n },\n ],\n preview: {\n select: {\n title: 'hex',\n alpha: 'alpha',\n hex: 'hex',\n hsl: 'hsl',\n },\n prepare({\n title,\n hex,\n hsl,\n alpha,\n }: {\n title?: string\n alpha?: number\n hex?: string\n hsl?: {h: number; s: number; l: number}\n }) {\n let subtitle = hex || 'No color set'\n if (hsl) {\n subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`\n }\n return {\n title: title,\n subtitle: subtitle,\n media: () => (\n <div\n style={{\n backgroundColor: hex ?? '#000',\n opacity: alpha ?? 1,\n position: 'absolute',\n height: '100%',\n width: '100%',\n top: '0',\n left: '0',\n }}\n />\n ),\n }\n },\n },\n}\n","import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'\nimport {set, setIfMissing, unset} from 'sanity/form'\nimport {debounce} from 'lodash'\nimport {Button} from '@sanity/ui'\nimport {AddIcon} from '@sanity/icons'\nimport {ColorPicker} from './ColorPicker'\nimport {ObjectInputProps} from 'sanity'\nimport {HSLColor, HSVColor, RGBColor} from 'react-color'\nimport {ObjectSchemaType} from 'sanity'\n\nconst DEFAULT_COLOR: ColorValue & {source: string} = {\n hex: '#24a3e3',\n hsl: {h: 200, s: 0.7732, l: 0.5156, a: 1},\n hsv: {h: 200, s: 0.8414, v: 0.8901, a: 1},\n rgb: {r: 46, g: 163, b: 227, a: 1},\n source: 'hex',\n}\n\nexport interface ColorValue {\n hex: string\n hsl: HSLColor\n hsv: HSVColor\n rgb: RGBColor\n}\n\nexport interface ColorOptions {\n disableAlpha?: boolean\n}\n\nexport type ColorSchemaType = ObjectSchemaType & {\n options?: ColorOptions\n}\nexport type ColorInputProps = ObjectInputProps<ColorValue, ColorSchemaType>\n\nexport function ColorInput(props: ColorInputProps) {\n const {onChange, schemaType: type, readOnly, value} = props\n const focusRef = useRef<HTMLButtonElement>(null)\n\n // use local state so we can have instant ui updates while debouncing patch emits\n const [color, setColor] = useState(value)\n useEffect(() => setColor(value), [value])\n\n const emitSetColor = useCallback(\n (nextColor: ColorValue) => {\n const fieldPatches = type.fields\n .filter((field) => field.name in nextColor)\n .map((field) => {\n const nextFieldValue = nextColor[field.name as keyof ColorValue]\n const isObject = field.type.jsonType === 'object'\n return set(\n isObject ? Object.assign({_type: field.type.name}, nextFieldValue) : nextFieldValue,\n [field.name]\n )\n })\n\n onChange([\n setIfMissing({_type: type.name}),\n set(type.name, ['_type']),\n set(nextColor.rgb?.a, ['alpha']),\n ...fieldPatches,\n ])\n },\n [onChange, type]\n )\n\n // The color picker emits onChange events continuously while the user is sliding the\n // hue/saturation/alpha selectors. This debounces the event to avoid excessive patches\n const debouncedColorChange = useMemo(() => debounce(emitSetColor, 100), [emitSetColor])\n const handleColorChange = useCallback(\n (nextColor: ColorValue) => {\n setColor(nextColor)\n debouncedColorChange(nextColor)\n },\n [debouncedColorChange, setColor]\n )\n\n const handleCreateColor = useCallback(() => {\n setColor(DEFAULT_COLOR)\n emitSetColor(DEFAULT_COLOR)\n }, [emitSetColor])\n\n const handleUnset = useCallback(() => {\n setColor(undefined)\n onChange(unset())\n }, [onChange])\n\n return (\n <>\n {value ? (\n <ColorPicker\n /* ref={this.focusRef}*/\n color={color}\n onChange={handleColorChange}\n readOnly={readOnly || (typeof type.readOnly === 'boolean' && type.readOnly)}\n disableAlpha={type.options?.disableAlpha}\n onUnset={handleUnset}\n />\n ) : (\n <Button\n icon={AddIcon}\n mode=\"ghost\"\n text=\"Create color\"\n ref={focusRef}\n disabled={Boolean(readOnly)}\n onClick={handleCreateColor}\n />\n )}\n </>\n )\n}\n","import React from 'react'\nimport {Alpha, Checkboard, Hue, Saturation} from 'react-color/lib/components/common'\nimport {CustomPicker, HEXColor, HSLColor, HSVColor, RGBColor} from 'react-color'\nimport {Box, Button, Card, Flex, Inline, Stack, Text} from '@sanity/ui'\nimport {TrashIcon} from '@sanity/icons'\nimport styled from 'styled-components'\nimport {ColorPickerFields} from './ColorPickerFields'\nimport {CustomPickerInjectedProps} from 'react-color/lib/components/common/ColorWrap'\nimport {ColorValue} from './ColorInput'\n\nconst ColorBox = styled(Box)`\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n`\n\nconst ReadOnlyContainer = styled(Flex)`\n margin-top: 6rem;\n background-color: var(--card-bg-color);\n position: relative;\n width: 100%;\n`\n\nexport interface ColorPickerProps\n extends CustomPickerInjectedProps<HSLColor | HSVColor | RGBColor | HEXColor> {\n width?: string\n disableAlpha: boolean\n readOnly?: boolean\n onUnset: () => void\n color: ColorValue\n}\n\nconst ColorPickerInner = (props: ColorPickerProps) => {\n const {\n width,\n color: {rgb, hex, hsv, hsl},\n onChange,\n onUnset,\n disableAlpha,\n readOnly,\n } = props\n return (\n <div style={{width}}>\n <Card padding={1} border radius={1}>\n <Stack space={2}>\n {!readOnly && (\n <>\n <Card overflow=\"hidden\" style={{position: 'relative', height: '5em'}}>\n <Saturation onChange={onChange} hsl={hsl} hsv={hsv} />\n </Card>\n\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px'}}\n >\n <Hue hsl={hsl} onChange={!readOnly && onChange} />\n </Card>\n\n {!disableAlpha && (\n <Card\n shadow={1}\n radius={3}\n overflow=\"hidden\"\n style={{position: 'relative', height: '10px'}}\n >\n <Alpha rgb={rgb} hsl={hsl} onChange={onChange} />\n </Card>\n )}\n </>\n )}\n <Flex>\n <Card\n flex={1}\n radius={2}\n overflow=\"hidden\"\n style={{position: 'relative', minWidth: '4em'}}\n >\n <Checkboard />\n <ColorBox\n style={{\n backgroundColor: `rgba(${rgb?.r},${rgb?.g},${rgb?.b},${rgb?.a})`,\n }}\n />\n\n {readOnly && (\n <ReadOnlyContainer\n padding={2}\n paddingBottom={1}\n sizing=\"border\"\n justify=\"space-between\"\n >\n <Stack space={3} marginTop={1}>\n <Text size={3} weight=\"bold\">\n {hex}\n </Text>\n\n <Inline space={3}>\n <Text size={1}>\n <strong>RGB: </strong>\n {rgb?.r} {rgb?.g} {rgb?.b}\n </Text>\n <Text size={1}>\n <strong>HSL: </strong> {Math.round(hsl?.h ?? 0)} {Math.round(hsl?.s ?? 0)}%{' '}\n {Math.round(hsl?.l ?? 0)}\n </Text>\n </Inline>\n </Stack>\n </ReadOnlyContainer>\n )}\n </Card>\n\n {!readOnly && (\n <Flex align=\"flex-start\" marginLeft={2}>\n <Box style={{width: 200}}>\n <ColorPickerFields\n rgb={rgb}\n hsl={hsl}\n hex={hex}\n onChange={onChange}\n disableAlpha={disableAlpha}\n />\n </Box>\n <Box marginLeft={2}>\n <Button onClick={onUnset} title=\"Delete color\" icon={TrashIcon} tone=\"critical\" />\n </Box>\n </Flex>\n )}\n </Flex>\n </Stack>\n </Card>\n </div>\n )\n}\n\nexport const ColorPicker = CustomPicker(ColorPickerInner)\n","import React, {useCallback, useMemo} from 'react'\n// @ts-expect-error missing export\nimport {isValidHex} from 'react-color/lib/helpers/color'\nimport {EditableInput} from 'react-color/lib/components/common'\nimport {Box, Flex, useTheme} from '@sanity/ui'\nimport {ColorChangeHandler, HEXColor, HSLColor, HSVColor, RGBColor} from 'react-color'\nimport {EditableInputStyles} from 'react-color/lib/components/common/EditableInput'\n\ninterface ColorPickerFieldsProps {\n rgb?: RGBColor\n hsl?: HSLColor\n hex?: string\n disableAlpha: boolean\n onChange: ColorChangeHandler<HSLColor | HSVColor | RGBColor | HEXColor>\n}\n\nexport const ColorPickerFields = ({\n onChange,\n rgb,\n hsl,\n hex,\n disableAlpha,\n}: ColorPickerFieldsProps) => {\n const {sanity} = useTheme()\n\n const inputStyles: EditableInputStyles = useMemo(\n () => ({\n input: {\n width: '80%',\n padding: '4px 10% 3px',\n border: 'none',\n boxShadow: `inset 0 0 0 1px ${sanity.color.input.default.enabled.border}`,\n color: sanity.color.input.default.enabled.fg,\n backgroundColor: sanity.color.input.default.enabled.bg,\n fontSize: sanity.fonts.text.sizes[0].fontSize,\n textAlign: 'center',\n },\n label: {\n display: 'block',\n textAlign: 'center',\n fontSize: sanity.fonts.label.sizes[0].fontSize,\n color: sanity.color.base.fg,\n paddingTop: '3px',\n paddingBottom: '4px',\n textTransform: 'capitalize',\n },\n }),\n [sanity]\n )\n\n const handleChange: ColorChangeHandler<Record<string, string>> = useCallback(\n (data) => {\n if ('hex' in data && data.hex && isValidHex(data.hex)) {\n onChange({\n hex: data.hex,\n source: 'hex',\n })\n } else if (\n rgb &&\n (('r' in data && data.r) || ('g' in data && data.g) || ('b' in data && data.b))\n ) {\n onChange({\n r: Number(data.r) || rgb.r,\n g: Number(data.g) || rgb.g,\n b: Number(data.b) || rgb.b,\n a: rgb.a,\n source: 'rgb',\n })\n } else if (hsl && 'a' in data && data.a) {\n let alpha = Number(data.a)\n if (alpha < 0) {\n alpha = 0\n } else if (alpha > 100) {\n alpha = 100\n }\n alpha /= 100\n\n onChange({\n h: hsl.h,\n s: hsl.s,\n l: hsl.l,\n a: alpha,\n source: 'hsl',\n })\n }\n },\n [onChange, hsl, rgb]\n )\n\n return (\n <Flex>\n <Box flex={2} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"hex\"\n value={hex?.replace('#', '')}\n onChange={handleChange}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"r\"\n value={rgb?.r}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"g\"\n value={rgb?.g}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n <Box flex={1} marginRight={1}>\n <EditableInput\n style={inputStyles}\n label=\"b\"\n value={rgb?.b}\n onChange={handleChange}\n dragLabel\n dragMax={255}\n />\n </Box>\n {!disableAlpha && (\n <Box flex={1}>\n <EditableInput\n style={inputStyles}\n label=\"a\"\n value={Math.round((rgb?.a ?? 1) * 100)}\n onChange={handleChange}\n dragLabel\n dragMax={100}\n />\n </Box>\n )}\n </Flex>\n )\n}\n","export const hsvaColor = {\n title: 'Hue Saturation Value',\n name: 'hsvaColor',\n type: 'object',\n fields: [\n {name: 'h', type: 'number', title: 'Hue'},\n {name: 's', type: 'number', title: 'Saturation'},\n {name: 'v', type: 'number', title: 'Value'},\n {name: 'a', type: 'number', title: 'Alpha'},\n ],\n}\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../../"}
|