ruoyi-plus-soybean/src/components/common/menu-toggler.vue

45 lines
997 B
Vue
Raw Normal View History

2023-11-17 08:45:00 +08:00
<script lang="ts" setup>
import { computed } from 'vue';
2023-12-14 21:45:29 +08:00
import { $t } from '@/locales';
2023-11-17 08:45:00 +08:00
defineOptions({ name: 'MenuToggler' });
2023-12-14 21:45:29 +08:00
const props = defineProps<Props>();
2023-11-17 08:45:00 +08:00
interface Props {
2023-12-14 21:45:29 +08:00
/** Show collapsed icon */
2023-11-17 08:45:00 +08:00
collapsed?: boolean;
2023-12-14 21:45:29 +08:00
/** Arrow style icon */
2023-11-17 08:45:00 +08:00
arrowIcon?: boolean;
}
type NumberBool = 0 | 1;
const icon = computed(() => {
const icons: Record<NumberBool, Record<NumberBool, string>> = {
0: {
0: 'line-md:menu-fold-left',
1: 'line-md:menu-fold-right'
},
1: {
0: 'ph-caret-double-left-bold',
1: 'ph-caret-double-right-bold'
}
};
const arrowIcon = Number(props.arrowIcon || false) as NumberBool;
const collapsed = Number(props.collapsed || false) as NumberBool;
return icons[arrowIcon][collapsed];
});
</script>
<template>
<ButtonIcon :tooltip-content="collapsed ? $t('icon.expand') : $t('icon.collapse')" tooltip-placement="bottom-start">
<SvgIcon :icon="icon" />
</ButtonIcon>
</template>
<style scoped></style>