gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<script setup lang="ts">
import type { MenuRecordRaw } from '../../../../../base/typings/src';
 
import type { NormalMenuProps } from './normal-menu';
 
import { useNamespace } from '../../../../../composables/src';
import { VbenIcon } from '../../../../shadcn-ui/src';
 
interface Props extends NormalMenuProps {}
 
defineOptions({
  name: 'NormalMenu',
});
 
const props = withDefaults(defineProps<Props>(), {
  activePath: '',
  collapse: false,
  menus: () => [],
  theme: 'dark',
});
 
const emit = defineEmits<{
  enter: [MenuRecordRaw];
  select: [MenuRecordRaw];
}>();
 
const { b, e, is } = useNamespace('normal-menu');
 
function menuIcon(menu: MenuRecordRaw) {
  return props.activePath === menu.path
    ? menu.activeIcon || menu.icon
    : menu.icon;
}
</script>
 
<template>
  <ul
    :class="[
      theme,
      b(),
      is('collapse', collapse),
      is(theme, true),
      is('rounded', rounded),
    ]"
    class="relative"
  >
    <template v-for="menu in menus" :key="menu.path">
      <li
        :class="[e('item'), is('active', activePath === menu.path)]"
        @click="() => emit('select', menu)"
        @mouseenter="() => emit('enter', menu)"
      >
        <VbenIcon :class="e('icon')" :icon="menuIcon(menu)" fallback />
 
        <span :class="e('name')" class="truncate"> {{ menu.name }}</span>
      </li>
    </template>
  </ul>
</template>
<style scoped>
@reference "@vben/tailwind-config/theme";
 
.vben-normal-menu {
  --menu-item-margin-y: 4px;
  --menu-item-margin-x: 0px;
  --menu-item-padding-y: 9px;
  --menu-item-padding-x: 0px;
  --menu-item-radius: 0px;
 
  height: calc(100% - 4px);
}
 
.vben-normal-menu.is-rounded {
  --menu-item-radius: 6px;
  --menu-item-margin-x: 8px;
}
 
.vben-normal-menu.is-dark .vben-normal-menu__item {
  @apply text-foreground/80;
}
 
.vben-normal-menu.is-dark .vben-normal-menu__item:not(.is-active):hover {
  @apply text-foreground;
}
 
.vben-normal-menu.is-dark
  .vben-normal-menu__item.is-active
  .vben-normal-menu__name,
.vben-normal-menu.is-dark
  .vben-normal-menu__item.is-active
  .vben-normal-menu__icon {
  @apply text-foreground;
}
 
.vben-normal-menu.is-collapse .vben-normal-menu__name {
  width: 0;
  height: 0;
  margin-top: 0;
  overflow: hidden;
  opacity: 0;
}
 
.vben-normal-menu.is-collapse .vben-normal-menu__icon {
  font-size: calc(var(--font-size-base, 16px) * 1.25);
}
 
.vben-normal-menu__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
 
  /* max-width: 64px; */
 
  /* max-height: 64px; */
  padding: var(--menu-item-padding-y) var(--menu-item-padding-x);
  margin: var(--menu-item-margin-y) var(--menu-item-margin-x);
  color: hsl(var(--foreground) / 90%);
  cursor: pointer;
  border-radius: var(--menu-item-radius);
  transition:
    background 0.15s ease,
    padding 0.15s ease,
    border-color 0.15s ease;
}
 
.vben-normal-menu__item.is-active {
  @apply bg-primary text-primary dark:bg-accent;
}
 
.vben-normal-menu__item.is-active .vben-normal-menu__name,
.vben-normal-menu__item.is-active .vben-normal-menu__icon {
  @apply text-primary-foreground font-semibold;
}
 
.vben-normal-menu__item:not(.is-active):hover {
  @apply bg-heavy text-primary dark:bg-accent dark:text-foreground;
}
 
.vben-normal-menu__item:hover .vben-normal-menu__icon {
  transform: scale(1.2);
}
 
.vben-normal-menu__icon {
  @apply max-h-5;
 
  font-size: calc(var(--font-size-base, 16px) * 1.25);
  transition: all 0.25s ease;
}
 
.vben-normal-menu__name {
  @apply mt-2;
 
  width: 100%;
  margin-bottom: 0;
  font-size: calc(var(--font-size-base, 16px) * 0.75);
  font-weight: 400;
  text-align: center;
  transition: all 0.25s ease;
}
</style>