-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.html
179 lines (151 loc) · 4.47 KB
/
ui.html
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<div class="container">
<div class="vStack-16">
<div>
<h2 class="title">Generate Palette</h2>
<p>Paste your colors in any format that you like, JSON, array, or simply a list of values</p>
</div>
<form class="vStack-16">
<div class="vStack-8">
<label for="input">Input</label>
<textarea id="colorsInput" required placeholder="JSON here..." rows="14" spellcheck="false"></textarea>
<label for="name">Color name</label>
<input id="colorName" type="text" placeholder="Tomato" />
</div>
<div class="hStack-16">
<button class="button--primary" type="submit" id="create">Generate Palette</button>
<button class="button--minimal" id="cancel">Cancel</button>
</div>
</form>
</div>
<script>
document.querySelector('form').onsubmit = (e) => {
e.preventDefault();
const colorsInput = document.getElementById('colorsInput');
const colorNameInput = document.getElementById('colorName');
let payload = {
name: colorNameInput.value,
}
try {
const json = JSON.parse(colorsInput.value);
payload.colors = colorsInput.value
parent.postMessage({ pluginMessage: { type: 'generate-palette', payload: JSON.stringify(payload) } }, '*')
} catch (error) {
// TODO: error handling
// This handles the case where the user pastes a JSON string, but it's not valid JSON
const json = JSON.stringify(colorsInput.value)
const matchedColors = json.match(/(#[\w\d]{6})/ig)
payload.colors = matchedColors
parent.postMessage({ pluginMessage: { type: 'generate-palette', payload: JSON.stringify(payload) } }, '*')
}
}
document.getElementById('cancel').onclick = () => {
parent.postMessage({ pluginMessage: { type: 'cancel' } }, '*')
}
</script>
<style>
body {
--text-heading: #11181c;
--text-body: #687076;
--gray-base: #889096;
--gray-light: #d7dbdf;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
--webkit-font-smoothing: antialiased;
color: var(--text-body);
line-height: 1.5;
font-size: 14px;
}
h1, h2, h3, p, form {
margin: 0;
}
h2 {
color: var(--text-heading);
}
.vStack-16 > * + * {
margin-top: 16px;
}
.vStack-8 > * + * {
margin-top: 8px;
}
.hStack-16 {
display: flex;
gap: 16px;
align-items: center;
}
.container {
padding: 16px;
}
label {
display: block;
font-weight: 500;
color: var(--text-heading);
}
textarea, input {
display: block;
width: 100%;
font-family: inherit;
font-size: 14px;
color: var(--text-heading);
padding: 8px;
border-radius: 4px;
box-shadow: inset 0 0 0 1px var(--gray-light);
border: none;
}
textarea::placeholder, input::placeholder {
color: var(--gray-base);
}
textarea {
resize: vertical;
font-family: monospace;
}
button {
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
border: none;
border-radius: 3px;
cursor: pointer;
font-size: 14px;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
padding: 4px 16px;
text-align: left;
vertical-align: middle;
min-height: 30px;
min-width: 30px;
outline: none;
}
.button--primary:hover {
background-color: #3a5ccc;
}
.button--primary:active {
background-color: #3451b2;
}
.button--primary {
background-color: #3e63dd;
background-image: linear-gradient(180deg,hsla(0,0%,100%,.1),hsla(0,0%,100%,0));
-webkit-box-shadow: inset 0 0 0 1px rgb(16 22 26 / 40%), inset 0 -1px 0 rgb(16 22 26 / 20%);
box-shadow: inset 0 0 0 1px rgb(16 22 26 / 40%), inset 0 -1px 0 rgb(16 22 26 / 20%);
color:#fdfdfe;
}
.button--minimal:hover {
background-color: #eceef0;
}
.button--minimal:active {
background-color: #e6e8eb;
}
.button--minimal {
color: inherit;
background: none;
box-shadow: none;
}
</style>
</div>