-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
245 lines (228 loc) · 11.4 KB
/
index.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Tailwind color palette by Ockam</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chroma-js/1.3.6/chroma.min.js"></script>
</head>
<body class="p-4 md:p-8">
<div id="app">
<h1 class="leading-none mb-1">Tailwind color palette</h1>
<p>Change color to generate a new palette (you can set the color to any format supported by
<a href="http://gka.github.io/chroma.js/#chroma" target="_blank">chroma.js</a>).
</p>
<div class="mt-4 p-4 border rounded shadow-md">
<div class="flex items-center mb-2">
<div class="w-1/4 md:w-1/6">
<label for="d3" class="block text-grey-dark font-bold md:text-right mb-1 md:mb-0 pr-4">Darkest</label>
</div>
<div class="w-1/4 md:w-1/6">
<input type="number" step="0.05" tabindex="4" v-model="darken[2]" id="d3" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
<div class="w-1/4 md:w-1/6 mx-2 self-stretch" :style="{backgroundColor: darkest}"></div>
<div class="w-1/4 md:w-1/6">
<input type="text" v-model="darkest" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
</div>
<div class="flex items-center mb-2">
<div class="w-1/4 md:w-1/6">
<label for="d2" class="block text-grey-dark font-bold md:text-right mb-1 md:mb-0 pr-4">Darker</label>
</div>
<div class="w-1/4 md:w-1/6">
<input type="number" step="0.05" tabindex="3" v-model="darken[1]" id="d2" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
<div class="w-1/4 md:w-1/6 mx-2 self-stretch" :style="{backgroundColor: darker}"></div>
<div class="w-1/4 md:w-1/6">
<input type="text" v-model="darker" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
</div>
<div class="flex items-center mb-2">
<div class="w-1/4 md:w-1/6">
<label for="d1" class="block text-grey-dark font-bold md:text-right mb-1 md:mb-0 pr-4">Dark</label>
</div>
<div class="w-1/4 md:w-1/6">
<input type="number" step="0.05" tabindex="2" v-model="darken[0]" id="d1" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
<div class="w-1/4 md:w-1/6 mx-2 self-stretch" :style="{backgroundColor: dark}"></div>
<div class="w-1/4 md:w-1/6">
<input type="text" v-model="dark" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
</div>
<div class="flex items-center mb-2">
<div class="w-1/4 md:w-1/6">
<label for="color" class="block text-grey-dark font-bold md:text-right mb-1 md:mb-0 pr-4">Color</label>
</div>
<div class="w-1/4 md:w-1/6">
<input type="text" tabindex="1" v-focus v-model.lazy="color" id="color" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker"
@focus>
</div>
<div class="w-1/4 md:w-1/6 mx-2 self-stretch flex items-center" :style="{backgroundColor: swatch}">
<small v-if="!colorIsValid" class="text-red">Invalid color!</small>
</div>
<div class="w-1/4 md:w-1/6">
<input type="text" v-model="swatch" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
</div>
<div class="flex items-center mb-2">
<div class="w-1/4 md:w-1/6">
<label for="b1" class="block text-grey-dark font-bold md:text-right mb-1 md:mb-0 pr-4">Light</label>
</div>
<div class="w-1/4 md:w-1/6">
<input type="number" step="0.05" tabindex="5" v-model="brighten[0]" id="b1" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
<div class="w-1/4 md:w-1/6 mx-2 self-stretch" :style="{backgroundColor: light}"></div>
<div class="w-1/4 md:w-1/6">
<input type="text" v-model="light" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
</div>
<div class="flex items-center mb-2">
<div class="w-1/4 md:w-1/6">
<label for="b2" class="block text-grey-dark font-bold md:text-right mb-1 md:mb-0 pr-4">Lighter</label>
</div>
<div class="w-1/4 md:w-1/6">
<input type="number" step="0.05" tabindex="6" v-model="brighten[1]" id="b2" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
<div class="w-1/4 md:w-1/6 mx-2 self-stretch" :style="{backgroundColor: lighter}"></div>
<div class="w-1/4 md:w-1/6">
<input type="text" v-model="lighter" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
</div>
<div class="flex items-center">
<div class="w-1/4 md:w-1/6">
<label for="b3" class="block text-grey-dark font-bold md:text-right mb-1 md:mb-0 pr-4">Lightest</label>
</div>
<div class="w-1/4 md:w-1/6">
<input type="number" step="0.05" tabindex="7" v-model="brighten[2]" id="b3" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
<div class="w-1/4 md:w-1/6 mx-2 self-stretch" :style="{backgroundColor: lightest}"></div>
<div class="w-1/4 md:w-1/6">
<input type="text" v-model="lightest" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker">
</div>
</div>
<div class="md:flex items-start mt-8 p-4 border">
<div class="sm:w-1/2 mb-4 md:flex items-center">
<div class="md:w-1/3 md:-ml-4">
<label for="var-name" class="block text-grey-dark font-bold md:text-right mb-1 md:mb-0 pr-4">Variable name</label>
</div>
<div class="md:w-2/3 md:mr-4">
<input type="text" class="shadow appearance-none border rounded w-full py-2 px-3 text-grey-darker" id="var-name" v-model="varName">
</div>
</div>
<div class="sm:w-1/2">
<pre class="">
"{{ varName }}-darkest": "{{ darkest }}",
"{{ varName }}-darker": "{{ darker }}",
"{{ varName }}-dark": "{{ dark }}",
"{{ varName }}": "{{ swatch }}",
"{{ varName }}-light": "{{ light }}",
"{{ varName }}-lighter": "{{ lighter }}",
"{{ varName }}-lightest": "{{ lightest }}"
</pre>
</div>
</div>
</div>
<p class="mt-8 text-sm text-grey-dark">All code is inline. You can save this file and make it yours. :)</p>
</div>
<script>
let app = new Vue({
el: '#app',
data: {
color: 'hotpink',
varName: 'hotpink',
darken: [1, 2, 2.6],
brighten: [1, 2, 2.5]
},
directives: {
focus: {
// directive definition
inserted: function (el) {
el.focus()
}
}
},
computed: {
colorIsValid() {
return this.validateColor(this.color)
},
darkest: {
get: function () {
return this.darkenColor(this.darken[2])
},
set: function (newVal) {
if (this.validateColor(newVal)) this.color = chroma(newVal).brighten(this.darken[2]).hex()
}
},
darker: {
get: function () {
return this.darkenColor(this.darken[1])
},
set: function (newVal) {
if (this.validateColor(newVal)) this.color = chroma(newVal).brighten(this.darken[1]).hex()
}
},
dark: {
get: function () {
return this.darkenColor(this.darken[0])
},
set: function (newVal) {
if (this.validateColor(newVal)) this.color = chroma(newVal).brighten(this.darken[0]).hex()
}
},
swatch: {
get: function () {
if (this.colorIsValid) return chroma(this.color).hex()
},
set: function (newVal) {
if (this.validateColor(newVal)) this.color = chroma(newVal).hex()
}
},
light: {
get: function () {
return this.brightenColor(this.brighten[0])
},
set: function (newVal) {
if (this.validateColor(newVal)) this.color = chroma(newVal).darken(this.brighten[0]).hex()
}
},
lighter: {
get: function () {
return this.brightenColor(this.brighten[1])
},
set: function (newVal) {
if (this.validateColor(newVal)) this.color = chroma(newVal).darken(this.brighten[1]).hex()
}
},
lightest: {
get: function () {
return this.brightenColor(this.brighten[2])
},
set: function (newVal) {
if (this.validateColor(newVal)) this.color = chroma(newVal).darken(this.brighten[2]).hex()
}
},
},
methods: {
validateColor(color) {
try {
chroma(color)
return true
}
catch (error) {
return false
}
},
darkenColor(value) {
if (this.colorIsValid) return chroma(this.color).darken(value).hex()
},
brightenColor(value) {
if (this.colorIsValid) return chroma(this.color).brighten(value).hex()
}
},
})
</script>
</body>
</html>