-
-
Notifications
You must be signed in to change notification settings - Fork 289
/
index.js
155 lines (140 loc) · 4.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
const pickrContainer = document.querySelector('.pickr-container');
const themeContainer = document.querySelector('.theme-container');
const themes = [
[
'classic',
{
swatches: [
'rgba(244, 67, 54, 1)',
'rgba(233, 30, 99, 0.95)',
'rgba(156, 39, 176, 0.9)',
'rgba(103, 58, 183, 0.85)',
'rgba(63, 81, 181, 0.8)',
'rgba(33, 150, 243, 0.75)',
'rgba(3, 169, 244, 0.7)',
'rgba(0, 188, 212, 0.7)',
'rgba(0, 150, 136, 0.75)',
'rgba(76, 175, 80, 0.8)',
'rgba(139, 195, 74, 0.85)',
'rgba(205, 220, 57, 0.9)',
'rgba(255, 235, 59, 0.95)',
'rgba(255, 193, 7, 1)'
],
components: {
preview: true,
opacity: true,
hue: true,
interaction: {
hex: true,
rgba: true,
hsva: true,
input: true,
clear: true,
save: true
}
}
}
],
[
'monolith',
{
swatches: [
'rgba(244, 67, 54, 1)',
'rgba(233, 30, 99, 0.95)',
'rgba(156, 39, 176, 0.9)',
'rgba(103, 58, 183, 0.85)',
'rgba(63, 81, 181, 0.8)',
'rgba(33, 150, 243, 0.75)',
'rgba(3, 169, 244, 0.7)'
],
defaultRepresentation: 'HEXA',
components: {
preview: true,
opacity: true,
hue: true,
interaction: {
hex: false,
rgba: false,
hsva: false,
input: true,
clear: true,
save: true
}
}
}
],
[
'nano',
{
swatches: [
'rgba(244, 67, 54, 1)',
'rgba(233, 30, 99, 0.95)',
'rgba(156, 39, 176, 0.9)',
'rgba(103, 58, 183, 0.85)',
'rgba(63, 81, 181, 0.8)',
'rgba(33, 150, 243, 0.75)',
'rgba(3, 169, 244, 0.7)'
],
defaultRepresentation: 'HEXA',
components: {
preview: true,
opacity: true,
hue: true,
interaction: {
hex: false,
rgba: false,
hsva: false,
input: true,
clear: true,
save: true
}
}
}
]
];
const buttons = [];
let pickr = null;
for (const [theme, config] of themes) {
const button = document.createElement('button');
button.innerHTML = theme;
buttons.push(button);
button.addEventListener('click', () => {
const el = document.createElement('p');
pickrContainer.appendChild(el);
// Delete previous instance
if (pickr) {
pickr.destroyAndRemove();
}
// Apply active class
for (const btn of buttons) {
btn.classList[btn === button ? 'add' : 'remove']('active');
}
// Create fresh instance
pickr = new Pickr(Object.assign({
el, theme,
default: '#42445a'
}, config));
// Set events
pickr.on('init', instance => {
console.log('Event: "init"', instance);
}).on('hide', instance => {
console.log('Event: "hide"', instance);
}).on('show', (color, instance) => {
console.log('Event: "show"', color, instance);
}).on('save', (color, instance) => {
console.log('Event: "save"', color, instance);
}).on('clear', instance => {
console.log('Event: "clear"', instance);
}).on('change', (color, source, instance) => {
console.log('Event: "change"', color, source, instance);
}).on('changestop', (source, instance) => {
console.log('Event: "changestop"', source, instance);
}).on('cancel', instance => {
console.log('cancel', pickr.getColor().toRGBA().toString(0));
}).on('swatchselect', (color, instance) => {
console.log('Event: "swatchselect"', color, instance);
});
});
themeContainer.appendChild(button);
}
buttons[0].click();