MCPcopy Index your code
hub / github.com/npmx-dev/npmx.dev / useAccentColor

Function useAccentColor

app/composables/useSettings.ts:153–193  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

151 * Composable for managing accent color.
152 */
153export function useAccentColor() {
154 const { settings } = useSettings()
155 const colorMode = useColorMode()
156 const { t } = useI18n()
157
158 const accentColorLabels = computed<Record<AccentColorId, string>>(() => ({
159 sky: t('settings.accent_colors.sky'),
160 coral: t('settings.accent_colors.coral'),
161 amber: t('settings.accent_colors.amber'),
162 emerald: t('settings.accent_colors.emerald'),
163 violet: t('settings.accent_colors.violet'),
164 magenta: t('settings.accent_colors.magenta'),
165 neutral: t('settings.clear_accent'),
166 }))
167
168 const accentColors = computed(() => {
169 const isDark = colorMode.value === 'dark'
170 const colors = isDark ? ACCENT_COLORS.dark : ACCENT_COLORS.light
171
172 return Object.entries(colors).map(([id, value]) => ({
173 id: id as AccentColorId,
174 label: accentColorLabels.value[id as AccentColorId],
175 value,
176 }))
177 })
178
179 function setAccentColor(id: AccentColorId | null) {
180 if (id) {
181 document.documentElement.style.setProperty('--accent-color', `var(--swatch-${id})`)
182 } else {
183 document.documentElement.style.removeProperty('--accent-color')
184 }
185 settings.value.accentColorId = id
186 }
187
188 return {
189 accentColors,
190 selectedAccentColor: computed(() => settings.value.accentColorId),
191 setAccentColor,
192 }
193}
194
195/**
196 * Composable for managing the search provider setting.

Callers 1

Calls 1

useSettingsFunction · 0.85

Tested by

no test coverage detected