| @@ -1,6 +1,8 @@ |
| 1 | <script setup lang="ts"> |
1 | <script setup lang="ts"> |
| 2 | import { useData } from 'vitepress' |
2 | import { useData } from 'vitepress' |
| |
3 | import { NuVerticalTransition } from '@nolebase/ui' |
| 3 | import { useStorage } from '@vueuse/core' |
4 | import { useStorage } from '@vueuse/core' |
| |
5 | import { computed, onMounted, onUnmounted, ref } from 'vue' |
| 4 | |
6 | |
| 5 | import { AccentColorStorageKey } from '../../constants' |
7 | import { AccentColorStorageKey } from '../../constants' |
| 6 | import MenuTitle from './MenuTitle.vue' |
8 | import MenuTitle from './MenuTitle.vue' |
| @@ -57,44 +59,147 @@ const accentOptions = [ |
| 57 | ] |
59 | ] |
| 58 | |
60 | |
| 59 | const accentColor = useStorage(AccentColorStorageKey, 'ayanami') |
61 | const accentColor = useStorage(AccentColorStorageKey, 'ayanami') |
| |
62 | |
| |
63 | const open = ref(false) |
| |
64 | const rootRef = ref<HTMLDivElement>() |
| |
65 | |
| |
66 | const selectedOption = computed( |
| |
67 | () => accentOptions.find((o) => o.key === accentColor.value) ?? accentOptions[0] |
| |
68 | ) |
| |
69 | |
| |
70 | function shadesFor(option: typeof accentOptions[number]) { |
| |
71 | return 'lightShades' in option && !isDark.value ? option.lightShades! : option.shades |
| |
72 | } |
| |
73 | |
| |
74 | function select(key: string) { |
| |
75 | accentColor.value = key |
| |
76 | open.value = false |
| |
77 | } |
| |
78 | |
| |
79 | function onDocClick(e: MouseEvent) { |
| |
80 | if (rootRef.value && !rootRef.value.contains(e.target as Node)) { |
| |
81 | open.value = false |
| |
82 | } |
| |
83 | } |
| |
84 | |
| |
85 | onMounted(() => document.addEventListener('click', onDocClick, true)) |
| |
86 | onUnmounted(() => document.removeEventListener('click', onDocClick, true)) |
| 60 | </script> |
87 | </script> |
| 61 | |
88 | |
| 62 | <template> |
89 | <template> |
| 63 | <div> |
90 | <div ref="rootRef" class="accent-color"> |
| 64 | <MenuTitle title="Accent Color" aria-label="Accent Color" mb-2> |
91 | <MenuTitle title="Accent Color" aria-label="Accent Color" mb-2> |
| 65 | <template #icon> |
92 | <template #icon> |
| 66 | <span i-lucide:swatch-book mr-1 aria-hidden="true" /> |
93 | <span i-lucide:swatch-book mr-1 aria-hidden="true" /> |
| 67 | </template> |
94 | </template> |
| 68 | </MenuTitle> |
95 | </MenuTitle> |
| 69 | <div class="accent-list"> |
96 | |
| |
97 | <div class="accent-select" :class="{ 'accent-select--open': open }"> |
| 70 | <button |
98 | <button |
| 71 | v-for="option in accentOptions" |
99 | type="button" |
| 72 | :key="option.key" |
100 | class="accent-trigger" |
| 73 | class="accent-btn" |
101 | aria-haspopup="listbox" |
| 74 | :class="{ 'accent-btn--selected': accentColor === option.key }" |
102 | :aria-expanded="open" |
| 75 | :aria-pressed="accentColor === option.key" |
103 | :aria-label="`Accent Color: ${selectedOption.label}`" |
| 76 | :aria-label="option.label" |
104 | @click="open = !open" |
| 77 | @click="accentColor = option.key" |
| |
| 78 | > |
105 | > |
| 79 | <span class="accent-label">{{ option.label }}</span> |
106 | <span class="accent-label">{{ selectedOption.label }}</span> |
| 80 | <span class="accent-shades"> |
107 | <span class="accent-shades"> |
| 81 | <span |
108 | <span |
| 82 | v-for="(shade, i) in ('lightShades' in option && !isDark ? option.lightShades : option.shades)" |
109 | v-for="(shade, i) in shadesFor(selectedOption)" |
| 83 | :key="i" |
110 | :key="i" |
| 84 | class="accent-shade" |
111 | class="accent-shade" |
| 85 | :style="{ backgroundColor: shade }" |
112 | :style="{ backgroundColor: shade }" |
| 86 | /> |
113 | /> |
| 87 | </span> |
114 | </span> |
| |
115 | <span |
| |
116 | class="accent-chevron i-lucide:chevron-down" |
| |
117 | :class="{ 'accent-chevron--open': open }" |
| |
118 | aria-hidden="true" |
| |
119 | /> |
| 88 | </button> |
120 | </button> |
| |
121 | |
| |
122 | <NuVerticalTransition :duration="200"> |
| |
123 | <div v-show="open" class="accent-options" role="listbox"> |
| |
124 | <button |
| |
125 | v-for="option in accentOptions" |
| |
126 | :key="option.key" |
| |
127 | type="button" |
| |
128 | role="option" |
| |
129 | class="accent-btn" |
| |
130 | :class="{ 'accent-btn--selected': accentColor === option.key }" |
| |
131 | :aria-selected="accentColor === option.key" |
| |
132 | :aria-label="option.label" |
| |
133 | @click="select(option.key)" |
| |
134 | > |
| |
135 | <span class="accent-label">{{ option.label }}</span> |
| |
136 | <span class="accent-shades"> |
| |
137 | <span |
| |
138 | v-for="(shade, i) in shadesFor(option)" |
| |
139 | :key="i" |
| |
140 | class="accent-shade" |
| |
141 | :style="{ backgroundColor: shade }" |
| |
142 | /> |
| |
143 | </span> |
| |
144 | </button> |
| |
145 | </div> |
| |
146 | </NuVerticalTransition> |
| 89 | </div> |
147 | </div> |
| 90 | </div> |
148 | </div> |
| 91 | </template> |
149 | </template> |
| 92 | |
150 | |
| 93 | <style scoped> |
151 | <style scoped> |
| 94 | .accent-list { |
152 | .accent-select { |
| |
153 | position: relative; |
| |
154 | } |
| |
155 | |
| |
156 | .accent-trigger { |
| |
157 | display: flex; |
| |
158 | align-items: center; |
| |
159 | gap: 8px; |
| |
160 | width: 100%; |
| |
161 | padding: 7px 10px; |
| |
162 | border-radius: 8px; |
| |
163 | border: 1px solid var(--vp-c-divider); |
| |
164 | background: var(--wk-c-menu-bg); |
| |
165 | color: var(--vp-c-text-1); |
| |
166 | font-size: 13px; |
| |
167 | cursor: pointer; |
| |
168 | transition: border-color 0.15s, background-color 0.15s; |
| |
169 | } |
| |
170 | |
| |
171 | .accent-trigger:hover { |
| |
172 | border-color: var(--vp-c-brand-1); |
| |
173 | } |
| |
174 | |
| |
175 | .accent-select--open .accent-trigger { |
| |
176 | border-color: var(--vp-c-brand-1); |
| |
177 | } |
| |
178 | |
| |
179 | .accent-chevron { |
| |
180 | flex-shrink: 0; |
| |
181 | width: 16px; |
| |
182 | height: 16px; |
| |
183 | color: var(--vp-c-text-2); |
| |
184 | transition: transform 0.2s ease; |
| |
185 | } |
| |
186 | |
| |
187 | .accent-chevron--open { |
| |
188 | transform: rotate(180deg); |
| |
189 | } |
| |
190 | |
| |
191 | .accent-options { |
| |
192 | margin-top: 6px; |
| |
193 | max-height: 240px; |
| |
194 | overflow-y: auto; |
| 95 | display: flex; |
195 | display: flex; |
| 96 | flex-direction: column; |
196 | flex-direction: column; |
| 97 | gap: 2px; |
197 | gap: 2px; |
| |
198 | padding: 4px; |
| |
199 | border-radius: 8px; |
| |
200 | border: 1px solid var(--vp-c-divider); |
| |
201 | background: var(--vp-c-bg-elv); |
| |
202 | box-shadow: var(--vp-shadow-2); |
| 98 | } |
203 | } |
| 99 | |
204 | |
| 100 | .accent-btn { |
205 | .accent-btn { |
| @@ -141,5 +246,4 @@ const accentColor = useStorage(AccentColorStorageKey, 'ayanami') |
| 141 | width: 18px; |
246 | width: 18px; |
| 142 | height: 100%; |
247 | height: 100%; |
| 143 | } |
248 | } |
| 144 | |
| |
| 145 | </style> |
249 | </style> |