@@ -4,6 +4,9 @@ const pickers = ['chrome', 'sketch', 'photoshop', 'compact', 'grayscale', 'mater
4
4
const searchParams = parseSearchParams (location .search );
5
5
const manualEnabledPickers = searchParams .picker ?.split (' ,' );
6
6
7
+ const DEFAULT_COLOR = ' F5F7FA' ;
8
+ const DEFAULT_COLOR_DARK = ' #004035' ;
9
+
7
10
function invertColor({ r , g , b , a }: { r: number ; g: number ; b: number , a: number }): string {
8
11
const invert = (val : number , alpha : number ) => alpha === 0 ? 0 : 255 - val ;
9
12
const inverted = {
@@ -16,7 +19,7 @@ function invertColor({ r, g, b, a}: { r: number; g: number; b: number, a: number
16
19
}
17
20
18
21
const hasInitialColor = !! searchParams .hex ;
19
- const initialColor = ` #${searchParams .hex ?? ' F5F7FA ' } ` ;
22
+ const initialColor = ` #${searchParams .hex ?? DEFAULT_COLOR } ` ;
20
23
</script >
21
24
22
25
<script setup lang="ts">
@@ -36,8 +39,8 @@ import {
36
39
tinycolor
37
40
// } from '../dist/vue-color.js';
38
41
} from ' ../src' ;
39
-
40
- // import '../dist/vue-color.css'
42
+ import ThemeToggle from ' ./components/ThemeToggle.vue ' ;
43
+ // import '../dist/vue-color.css';
41
44
42
45
const showStatus: Record <(typeof pickers )[number ], boolean > = {} as Record <(typeof pickers )[number ], boolean >;
43
46
pickers .forEach ((picker ) => {
@@ -76,7 +79,7 @@ const hsva = computed(() => {
76
79
const hsva = tinycolor (tinyColor .value ).toHsv ();
77
80
const res: Record <string , number > = {};
78
81
for (const [key, value] of Object .entries (hsva )) {
79
- res [key ] = value .toFixed (2 );
82
+ res [key ] = Number ( value .toFixed (2 ) );
80
83
}
81
84
return res ;
82
85
});
@@ -89,23 +92,32 @@ const updateHue = (newHue: number) => {
89
92
tinyColor .value = tinycolor (tinyColor .value ).spin (newHue - hsva .value .h ).clone ();
90
93
}
91
94
95
+ const onModeChange = (isDark : boolean ) => {
96
+ if (isDark ) {
97
+ tinyColor .value = tinycolor (DEFAULT_COLOR_DARK );
98
+ } else {
99
+ tinyColor .value = tinycolor (initialColor );
100
+ }
101
+ }
102
+
92
103
</script >
93
104
94
105
<template >
95
106
<div class =" color-background" :style =" [background]" ></div >
96
107
<div class =" wrapper" >
97
- <div >
108
+ <div class = " fixed-side " >
98
109
<div class =" title text" >
99
- <h1 >Vue-color</ h1 >< span class =" tag" >v3.0</span >
110
+ <h1 >Vue-color<span class =" tag" >v3.0</span ></ h1 >
100
111
</div >
101
112
102
113
<main class =" intro text" >
103
114
A collection of efficient color pickers designed for modern web development.
104
- <ul class =" feature-list text" :style = " {color: textColor, opacity: 0.75} " >
115
+ <ul class =" feature-list text" >
105
116
<li >✅ Modular & Tree-Shakable</li >
106
117
<li >✅ TypeScript Ready</li >
107
118
<li >✅ SSR-Friendly</li >
108
119
<li >✅ Optimized for Accessibility</li >
120
+ <li class =" dark-mode" ><span >✅ Supports Dark Theme</span ><ThemeToggle style =" margin-left : 10px ;" :color =" textColor" @change =" onModeChange" /></li >
109
121
</ul >
110
122
</main >
111
123
<a
@@ -118,65 +130,65 @@ const updateHue = (newHue: number) => {
118
130
Get Started   ; 🚀
119
131
</a >
120
132
</div >
121
- <div :style = " {flex: 0.8} " >
133
+ <div class = " picker-containers " >
122
134
<div class =" row" >
123
135
<div class =" col" >
124
136
<div class =" text current-color" >
125
137
{{ hex }}<br />
126
- {{ color }}<br />
127
- {{ hsva }}
138
+ {{ tinyColor.toRgbString() }}<br />
139
+ {{ tinyColor.toHsvString() }}
128
140
</div >
129
- <div class = " picker-container " v-if =" showStatus.chrome" >
141
+ <div v-if =" showStatus.chrome" >
130
142
<ChromePicker v-model:tinyColor =" tinyColor" v-model =" color" />
131
143
<div class =" picker-title text" >< ; ChromePicker /> ; </div >
132
144
</div >
133
145
</div >
134
146
135
- <div class =" picker-container " v-if =" showStatus.sketch" >
147
+ <div class =" col " v-if =" showStatus.sketch" >
136
148
<div ><SketchPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
137
149
<div class =" picker-title text" >< ; SketchPicker /> ; </div >
138
150
</div >
139
151
140
- <div class =" picker-container " v-if =" showStatus.photoshop" >
152
+ <div class =" col " v-if =" showStatus.photoshop" >
141
153
<div ><PhotoshopPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
142
154
<div class =" picker-title text" >< ; PhotoshopPicker /> ; </div >
143
155
</div >
144
156
</div >
145
- <div class =" row" :style = " {marginTop: '5%'} " >
157
+ <div class =" row" >
146
158
<div class =" col" >
147
- <div class = " picker-container " v-if =" showStatus.compact" >
159
+ <div v-if =" showStatus.compact" >
148
160
<div ><CompactPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
149
161
<div class =" picker-title text" >< ; CompactPicker /> ; </div >
150
162
</div >
151
- <div class = " picker-container " v-if =" showStatus.grayscale" >
163
+ <div v-if =" showStatus.grayscale" >
152
164
<div ><GrayscalePicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
153
165
<div class =" picker-title text" >< ; GrayscalePicker /> ; </div >
154
166
</div >
155
- <div class = " picker-container " v-if =" showStatus.material" >
167
+ <div v-if =" showStatus.material" >
156
168
<div ><MaterialPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
157
169
<div class =" picker-title text" >< ; MaterialPicker /> ; </div >
158
170
</div >
159
171
</div >
160
172
161
173
<div class =" col" >
162
- <div class = " picker-container " v-if =" showStatus.hue" >
174
+ <div v-if =" showStatus.hue" >
163
175
<div :style =" {width: '410px'}" ><HueSlider :modelValue =" hsva.h" @update:modelValue =" updateHue" /></div >
164
176
<div class =" picker-title text" >< ; HueSlider /> ; </div >
165
177
</div >
166
178
167
- <div class = " picker-container " v-if =" showStatus.slider" >
179
+ <div v-if =" showStatus.slider" >
168
180
<div ><SliderPicker v-model:tinyColor =" tinyColor" v-model =" color" :alpha =" true" /></div >
169
181
<div class =" picker-title text" >< ; SliderPicker /> ; </div >
170
182
</div >
171
183
172
- <div class = " picker-container " v-if =" showStatus.twitter" >
184
+ <div v-if =" showStatus.twitter" >
173
185
<div ><TwitterPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
174
186
<div class =" picker-title text" >< ; TwitterPicker /> ; </div >
175
187
</div >
176
188
</div >
177
189
178
190
<div class =" col" >
179
- <div class = " picker-container " v-if =" showStatus.swatches" >
191
+ <div v-if =" showStatus.swatches" >
180
192
<div ><SwatchesPicker v-model:tinyColor =" tinyColor" v-model =" color" /></div >
181
193
<div class =" picker-title text" >< ; SwatchesPicker /> ; </div >
182
194
</div >
@@ -199,68 +211,82 @@ const updateHue = (newHue: number) => {
199
211
display : block ;
200
212
}
201
213
214
+ .color-background {
215
+ position : absolute ;
216
+ top : 0 ;
217
+ left : 0 ;
218
+ width : 100% ;
219
+ height : 100% ;
220
+ z-index : -1 ;
221
+ }
222
+
202
223
.wrapper {
203
224
display : flex ;
204
- justify-content : space-evenly ;
205
- padding : 50px 0 ;
225
+ padding : 50px 0 0 50px ;
206
226
}
207
227
208
- .row {
209
- display : flex ;
210
- align-items : center ;
211
- justify-content : space-between ;
228
+ .fixed-side {
229
+ width : 300px ;
212
230
}
213
231
214
- .col {
215
- display : flex ;
216
- flex-direction : column ;
217
- gap : 20px ;
232
+ .picker-containers {
233
+ flex : 1 ;
218
234
}
219
235
220
- .color-background {
221
- width : 100vw ;
222
- height : 100vh ;
223
- position : absolute ;
224
- top : 0 ;
225
- left : 0 ;
226
- z-index : -1 ;
236
+ .row {
237
+ width : 100% ;
238
+ display : flex ;
239
+ flex-wrap : wrap ;
240
+ justify-content : center ;
241
+ align-items : center ;
242
+ gap : 50px ;
243
+ margin-bottom : 50px ;
227
244
}
228
245
229
246
.title {
230
247
display : flex ;
248
+ margin-bottom : 18px ;
231
249
}
232
250
233
251
.title h1 {
252
+ position : relative ;
234
253
display : inline-block ;
235
254
font-size : 60px ;
236
255
font-weight : bold ;
237
256
margin : 0 ;
238
257
}
239
258
240
259
.tag {
260
+ position : absolute ;
261
+ top : 0 ;
262
+ right : -20% ;
241
263
display : block ;
242
- font-size : 16px ;
243
- width : 30px ;
244
- height : 20px ;
245
- border-radius : 6px ;
246
- text-align : center ;
247
- background-color : #42B883 ;
248
264
padding : 2px 4px ;
249
- margin-left : 10 px ;
265
+ border-radius : 6 px ;
250
266
color : #fff ;
267
+ background-color : #42B883 ;
268
+ font-size : 16px ;
269
+ font-weight :lighter ;
270
+ text-align : center ;
251
271
}
252
272
253
273
.intro {
254
274
font-size : 20px ;
255
- line-height : 1.5 ;
275
+ line-height : 1.8 ;
256
276
width : 300px ;
257
277
}
258
278
259
279
.feature-list {
260
- line-height : 1.6 ;
280
+ line-height : 1.8 ;
261
281
padding-left : 0px ;
262
282
list-style : none ;
263
283
font-size : 18px ;
284
+ opacity : 0.75 ;
285
+ }
286
+
287
+ .dark-mode {
288
+ display : flex ;
289
+ align-items : center ;
264
290
}
265
291
266
292
.get-started {
@@ -280,20 +306,16 @@ const updateHue = (newHue: number) => {
280
306
opacity : 0.8 ;
281
307
}
282
308
283
- .picker-container {
284
- margin-left : 5% ;
285
- }
286
-
287
309
.picker-title {
288
310
margin-top : 10px ;
311
+ margin-bottom : 20px ;
289
312
font-size : 14px ;
290
- opacity : 0.5 ;
313
+ opacity : 0.75 ;
291
314
}
292
315
293
316
.current-color {
294
- padding : 10px ;
295
- width : 240px ;
296
- height : 100px ;
297
- line-height : 1.5 ;
317
+ margin-bottom : 10px ;
318
+ line-height : 1.7 ;
319
+ opacity : 0.75 ;
298
320
}
299
321
</style >
0 commit comments