ruoyi-plus-soybean/src/components/common/theme-schema-switch.vue

57 lines
1.1 KiB
Vue
Raw Normal View History

2023-11-17 08:45:00 +08:00
<script setup lang="ts">
import { computed } from 'vue';
import type { PopoverPlacement } from 'naive-ui';
import { $t } from '@/locales';
defineOptions({ name: 'ThemeSchemaSwitch' });
2023-12-14 21:45:29 +08:00
const props = withDefaults(defineProps<Props>(), {
showTooltip: true,
tooltipPlacement: 'bottom'
});
const emit = defineEmits<Emits>();
2023-11-17 08:45:00 +08:00
interface Props {
2023-12-14 21:45:29 +08:00
/** Theme schema */
2023-11-17 08:45:00 +08:00
themeSchema: UnionKey.ThemeScheme;
2023-12-14 21:45:29 +08:00
/** Show tooltip */
2023-11-17 08:45:00 +08:00
showTooltip?: boolean;
2023-12-14 21:45:29 +08:00
/** Tooltip placement */
2023-11-17 08:45:00 +08:00
tooltipPlacement?: PopoverPlacement;
}
interface Emits {
(e: 'switch'): void;
}
function handleSwitch() {
emit('switch');
}
const icons: Record<UnionKey.ThemeScheme, string> = {
light: 'material-symbols:sunny',
dark: 'material-symbols:nightlight-rounded',
auto: 'material-symbols:hdr-auto'
};
const icon = computed(() => icons[props.themeSchema]);
const tooltipContent = computed(() => {
if (!props.showTooltip) return '';
return $t('icon.themeSchema');
});
</script>
<template>
<ButtonIcon
:icon="icon"
:tooltip-content="tooltipContent"
:tooltip-placement="tooltipPlacement"
@click="handleSwitch"
/>
</template>
<style scoped></style>