Skip to content

Commit 682a6c7

Browse files
committed
add theme changing
1 parent 8023aff commit 682a6c7

File tree

1 file changed

+85
-17
lines changed

1 file changed

+85
-17
lines changed

src/routes/+page.svelte

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
} from 'date-fns';
1212
import Dot from '../components/dot.svelte';
1313
import { browser } from '$app/environment';
14-
import * as Lockr from "lockr"
15-
14+
import * as Lockr from 'lockr';
15+
import ColorPicker from 'svelte-awesome-color-picker';
1616
1717
function changeBg() {
1818
document.querySelector(':root').style.setProperty('--bg-color', '#ffffff');
@@ -119,22 +119,30 @@
119119
let viewID = $derived(timerange + unit + colsName);
120120
121121
function save() {
122-
console.log("SAVING!")
123-
Lockr.set(viewID + "_notes", currentNotes)
124-
Lockr.set(viewID + "_colors", currentColors)
122+
console.log('SAVING!');
123+
Lockr.set(viewID + '_notes', currentNotes);
124+
Lockr.set(viewID + '_colors', currentColors);
125125
}
126126
127127
function reset() {
128-
Lockr.rm(viewID + "_notes")
129-
Lockr.rm(viewID + "_colors")
130-
currentColors = new Array(30).fill('')
131-
currentNotes = new Array(30).fill('')
128+
Lockr.rm(viewID + '_notes');
129+
Lockr.rm(viewID + '_colors');
130+
currentColors = new Array(30).fill('');
131+
currentNotes = new Array(30).fill('');
132+
}
133+
134+
function getVar(varName) {
135+
if (browser) {
136+
return window.getComputedStyle(document.documentElement).getPropertyValue(varName);
137+
} else {
138+
return "#FFFFFF"
139+
}
132140
}
133141
134142
$effect(() => {
135-
currentColors = Lockr.get(viewID + "_colors", new Array(30).fill(''))
136-
currentNotes = Lockr.get(viewID + "_notes", new Array(30).fill(''))
137-
})
143+
currentColors = Lockr.get(viewID + '_colors', new Array(30).fill(''));
144+
currentNotes = Lockr.get(viewID + '_notes', new Array(30).fill(''));
145+
});
138146
139147
$inspect(currentColors);
140148
</script>
@@ -188,7 +196,12 @@
188196
<br />
189197

190198
<label for="time-range" class="text-text">showing</label>
191-
<select name="time-range" id="time-range" class="bg-inactive text-text p-1 rounded-lg hover:bg-primary hover:text-inactive transition-all duration-300" bind:value={timerange}>
199+
<select
200+
name="time-range"
201+
id="time-range"
202+
class="bg-inactive text-text hover:bg-primary hover:text-inactive rounded-lg p-1 transition-all duration-300"
203+
bind:value={timerange}
204+
>
192205
<option value="hour">this hour</option>
193206
<option value="day">this day</option>
194207
<option value="week">this week</option>
@@ -197,7 +210,12 @@
197210
</select>
198211

199212
<label for="dot-is" class="text-text">with each dot being</label>
200-
<select name="dot-is" id="dot-is" class="bg-inactive text-text p-1 rounded-lg hover:bg-primary hover:text-inactive transition-all duration-300" bind:value={unit}>
213+
<select
214+
name="dot-is"
215+
id="dot-is"
216+
class="bg-inactive text-text hover:bg-primary hover:text-inactive rounded-lg p-1 transition-all duration-300"
217+
bind:value={unit}
218+
>
201219
<option value="min">a minute</option>
202220
<option value="hour">an hour</option>
203221
<option value="day">a day</option>
@@ -207,7 +225,12 @@
207225
</select>
208226

