Publish Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Canceled after 0s
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Canceled after 0s
Publish Docker image / merge (push) Canceled after 0s
ci / ci (22, ubuntu-latest) (push) Canceled after 0s
GitHub Release / release (push) Canceled after 0s
Fix TypeScript errors blocking CI, split Docker publish into native amd64/arm64 jobs with manifest merge, and add npm cache mounts.
101 lines
2.4 KiB
TypeScript
101 lines
2.4 KiB
TypeScript
import type { DropdownMenuItem } from '@nuxt/ui'
|
|
|
|
export function useAppearanceMenus() {
|
|
const colorMode = useColorMode()
|
|
const { locale, locales, setLocale, t } = useI18n()
|
|
|
|
const themeIcon = computed(() => {
|
|
if (colorMode.preference === 'system') return 'i-lucide-monitor'
|
|
return colorMode.preference === 'dark' ? 'i-lucide-moon' : 'i-lucide-sun'
|
|
})
|
|
|
|
const localeMenuItems = computed<DropdownMenuItem[][]>(() => [[
|
|
...locales.value.map(loc => ({
|
|
label: t(`locale.${loc.code}`),
|
|
icon: 'i-lucide-languages',
|
|
type: 'checkbox' as const,
|
|
checked: locale.value === loc.code,
|
|
onUpdateChecked(checked: boolean) {
|
|
if (checked && typeof loc.code === 'string') {
|
|
void setLocale(loc.code)
|
|
}
|
|
}
|
|
}))
|
|
]])
|
|
|
|
const themeMenuItems = computed<DropdownMenuItem[][]>(() => [[
|
|
{
|
|
label: t('theme.light'),
|
|
icon: 'i-lucide-sun',
|
|
type: 'checkbox',
|
|
checked: colorMode.preference === 'light',
|
|
onUpdateChecked(checked: boolean) {
|
|
if (checked) colorMode.preference = 'light'
|
|
}
|
|
},
|
|
{
|
|
label: t('theme.dark'),
|
|
icon: 'i-lucide-moon',
|
|
type: 'checkbox',
|
|
checked: colorMode.preference === 'dark',
|
|
onUpdateChecked(checked: boolean) {
|
|
if (checked) colorMode.preference = 'dark'
|
|
}
|
|
},
|
|
{
|
|
label: t('theme.system'),
|
|
icon: 'i-lucide-monitor',
|
|
type: 'checkbox',
|
|
checked: colorMode.preference === 'system',
|
|
onUpdateChecked(checked: boolean) {
|
|
if (checked) colorMode.preference = 'system'
|
|
}
|
|
}
|
|
]])
|
|
|
|
const themeOptions = computed(() => [
|
|
{
|
|
value: 'light' as const,
|
|
label: t('theme.light'),
|
|
icon: 'i-lucide-sun'
|
|
},
|
|
{
|
|
value: 'dark' as const,
|
|
label: t('theme.dark'),
|
|
icon: 'i-lucide-moon'
|
|
},
|
|
{
|
|
value: 'system' as const,
|
|
label: t('theme.system'),
|
|
icon: 'i-lucide-monitor'
|
|
}
|
|
])
|
|
|
|
const localeOptions = computed(() =>
|
|
locales.value.map(loc => ({
|
|
code: String(loc.code),
|
|
label: t(`locale.${loc.code}`)
|
|
}))
|
|
)
|
|
|
|
function setThemePreference(value: 'light' | 'dark' | 'system') {
|
|
colorMode.preference = value
|
|
}
|
|
|
|
async function setLocalePreference(code: string) {
|
|
if (code === 'zh-CN' || code === 'en') {
|
|
await setLocale(code)
|
|
}
|
|
}
|
|
|
|
return {
|
|
themeIcon,
|
|
localeMenuItems,
|
|
themeMenuItems,
|
|
localeOptions,
|
|
themeOptions,
|
|
setThemePreference,
|
|
setLocalePreference
|
|
}
|
|
}
|