Files
syops/frontend/src/components/ThemeToggleButton.vue
T
2026-05-27 16:06:48 +08:00

34 lines
1.1 KiB
Vue

<script setup lang="ts">
import { computed } from 'vue';
import { Sun, Moon } from 'lucide-vue-next';
import { useTheme } from '../composables/useTheme';
import { useI18n } from 'vue-i18n';
const props = withDefaults(defineProps<{ floating?: boolean }>(), {
floating: false,
});
const { t } = useI18n();
const { appliedTheme, toggleLightDark } = useTheme();
const isDarkTheme = computed(() => appliedTheme.value === 'dark');
const buttonClass = computed(() =>
props.floating
? 'theme-toggle-btn theme-toggle-btn--floating'
: 'theme-toggle-btn theme-toggle-btn--inline'
);
</script>
<template>
<button
type="button"
:class="buttonClass"
:title="isDarkTheme ? (t('theme.switchToLight') || 'Switch to light mode') : (t('theme.switchToDark') || 'Switch to dark mode')"
:aria-label="isDarkTheme ? (t('theme.switchToLight') || 'Switch to light mode') : (t('theme.switchToDark') || 'Switch to dark mode')"
@click="toggleLightDark"
>
<Sun v-if="isDarkTheme" class="w-4 h-4 md:w-5 md:h-5" />
<Moon v-else class="w-4 h-4 md:w-5 md:h-5" />
</button>
</template>