1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-04 16:09:59 +00:00

refactor: button creation with v-for to remove redundancy (#2020)

This commit is contained in:
Phojie Rengel 2023-04-28 15:42:23 +08:00 committed by GitHub
parent 5c3b8be055
commit 5dc136372b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,36 +6,38 @@ const colorMode = useColorMode()
function setColorMode(mode: ColorMode) {
colorMode.preference = mode
}
const modes = [
{
icon: 'i-ri-moon-line',
label: 'settings.interface.dark_mode',
mode: 'dark',
},
{
icon: 'i-ri-sun-line',
label: 'settings.interface.light_mode',
mode: 'light',
},
{
icon: 'i-ri-computer-line',
label: 'settings.interface.system_mode',
mode: 'system',
},
] as const
</script>
<template>
<div flex="~ gap4 wrap" w-full>
<button
v-for="{ icon, label, mode } in modes"
:key="mode"
btn-text flex-1 flex="~ gap-1 center" p4 border="~ base rounded" bg-base ws-nowrap
:tabindex="colorMode.preference === 'dark' ? 0 : -1"
:class="colorMode.preference === 'dark' ? 'pointer-events-none' : 'filter-saturate-0'"
@click="setColorMode('dark')"
:tabindex="colorMode.preference === mode ? 0 : -1"
:class="colorMode.preference === mode ? 'pointer-events-none' : 'filter-saturate-0'"
@click="setColorMode(mode)"
>
<div i-ri:moon-line />
{{ $t('settings.interface.dark_mode') }}
</button>
<button
btn-text flex-1 flex="~ gap-1 center" p4 border="~ base rounded" bg-base ws-nowrap
:tabindex="colorMode.preference === 'light' ? 0 : -1"
:class="colorMode.preference === 'light' ? 'pointer-events-none' : 'filter-saturate-0'"
@click="setColorMode('light')"
>
<div i-ri:sun-line />
{{ $t('settings.interface.light_mode') }}
</button>
<button
btn-text flex-1 flex="~ gap-1 center" p4 border="~ base rounded" bg-base ws-nowrap
:tabindex="colorMode.preference === 'system' ? 0 : -1"
:class="colorMode.preference === 'system' ? 'pointer-events-none' : 'filter-saturate-0'"
@click="setColorMode('system')"
>
<div i-ri:computer-line />
{{ $t('settings.interface.system_mode') }}
<span :class="`${icon}`" />
{{ $t(label) }}
</button>
</div>
</template>