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