209227
<label for="cols" class="text-text">and each row representing</label>
210-
<select name="cols" id="dot-is" class="bg-inactive text-text p-1 rounded-lg hover:bg-primary hover:text-inactive transition-all duration-300" bind:value={colsName}>
228+
<select
229+
name="cols"
230+
id="dot-is"
231+
class="bg-inactive text-text hover:bg-primary hover:text-inactive rounded-lg p-1 transition-all duration-300"
232+
bind:value={colsName}
233+
>
211234
<option value="hour">an hour</option>
212235
<option value="day">a day</option>
213236
<option value="week">a week</option>
@@ -217,6 +240,51 @@
217240

218241
<br />
219242

220-
<button class="bg-inactive text-text mt-2 mr-2 px-3 rounded-lg py-1 hover:bg-primary hover:text-inactive transition-all duration-300 " onclick={save}>save notes and colors to this view</button>
221-
<button class="bg-inactive text-text mt-2 mr-2 px-3 rounded-lg py-1 hover:bg-primary hover:text-inactive transition-all duration-300 " onclick={reset}>reset saved data for this view</button>
243+
<button
244+
class="bg-inactive text-text hover:bg-primary hover:text-inactive mt-2 mr-2 rounded-lg px-3 py-1 transition-all duration-300"
245+
onclick={save}>save notes and colors to this view</button
246+
>
247+
<button
248+
class="bg-inactive text-text hover:bg-primary hover:text-inactive mt-2 mr-2 rounded-lg px-3 py-1 transition-all duration-300"
249+
onclick={reset}>reset saved data for this view</button
250+
>
251+
252+
<br />
253+
254+
<button
255+
class="bg-inactive text-text hover:bg-primary hover:text-inactive mt-2 mr-2 rounded-lg px-3 py-1 transition-all duration-300"
256+
popovertarget="theming-menu">open theming menu</button
257+
>
258+
259+
<div
260+
popover
261+
class="bg-bg border-text absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 flex-row items-center gap-3 rounded-xl border-1 p-4 transition-all backdrop:backdrop-blur-sm open:flex overflow-visible"
262+
id="theming-menu"
263+
>
264+
<div class="picker flex flex-col gap-3 *:hover:font-extrabold *:transition-all *:duration-175">
265+
<ColorPicker hex={getVar("--bg-color")} label="Background" onInput={(event) => {document.querySelector(':root').style.setProperty('--bg-color', event.hex)}}/>
266+
<ColorPicker hex={getVar("--inactive-color")} label="Inactive" onInput={(event) => {document.querySelector(':root').style.setProperty('--inactive-color', event.hex)}}/>
267+
<ColorPicker hex={getVar("--active-color")} label="Active" onInput={(event) => {document.querySelector(':root').style.setProperty('--active-color', event.hex)}}/>
268+
<ColorPicker hex={getVar("--red-color")} label="Red" onInput={(event) => {document.querySelector(':root').style.setProperty('--red-color', event.hex)}}/>
269+
<ColorPicker hex={getVar("--yellow-color")} label="Yellow" onInput={(event) => {document.querySelector(':root').style.setProperty('--yellow-color', event.hex)}}/>
270+
<ColorPicker hex={getVar("--green-color")} label="Green" onInput={(event) => {document.querySelector(':root').style.setProperty('--green-color', event.hex)}}/>
271+
<ColorPicker hex={getVar("--blue-color")} label="Blue" onInput={(event) => {document.querySelector(':root').style.setProperty('--blue-color', event.hex)}}/>
272+
273+
</div>
274+
275+
</div>
222276
</div>
277+
278+
<style>
279+
.picker {
280+
--cp-bg-color: var(--bg-color);
281+
--cp-border-color: var(--text-color);
282+
--cp-text-color: var(--text-color);
283+
--cp-input-color: var(--inactive-color);
284+
--cp-button-hover-color: var(--active-color);
285+
--slider-width: 20px;
286+
--picker-indicator-size: 15px;
287+
--focus-color: var(--active-color);
288+
--picker-z-index: 100
289+
}
290+
</style>

0 commit comments

Comments
 (0)