@thednp/color-picker 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -1
- package/dist/css/color-picker.css +82 -46
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +82 -46
- package/dist/css/color-picker.rtl.min.css +2 -2
- package/dist/js/color-esm.js +1 -1
- package/dist/js/color-esm.min.js +1 -1
- package/dist/js/color-palette-esm.js +1 -1
- package/dist/js/color-palette-esm.min.js +1 -1
- package/dist/js/color-palette.js +1 -1
- package/dist/js/color-palette.min.js +1 -1
- package/dist/js/color-picker-element-esm.js +180 -164
- package/dist/js/color-picker-element-esm.min.js +2 -2
- package/dist/js/color-picker-element.js +180 -164
- package/dist/js/color-picker-element.min.js +2 -2
- package/dist/js/color-picker-esm.js +69 -113
- package/dist/js/color-picker-esm.min.js +2 -2
- package/dist/js/color-picker.js +69 -113
- package/dist/js/color-picker.min.js +2 -2
- package/dist/js/color.js +1 -1
- package/dist/js/color.min.js +1 -1
- package/package.json +17 -14
- package/src/js/color-picker-element.js +44 -33
- package/src/js/color-picker.js +43 -44
- package/src/js/util/getColorMenu.js +7 -8
- package/src/js/util/setMarkup.js +4 -7
- package/src/js/util/toggleCEAttr.js +70 -0
- package/src/scss/_variables.scss +7 -0
- package/src/scss/color-picker.scss +86 -45
- package/types/index.d.ts +1 -1
- package/types/source/types.d.ts +8 -6
@@ -1,8 +1,43 @@
|
|
1
|
+
@import "variables";
|
2
|
+
|
1
3
|
/* :host */
|
2
4
|
color-picker,
|
3
5
|
.color-picker {
|
4
6
|
position: relative;
|
5
7
|
display: flex;
|
8
|
+
|
9
|
+
@each $name in "white", "black" {
|
10
|
+
@each $lvl in $transparency-levels {
|
11
|
+
@if (type-of($name) == "string" and type-of($lvl) == "number") {
|
12
|
+
$color: #fff;
|
13
|
+
@if $name == "black" {
|
14
|
+
$color: #000;
|
15
|
+
}
|
16
|
+
$rgba: rgba($color, $lvl * .01);
|
17
|
+
--#{$name}-#{$lvl}: #{$rgba};
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
--dropdown-transition: #{$dropdown-transition};
|
22
|
+
--btn-transition: #{$btn-transition};
|
23
|
+
--options-transition: #{$options-transition};
|
24
|
+
--dropdown-bg: var(--black-75);
|
25
|
+
--dropdown-color: var(--white-75);
|
26
|
+
--dropdown-shadow: 0 6px 12px var(--black-33);
|
27
|
+
--dropdown-scrollbar-bg: var(--white-33);
|
28
|
+
--dropdown-scrollbar-bg-hover: var(--white-50);
|
29
|
+
--knob-bg: #000;
|
30
|
+
--knob-border: 1px solid var(--white-90);
|
31
|
+
--knob-shadow-hover: 0 0 0 6px var(--white-50);
|
32
|
+
--knob-shadow-active: 0 0 0 6px var(--white-90);
|
33
|
+
--input-border: 1px solid var(--white-15);
|
34
|
+
--input-border-hover: 1px solid var(--white-33);
|
35
|
+
--input-bg-hover: var(--black-15);
|
36
|
+
--option-color-hover: var(--black-75);
|
37
|
+
--option-bg-hover: var(--white-50);
|
38
|
+
--option-color-active: var(--black-75);
|
39
|
+
--option-bg-active: var(--white-90);
|
40
|
+
--visual-shadow: 0 0 0 1px var(--white-15) inset;
|
6
41
|
}
|
7
42
|
|
8
43
|
color-picker:focus,
|
@@ -18,12 +53,12 @@ color-picker:focus,
|
|
18
53
|
flex-direction: column;
|
19
54
|
width: min-content;
|
20
55
|
padding: .5rem;
|
21
|
-
color:
|
22
|
-
background:
|
56
|
+
color: var(--dropdown-color);
|
57
|
+
background: var(--dropdown-bg);
|
23
58
|
border-radius: .5rem;
|
24
|
-
box-shadow:
|
59
|
+
box-shadow: var(--dropdown-shadow);
|
25
60
|
opacity: 0;
|
26
|
-
transition:
|
61
|
+
transition: var(--dropdown-transition);
|
27
62
|
}
|
28
63
|
|
29
64
|
.color-dropdown.picker { left: 0; }
|
@@ -65,12 +100,13 @@ color-picker:focus,
|
|
65
100
|
border-radius: .25rem;
|
66
101
|
outline: none;
|
67
102
|
appearance: none;
|
68
|
-
transition-duration: .33s;
|
69
|
-
transition-property: box-shadow, border;
|
103
|
+
// transition-duration: .33s;
|
104
|
+
// transition-property: box-shadow, border;
|
105
|
+
transition: var(--btn-transition);
|
70
106
|
}
|
71
107
|
.btn-appearance:focus,
|
72
108
|
.btn-appearance:hover {
|
73
|
-
box-shadow: 0 0 0 3px
|
109
|
+
box-shadow: 0 0 0 3px var(--black-15);
|
74
110
|
}
|
75
111
|
|
76
112
|
/* color-preview */
|
@@ -80,23 +116,23 @@ color-picker:focus,
|
|
80
116
|
}
|
81
117
|
|
82
118
|
.txt-dark .color-preview {
|
83
|
-
color:
|
119
|
+
color: var(--white-75);
|
84
120
|
}
|
85
121
|
.txt-dark .color-preview:focus {
|
86
|
-
box-shadow: 0 0 0 1px
|
122
|
+
box-shadow: 0 0 0 1px #fff inset, 0 0 0 3px var(--black-15);
|
87
123
|
}
|
88
124
|
.txt-dark .color-preview::placeholder {
|
89
|
-
color:
|
125
|
+
color: var(--white-50);
|
90
126
|
}
|
91
127
|
.txt-light .color-preview {
|
92
|
-
color:
|
128
|
+
color: var(--black-75);
|
93
129
|
}
|
94
130
|
.txt-light .color-preview:focus {
|
95
|
-
color:
|
96
|
-
box-shadow: 0 0 0 1px
|
131
|
+
color: var(--black-75);
|
132
|
+
box-shadow: 0 0 0 1px var(--black-50) inset, 0 0 0 3px var(--black-15);
|
97
133
|
}
|
98
134
|
.txt-light .color-preview::placeholder {
|
99
|
-
color:
|
135
|
+
color: var(--black-50);
|
100
136
|
}
|
101
137
|
|
102
138
|
/* picker-toggle */
|
@@ -128,18 +164,18 @@ color-picker:focus,
|
|
128
164
|
border-radius: 0 .25rem .25rem 0;
|
129
165
|
}
|
130
166
|
.txt-light .menu-toggle {
|
131
|
-
background:
|
167
|
+
background: var(--black-50);
|
132
168
|
}
|
133
169
|
.txt-light .menu-toggle:focus,
|
134
170
|
.txt-light .menu-toggle:focus {
|
135
|
-
background:
|
171
|
+
background: var(--black-75);
|
136
172
|
}
|
137
173
|
.txt-dark .menu-toggle {
|
138
|
-
background:
|
174
|
+
background: var(--white-33);
|
139
175
|
}
|
140
176
|
.txt-dark .menu-toggle:focus,
|
141
177
|
.txt-dark .menu-toggle:focus {
|
142
|
-
background:
|
178
|
+
background: var(--white-50);
|
143
179
|
}
|
144
180
|
.menu-toggle svg {
|
145
181
|
width: auto;
|
@@ -168,11 +204,11 @@ color-picker:focus,
|
|
168
204
|
}
|
169
205
|
|
170
206
|
.scrollable:hover::-webkit-scrollbar-thumb {
|
171
|
-
background-color:
|
207
|
+
background-color: var(--dropdown-scrollbar-bg);
|
172
208
|
}
|
173
209
|
|
174
210
|
.scrollable::-webkit-scrollbar-thumb:hover {
|
175
|
-
background-color:
|
211
|
+
background-color: var(--dropdown-scrollbar-bg-hover);
|
176
212
|
}
|
177
213
|
|
178
214
|
/* color-defaults */
|
@@ -205,27 +241,28 @@ color-picker:focus,
|
|
205
241
|
|
206
242
|
.color-defaults .color-option:focus,
|
207
243
|
.color-defaults .color-option:hover {
|
208
|
-
|
244
|
+
color: var(--option-color-hover);
|
245
|
+
background: var(--option-bg-hover);
|
209
246
|
outline: none;
|
210
247
|
}
|
211
248
|
|
212
249
|
.color-defaults .color-option:active,
|
213
250
|
.color-defaults .color-option.active {
|
214
|
-
color:
|
215
|
-
background:
|
251
|
+
color: var(--option-color-active);
|
252
|
+
background: var(--option-bg-active);
|
216
253
|
}
|
217
254
|
|
218
255
|
/* color-options grid */
|
219
256
|
.color-options {
|
220
|
-
display: grid;
|
221
|
-
padding: 0;
|
222
|
-
margin: 0;
|
223
|
-
list-style: none;
|
224
257
|
--grid-item-size: 2rem; // grid item width / height
|
225
258
|
--grid-fit: 5; // grid columns
|
226
259
|
--grid-gap: .25rem; // grid vertical / horizontal spacing
|
227
260
|
--grid-height: auto; // default height
|
228
261
|
--grid-hover-height: auto; // height on hover
|
262
|
+
display: grid;
|
263
|
+
padding: 0;
|
264
|
+
margin: 0;
|
265
|
+
list-style: none;
|
229
266
|
grid-template-columns: repeat(var(--grid-fit), var(--grid-item-size));
|
230
267
|
grid-template-rows: repeat(auto-fill, var(--grid-item-size));
|
231
268
|
gap: var(--grid-gap);
|
@@ -234,7 +271,7 @@ color-picker:focus,
|
|
234
271
|
height: var(--grid-height);
|
235
272
|
margin: 0 -.5rem 0 0; // 0.5rem is the scrollbar width
|
236
273
|
overflow-y: scroll;
|
237
|
-
transition:
|
274
|
+
transition: var(--options-transition);
|
238
275
|
}
|
239
276
|
.color-options.scrollable:hover {
|
240
277
|
height: var(--grid-hover-height);
|
@@ -272,7 +309,7 @@ color-picker:focus,
|
|
272
309
|
.color-options .color-option:active::before,
|
273
310
|
.color-options .color-option:focus::before {
|
274
311
|
content: "";
|
275
|
-
border: 3px solid
|
312
|
+
border: 3px solid var(--white-75);
|
276
313
|
mix-blend-mode: difference;
|
277
314
|
}
|
278
315
|
|
@@ -294,10 +331,10 @@ color-picker:focus,
|
|
294
331
|
}
|
295
332
|
}
|
296
333
|
.txt-dark .color-options .color-option.active:after {
|
297
|
-
box-shadow: 0 0 0 4px
|
334
|
+
box-shadow: 0 0 0 4px var(--white-90);
|
298
335
|
}
|
299
336
|
.txt-light .color-options .color-option.active:after {
|
300
|
-
box-shadow: 0 0 0 4px
|
337
|
+
box-shadow: 0 0 0 4px var(--black-90);
|
301
338
|
}
|
302
339
|
|
303
340
|
/* color-form */
|
@@ -328,25 +365,27 @@ color-picker:focus,
|
|
328
365
|
color: inherit;
|
329
366
|
text-align: right;
|
330
367
|
background: transparent;
|
331
|
-
border:
|
368
|
+
border: var(--input-border);
|
332
369
|
outline: none;
|
333
370
|
}
|
334
371
|
|
335
372
|
.color-input.hex {
|
336
373
|
width: 92.5%;
|
337
374
|
max-width: 92.5%;
|
338
|
-
/* width: calc(100% - 4% - 1rem); */
|
339
375
|
}
|
340
376
|
|
341
377
|
.color-input:active,
|
342
378
|
.color-input:focus {
|
343
|
-
background:
|
344
|
-
border:
|
379
|
+
background: var(--input-bg-hover);
|
380
|
+
border: var(--input-border-hover);
|
345
381
|
}
|
346
382
|
|
347
383
|
/* visual control */
|
348
384
|
.visual-control {
|
349
385
|
height: 150px;
|
386
|
+
/* important for mobile devices */
|
387
|
+
touch-action: none;
|
388
|
+
box-shadow: var(--visual-shadow);
|
350
389
|
}
|
351
390
|
|
352
391
|
.visual-control1 {
|
@@ -389,20 +428,22 @@ color-picker:focus,
|
|
389
428
|
top: 0;
|
390
429
|
left: 0;
|
391
430
|
height: 7px;
|
431
|
+
/* important for mobile devices */
|
432
|
+
touch-action: none;
|
392
433
|
user-select: none;
|
393
|
-
background-color:
|
394
|
-
border:
|
434
|
+
background-color: var(--knob-bg);
|
435
|
+
border: var(--knob-border);
|
395
436
|
border-radius: 5px;
|
396
437
|
outline: none;
|
397
438
|
will-change: transform;
|
398
439
|
}
|
399
440
|
.knob:hover {
|
400
|
-
box-shadow:
|
441
|
+
box-shadow: var(--knob-shadow-hover);
|
401
442
|
}
|
402
443
|
.knob:focus,
|
403
444
|
.knob:active {
|
404
445
|
z-index: 1;
|
405
|
-
box-shadow:
|
446
|
+
box-shadow: var(--knob-shadow-active);
|
406
447
|
}
|
407
448
|
|
408
449
|
/* color-pointer */
|
@@ -413,26 +454,26 @@ color-picker:focus,
|
|
413
454
|
}
|
414
455
|
|
415
456
|
.txt-dark .color-pointer {
|
416
|
-
box-shadow: 0 0 0 5px
|
457
|
+
box-shadow: 0 0 0 5px var(--white-50);
|
417
458
|
}
|
418
459
|
.txt-light .color-pointer {
|
419
|
-
box-shadow: 0 0 0 5px
|
460
|
+
box-shadow: 0 0 0 5px var(--black-50);
|
420
461
|
}
|
421
462
|
|
422
463
|
.txt-dark .color-pointer:hover {
|
423
|
-
box-shadow: 0 0 0 5px
|
464
|
+
box-shadow: 0 0 0 5px var(--white-75);
|
424
465
|
}
|
425
466
|
.txt-light .color-pointer:hover {
|
426
|
-
box-shadow: 0 0 0 5px
|
467
|
+
box-shadow: 0 0 0 5px var(--black-75);
|
427
468
|
}
|
428
469
|
|
429
470
|
.txt-dark .color-pointer:focus,
|
430
471
|
.txt-dark .color-pointer:active {
|
431
|
-
box-shadow: 0 0 0 5px
|
472
|
+
box-shadow: 0 0 0 5px var(--white-90);
|
432
473
|
}
|
433
474
|
.txt-light .color-pointer:focus,
|
434
475
|
.txt-light .color-pointer:active {
|
435
|
-
box-shadow: 0 0 0 5px
|
476
|
+
box-shadow: 0 0 0 5px var(--black-90);
|
436
477
|
}
|
437
478
|
|
438
479
|
/* utility */
|
package/types/index.d.ts
CHANGED
package/types/source/types.d.ts
CHANGED
@@ -32,9 +32,6 @@ export interface RGBA extends RGB {
|
|
32
32
|
* @link https://en.wikibooks.org/wiki/Color_Models:_RGB,_HSV,_HSL#HSL
|
33
33
|
*/
|
34
34
|
export interface HSL {
|
35
|
-
// h: number | string;
|
36
|
-
// s: number | string;
|
37
|
-
// l: number | string;
|
38
35
|
h: number;
|
39
36
|
s: number;
|
40
37
|
l: number;
|
@@ -79,12 +76,17 @@ export interface ColorPickerOptions {
|
|
79
76
|
colorLabels?: string[];
|
80
77
|
componentLabels?: Record<string, string>;
|
81
78
|
format?: ColorFormats;
|
82
|
-
colorPresets?: string[]
|
79
|
+
colorPresets?: string[] | {
|
80
|
+
hue: number,
|
81
|
+
lightSteps: number,
|
82
|
+
hueSteps: number,
|
83
|
+
colors: string[],
|
84
|
+
};
|
83
85
|
colorKeywords?: string[];
|
84
86
|
}
|
85
87
|
|
86
88
|
export type ColorInput = string | RGB | RGBA | HSL | HSLA | HSV | HSVA | HWB | ColorObject;
|
87
89
|
export type ColorFormats = string | 'rgb' | 'hex' | 'hex3' | 'hex4' | 'hex6' | 'hex8' | 'hsl' | 'hsv' | 'hwb';
|
88
90
|
|
89
|
-
export type GetInstance<T> = (
|
90
|
-
export type InitCallback<T> = (element:
|
91
|
+
export type GetInstance<T, ET> = (target: ET | string, component: string) => T | null;
|
92
|
+
export type InitCallback<T> = (element: HTMLInputElement | string ) => T;
|