-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathAccentColorPicker.vue
More file actions
54 lines (51 loc) · 1.96 KB
/
AccentColorPicker.vue
File metadata and controls
54 lines (51 loc) · 1.96 KB
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
<script setup lang="ts">
import { useAccentColor } from '~/composables/useSettings'
const { accentColors, selectedAccentColor, setAccentColor } = useAccentColor()
onPrehydrate(el => {
const settings = JSON.parse(localStorage.getItem('npmx-settings') || '{}')
const id = settings.accentColorId
if (id) {
const input = el.querySelector<HTMLInputElement>(`input[value="${id}"]`)
if (input) {
input.checked = true
}
}
})
</script>
<template>
<fieldset
class="flex items-center gap-4 has-[input:focus-visible]:(outline-solid outline-accent/70 outline-offset-4) rounded-xl w-fit"
>
<legend class="sr-only">{{ $t('settings.accent_colors') }}</legend>
<label
v-for="color in accentColors"
:key="color.id"
class="size-6 rounded-full transition-transform duration-150 motion-safe:hover:scale-110 cursor-pointer has-[:checked]:(ring-2 ring-fg ring-offset-2 ring-offset-bg-subtle) has-[:focus-visible]:(ring-2 ring-fg ring-offset-2 ring-offset-bg-subtle)"
:style="{ backgroundColor: `var(--swatch-${color.id})` }"
>
<input
type="radio"
name="accent-color"
class="sr-only"
:value="color.id"
:checked="selectedAccentColor === color.id"
:aria-label="color.name"
@change="setAccentColor(color.id)"
/>
</label>
<label
class="size-6 rounded-full transition-transform duration-150 motion-safe:hover:scale-110 cursor-pointer has-[:checked]:(ring-2 ring-fg ring-offset-2 ring-offset-bg-subtle) has-[:focus-visible]:(ring-2 ring-fg ring-offset-2 ring-offset-bg-subtle) flex items-center justify-center bg-fg"
>
<input
type="radio"
name="accent-color"
class="sr-only"
value=""
:checked="selectedAccentColor === null"
:aria-label="$t('settings.clear_accent')"
@change="setAccentColor(null)"
/>
<span class="i-carbon-error size-4 text-bg" aria-hidden="true" />
</label>
</fieldset>
</template>