docs/.vitepress/theme/components/settings/AccentBackground.vue
127 lines · 3888 bytes
1<script setup lang="ts">
2import {
3 NuInputHighlight,
4 NuInputHorizontalRadioGroup,
5 NuVerticalTransition
6} from '@nolebase/ui'
7import { useStorage } from '@vueuse/core'
8import { computed, ref } from 'vue'
9
10import MenuHelp from './MenuHelp.vue'
11import MenuTitle from './MenuTitle.vue'
12
13import { AccentBgStorageKey, AccentBgStrengthStorageKey } from '../../constants'
14
15const menuTitleElementRef = ref<HTMLDivElement>()
16const isMenuHelpPoppedUp = ref(false)
17const intensityTitleElementRef = ref<HTMLDivElement>()
18const isIntensityHelpPoppedUp = ref(false)
19
20const accentBg = useStorage(AccentBgStorageKey, false)
21const strengthStorageValue = useStorage(AccentBgStrengthStorageKey, 60)
22
23const strengthValue = computed({
24 get: () => {
25 const parsed = Number.parseInt(String(strengthStorageValue.value))
26 if (Number.isNaN(parsed)) return 60
27 // Snap stored values to the nearest preset.
28 return Math.round(Math.min(100, Math.max(20, parsed)) / 20) * 20
29 },
30 set: (val) => {
31 strengthStorageValue.value = val
32 }
33})
34
35const fieldOptions = computed(() => [
36 {
37 value: true,
38 title: 'On',
39 ariaLabel: 'On',
40 text: 'ON',
41 name: 'Accent Background Toggle Switch'
42 },
43 {
44 value: false,
45 title: 'Off',
46 ariaLabel: 'Off',
47 text: 'OFF',
48 name: 'Accent Background Toggle Switch'
49 }
50])
51
52const strengthOptions = computed(() =>
53 [20, 40, 60, 80, 100].map((v) => ({
54 value: v,
55 title: `${v}%`,
56 ariaLabel: `${v}%`,
57 text: `${v}`,
58 name: 'Accent Background Strength'
59 }))
60)
61</script>
62
63<template>
64 <div space-y-2 select-none role="radiogroup">
65 <div ref="menuTitleElementRef" relative flex items-center>
66 <MenuTitle
67 title="Accent Background"
68 aria-label="Accent Background"
69 flex="1"
70 pr-4
71 >
72 <template #icon>
73 <span i-lucide:paint-roller mr-1 aria-hidden="true" />
74 </template>
75 </MenuTitle>
76 <MenuHelp
77 v-model:is-popped-up="isMenuHelpPoppedUp"
78 :menu-title-element-ref="menuTitleElementRef"
79 >
80 <h4 text-md mb-1 font-semibold>Accent Background</h4>
81 <p text="sm" mb-2 max-w-100>
82 Tints backgrounds, surfaces, and text with your accent color.
83 </p>
84 </MenuHelp>
85 </div>
86 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
87 <NuInputHorizontalRadioGroup
88 v-model="accentBg"
89 bg="$vp-nolebase-enhanced-readabilities-menu-background-color"
90 text="sm $vp-nolebase-enhanced-readabilities-menu-text-color"
91 :options="fieldOptions"
92 />
93 </NuInputHighlight>
94 <NuVerticalTransition :duration="200">
95 <div v-show="accentBg" space-y-2 role="radiogroup">
96 <div ref="intensityTitleElementRef" relative flex items-center>
97 <MenuTitle title="Intensity" aria-label="Intensity" flex="1" pr-4>
98 <template #icon>
99 <span
100 i-lucide:chart-no-axes-column-increasing
101 mr-1
102 aria-hidden="true"
103 />
104 </template>
105 </MenuTitle>
106 <MenuHelp
107 v-model:is-popped-up="isIntensityHelpPoppedUp"
108 :menu-title-element-ref="intensityTitleElementRef"
109 >
110 <h4 text-md mb-1 font-semibold>Intensity</h4>
111 <p text="sm" mb-2 max-w-100>
112 How strongly the accent color tints the background.
113 </p>
114 </MenuHelp>
115 </div>
116 <NuInputHighlight :active="isIntensityHelpPoppedUp" class="rounded-md">
117 <NuInputHorizontalRadioGroup
118 v-model="strengthValue"
119 bg="$vp-nolebase-enhanced-readabilities-menu-background-color"
120 text="sm $vp-nolebase-enhanced-readabilities-menu-text-color"
121 :options="strengthOptions"
122 />
123 </NuInputHighlight>
124 </div>
125 </NuVerticalTransition>
126 </div>
127</template>