menu.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. <script lang="ts" setup>
  2. import type {
  3. MenuItemClicked,
  4. MenuItemRegistered,
  5. MenuProps,
  6. MenuProvider,
  7. } from '../interface';
  8. import {
  9. computed,
  10. nextTick,
  11. reactive,
  12. ref,
  13. toRef,
  14. useSlots,
  15. type VNodeArrayChildren,
  16. watch,
  17. watchEffect,
  18. } from 'vue';
  19. import { useNamespace } from '@vben-core/composables';
  20. import { Ellipsis } from '@vben-core/icons';
  21. import { isHttpUrl } from '@vben-core/shared';
  22. import { useResizeObserver, UseResizeObserverReturn } from '@vueuse/core';
  23. import {
  24. createMenuContext,
  25. createSubMenuContext,
  26. useMenuStyle,
  27. } from '../hooks';
  28. import { flattedChildren } from '../utils';
  29. import SubMenu from './sub-menu.vue';
  30. interface Props extends MenuProps {}
  31. defineOptions({ name: 'Menu' });
  32. const props = withDefaults(defineProps<Props>(), {
  33. accordion: true,
  34. collapse: false,
  35. mode: 'vertical',
  36. rounded: true,
  37. theme: 'dark',
  38. });
  39. const emit = defineEmits<{
  40. close: [string, string[]];
  41. open: [string, string[]];
  42. select: [string, string[]];
  43. }>();
  44. const { b, is } = useNamespace('menu');
  45. const menuStyle = useMenuStyle();
  46. const slots = useSlots();
  47. const menu = ref<HTMLUListElement>();
  48. const sliceIndex = ref(-1);
  49. const openedMenus = ref<MenuProvider['openedMenus']>(
  50. props.defaultOpeneds && !props.collapse ? [...props.defaultOpeneds] : [],
  51. );
  52. const activePath = ref<MenuProvider['activePath']>(props.defaultActive);
  53. const items = ref<MenuProvider['items']>({});
  54. const subMenus = ref<MenuProvider['subMenus']>({});
  55. const mouseInChild = ref(false);
  56. const defaultSlots: VNodeArrayChildren = slots.default?.() ?? [];
  57. const isMenuPopup = computed<MenuProvider['isMenuPopup']>(() => {
  58. return (
  59. props.mode === 'horizontal' || (props.mode === 'vertical' && props.collapse)
  60. );
  61. });
  62. const getSlot = computed(() => {
  63. const originalSlot = flattedChildren(defaultSlots) as VNodeArrayChildren;
  64. const slotDefault =
  65. sliceIndex.value === -1
  66. ? originalSlot
  67. : originalSlot.slice(0, sliceIndex.value);
  68. const slotMore =
  69. sliceIndex.value === -1 ? [] : originalSlot.slice(sliceIndex.value);
  70. return { showSlotMore: slotMore.length > 0, slotDefault, slotMore };
  71. });
  72. watch(
  73. () => props.collapse,
  74. (value) => {
  75. if (value) openedMenus.value = [];
  76. },
  77. );
  78. watch(items.value, initMenu);
  79. watch(
  80. () => props.defaultActive,
  81. (currentActive = '') => {
  82. if (!items.value[currentActive]) {
  83. activePath.value = '';
  84. }
  85. updateActiveName(currentActive);
  86. },
  87. );
  88. let resizeStopper: UseResizeObserverReturn['stop'];
  89. watchEffect(() => {
  90. if (props.mode === 'horizontal') {
  91. resizeStopper = useResizeObserver(menu, handleResize).stop;
  92. } else {
  93. resizeStopper?.();
  94. }
  95. });
  96. // 注入上下文
  97. createMenuContext(
  98. reactive({
  99. activePath,
  100. addMenuItem,
  101. addSubMenu,
  102. closeMenu,
  103. handleMenuItemClick,
  104. handleSubMenuClick,
  105. isMenuPopup,
  106. openedMenus,
  107. openMenu,
  108. props,
  109. removeMenuItem,
  110. removeSubMenu,
  111. subMenus,
  112. theme: toRef(props, 'theme'),
  113. items,
  114. }),
  115. );
  116. createSubMenuContext({
  117. addSubMenu,
  118. level: 1,
  119. mouseInChild,
  120. removeSubMenu,
  121. });
  122. function calcMenuItemWidth(menuItem: HTMLElement) {
  123. const computedStyle = getComputedStyle(menuItem);
  124. const marginLeft = Number.parseInt(computedStyle.marginLeft, 10);
  125. const marginRight = Number.parseInt(computedStyle.marginRight, 10);
  126. return menuItem.offsetWidth + marginLeft + marginRight || 0;
  127. }
  128. function calcSliceIndex() {
  129. if (!menu.value) {
  130. return -1;
  131. }
  132. const items = [...(menu.value?.childNodes ?? [])].filter(
  133. (item) =>
  134. // remove comment type node #12634
  135. item.nodeName !== '#comment' &&
  136. (item.nodeName !== '#text' || item.nodeValue),
  137. ) as HTMLElement[];
  138. const moreItemWidth = 46;
  139. const computedMenuStyle = getComputedStyle(menu?.value);
  140. const paddingLeft = Number.parseInt(computedMenuStyle.paddingLeft, 10);
  141. const paddingRight = Number.parseInt(computedMenuStyle.paddingRight, 10);
  142. const menuWidth = menu.value?.clientWidth - paddingLeft - paddingRight;
  143. let calcWidth = 0;
  144. let sliceIndex = 0;
  145. items.forEach((item, index) => {
  146. calcWidth += calcMenuItemWidth(item);
  147. if (calcWidth <= menuWidth - moreItemWidth) {
  148. sliceIndex = index + 1;
  149. }
  150. });
  151. return sliceIndex === items.length ? -1 : sliceIndex;
  152. }
  153. function debounce(fn: () => void, wait = 33.34) {
  154. let timer: null | ReturnType<typeof setTimeout>;
  155. return () => {
  156. timer && clearTimeout(timer);
  157. timer = setTimeout(() => {
  158. fn();
  159. }, wait);
  160. };
  161. }
  162. let isFirstTimeRender = true;
  163. function handleResize() {
  164. if (sliceIndex.value === calcSliceIndex()) {
  165. return;
  166. }
  167. const callback = () => {
  168. sliceIndex.value = -1;
  169. nextTick(() => {
  170. sliceIndex.value = calcSliceIndex();
  171. });
  172. };
  173. callback();
  174. // // execute callback directly when first time resize to avoid shaking
  175. isFirstTimeRender ? callback() : debounce(callback)();
  176. isFirstTimeRender = false;
  177. }
  178. function getActivePaths() {
  179. const activeItem = activePath.value && items.value[activePath.value];
  180. if (!activeItem || props.mode === 'horizontal' || props.collapse) {
  181. return [];
  182. }
  183. return activeItem.parentPaths;
  184. }
  185. // 默认展开菜单
  186. function initMenu() {
  187. const parentPaths = getActivePaths();
  188. // 展开该菜单项的路径上所有子菜单
  189. // expand all subMenus of the menu item
  190. parentPaths.forEach((path) => {
  191. const subMenu = subMenus.value[path];
  192. subMenu && openMenu(path, subMenu.parentPaths);
  193. });
  194. }
  195. function updateActiveName(val: string) {
  196. const itemsInData = items.value;
  197. const item =
  198. itemsInData[val] ||
  199. (activePath.value && itemsInData[activePath.value]) ||
  200. itemsInData[props.defaultActive || ''];
  201. activePath.value = item ? item.path : val;
  202. }
  203. function handleMenuItemClick(data: MenuItemClicked) {
  204. const { collapse, mode } = props;
  205. if (mode === 'horizontal' || collapse) {
  206. openedMenus.value = [];
  207. }
  208. const { parentPaths, path } = data;
  209. if (!path || !parentPaths) {
  210. return;
  211. }
  212. if (!isHttpUrl(path)) {
  213. activePath.value = path;
  214. }
  215. emit('select', path, parentPaths);
  216. }
  217. function handleSubMenuClick({ parentPaths, path }: MenuItemRegistered) {
  218. const isOpened = openedMenus.value.includes(path);
  219. if (isOpened) {
  220. closeMenu(path, parentPaths);
  221. } else {
  222. openMenu(path, parentPaths);
  223. }
  224. }
  225. function close(path: string) {
  226. const i = openedMenus.value.indexOf(path);
  227. if (i !== -1) {
  228. openedMenus.value.splice(i, 1);
  229. }
  230. }
  231. /**
  232. * 关闭、折叠菜单
  233. */
  234. function closeMenu(path: string, parentPaths: string[]) {
  235. if (props.accordion) {
  236. openedMenus.value = subMenus.value[path]?.parentPaths;
  237. }
  238. close(path);
  239. emit('close', path, parentPaths);
  240. }
  241. /**
  242. * 点击展开菜单
  243. */
  244. function openMenu(path: string, parentPaths: string[]) {
  245. if (openedMenus.value.includes(path)) {
  246. return;
  247. }
  248. // 手风琴模式菜单
  249. if (props.accordion) {
  250. const activeParentPaths = getActivePaths();
  251. if (activeParentPaths.includes(path)) {
  252. parentPaths = activeParentPaths;
  253. }
  254. openedMenus.value = openedMenus.value.filter((path: string) =>
  255. parentPaths.includes(path),
  256. );
  257. }
  258. openedMenus.value.push(path);
  259. emit('open', path, parentPaths);
  260. }
  261. function addMenuItem(item: MenuItemRegistered) {
  262. items.value[item.path] = item;
  263. }
  264. function addSubMenu(subMenu: MenuItemRegistered) {
  265. subMenus.value[subMenu.path] = subMenu;
  266. }
  267. function removeSubMenu(subMenu: MenuItemRegistered) {
  268. Reflect.deleteProperty(subMenus.value, subMenu.path);
  269. }
  270. function removeMenuItem(item: MenuItemRegistered) {
  271. Reflect.deleteProperty(items.value, item.path);
  272. }
  273. </script>
  274. <template>
  275. <ul
  276. ref="menu"
  277. :class="[
  278. theme,
  279. b(),
  280. is(mode, true),
  281. is(theme, true),
  282. is('rounded', rounded),
  283. is('collapse', collapse),
  284. ]"
  285. :style="menuStyle"
  286. role="menu"
  287. >
  288. <template v-if="mode === 'horizontal' && getSlot.showSlotMore">
  289. <template v-for="item in getSlot.slotDefault" :key="item.key">
  290. <component :is="item" />
  291. </template>
  292. <SubMenu is-sub-menu-more path="sub-menu-more">
  293. <template #title>
  294. <Ellipsis class="size-4" />
  295. </template>
  296. <template v-for="item in getSlot.slotMore" :key="item.key">
  297. <component :is="item" />
  298. </template>
  299. </SubMenu>
  300. </template>
  301. <template v-else>
  302. <slot></slot>
  303. </template>
  304. </ul>
  305. </template>
  306. <style lang="scss">
  307. $namespace: vben;
  308. @mixin menu-item-active {
  309. color: var(--menu-item-active-color);
  310. text-decoration: none;
  311. cursor: pointer;
  312. background: var(--menu-item-active-background-color);
  313. }
  314. @mixin menu-item {
  315. position: relative;
  316. display: flex;
  317. // gap: 12px;
  318. align-items: center;
  319. height: var(--menu-item-height);
  320. padding: var(--menu-item-padding-y) var(--menu-item-padding-x);
  321. margin: 0 var(--menu-item-margin-x) var(--menu-item-margin-y)
  322. var(--menu-item-margin-x);
  323. font-size: var(--menu-font-size);
  324. color: var(--menu-item-color);
  325. text-decoration: none;
  326. white-space: nowrap;
  327. list-style: none;
  328. cursor: pointer;
  329. background: var(--menu-item-background-color);
  330. border: none;
  331. border-radius: var(--menu-item-radius);
  332. transition:
  333. background 0.15s ease,
  334. color 0.15s ease,
  335. padding 0.15s ease,
  336. border-color 0.15s ease;
  337. &.is-disabled {
  338. cursor: not-allowed;
  339. background: none !important;
  340. opacity: 0.25;
  341. }
  342. .#{$namespace}-menu__icon {
  343. transition: transform 0.25s;
  344. }
  345. &:hover {
  346. .#{$namespace}-menu__icon {
  347. transform: scale(1.2);
  348. }
  349. }
  350. &:hover,
  351. &:focus {
  352. outline: none;
  353. }
  354. * {
  355. vertical-align: bottom;
  356. }
  357. }
  358. @mixin menu-title {
  359. max-width: var(--menu-title-width);
  360. overflow: hidden;
  361. text-overflow: ellipsis;
  362. white-space: nowrap;
  363. opacity: 1;
  364. }
  365. .#{$namespace}-menu__popup-container,
  366. .#{$namespace}-menu {
  367. --menu-title-width: 140px;
  368. --menu-item-icon-size: 16px;
  369. --menu-item-height: 38px;
  370. --menu-item-padding-y: 21px;
  371. --menu-item-padding-x: 12px;
  372. --menu-item-popup-padding-y: 20px;
  373. --menu-item-popup-padding-x: 12px;
  374. --menu-item-margin-y: 3px;
  375. --menu-item-margin-x: 0px;
  376. --menu-item-collapse-padding-y: 23.5px;
  377. --menu-item-collapse-padding-x: 0px;
  378. --menu-item-collapse-margin-y: 4px;
  379. --menu-item-collapse-margin-x: 0px;
  380. --menu-item-radius: 0px;
  381. --menu-item-indent: 16px;
  382. --menu-font-size: 14px;
  383. &.is-dark {
  384. --menu-background-color: hsl(var(--menu));
  385. // --menu-submenu-opened-background-color: hsl(var(--menu-opened-dark));
  386. --menu-item-background-color: var(--menu-background-color);
  387. --menu-item-color: hsl(var(--foreground) / 80%);
  388. --menu-item-hover-color: hsl(var(--accent-foreground));
  389. --menu-item-hover-background-color: hsl(var(--accent));
  390. --menu-item-active-color: hsl(var(--primary-foreground));
  391. --menu-item-active-background-color: hsl(var(--primary));
  392. --menu-submenu-hover-color: hsl(var(--foreground));
  393. --menu-submenu-hover-background-color: hsl(var(--accent));
  394. --menu-submenu-active-color: hsl(var(--foreground));
  395. --menu-submenu-active-background-color: transparent;
  396. --menu-submenu-background-color: var(--menu-background-color);
  397. }
  398. &.is-light {
  399. --menu-background-color: hsl(var(--menu));
  400. // --menu-submenu-opened-background-color: hsl(var(--menu-opened));
  401. --menu-item-background-color: var(--menu-background-color);
  402. --menu-item-color: hsl(var(--foreground));
  403. --menu-item-hover-color: var(--menu-item-color);
  404. --menu-item-hover-background-color: hsl(var(--accent));
  405. --menu-item-active-color: hsl(var(--primary));
  406. --menu-item-active-background-color: hsl(var(--primary) / 15%);
  407. --menu-submenu-hover-color: hsl(var(--primary));
  408. --menu-submenu-hover-background-color: hsl(var(--accent));
  409. --menu-submenu-active-color: hsl(var(--primary));
  410. --menu-submenu-active-background-color: transparent;
  411. --menu-submenu-background-color: var(--menu-background-color);
  412. }
  413. &.is-rounded {
  414. --menu-item-margin-x: 8px;
  415. --menu-item-collapse-margin-x: 6px;
  416. --menu-item-radius: 10px;
  417. }
  418. &.is-horizontal:not(.is-rounded) {
  419. --menu-item-height: 60px;
  420. --menu-item-radius: 0px;
  421. }
  422. &.is-horizontal.is-rounded {
  423. --menu-item-height: 40px;
  424. --menu-item-radius: 6px;
  425. --menu-item-padding-x: 12px;
  426. }
  427. // .vben-menu__popup,
  428. &.is-horizontal {
  429. --menu-item-padding-y: 0px;
  430. --menu-item-padding-x: 10px;
  431. --menu-item-margin-y: 0px;
  432. --menu-item-margin-x: 1px;
  433. --menu-background-color: transparent;
  434. &.is-dark {
  435. --menu-item-hover-color: var(--foreground);
  436. --menu-item-hover-background-color: hsl(var(--accent));
  437. --menu-item-active-color: hsl(var(--foreground));
  438. --menu-item-active-background-color: hsl(var(--accent));
  439. --menu-submenu-active-color: hsl(var(--foreground));
  440. --menu-submenu-active-background-color: hsl(var(--accent));
  441. --menu-submenu-hover-color: hsl(var(--foreground));
  442. --menu-submenu-hover-background-color: hsl(var(--accent));
  443. }
  444. &.is-light {
  445. --menu-item-active-color: hsl(var(--primary-foreground));
  446. --menu-item-active-background-color: hsl(var(--primary));
  447. --menu-item-hover-background-color: hsl(var(--accent));
  448. --menu-item-hover-color: hsl(var(--primary));
  449. --menu-submenu-active-color: hsl(var(--primary-foreground));
  450. --menu-submenu-active-background-color: hsl(var(--primary));
  451. --menu-submenu-hover-color: hsl(var(--primary));
  452. --menu-submenu-hover-background-color: hsl(var(--accent));
  453. }
  454. }
  455. }
  456. .#{$namespace}-menu {
  457. position: relative;
  458. box-sizing: border-box;
  459. padding-left: 0;
  460. margin: 0;
  461. list-style: none;
  462. background: hsl(var(--menu-background-color));
  463. // 垂直菜单
  464. &.is-vertical {
  465. &:not(.#{$namespace}-menu.is-collapse) {
  466. & .#{$namespace}-menu-item,
  467. & .#{$namespace}-sub-menu-content,
  468. & .#{$namespace}-menu-item-group__title {
  469. padding-left: calc(
  470. var(--menu-item-indent) + var(--menu-level) * var(--menu-item-indent)
  471. );
  472. white-space: nowrap;
  473. }
  474. & > .#{$namespace}-sub-menu {
  475. // .#{$namespace}-menu {
  476. // background: var(--menu-submenu-opened-background-color);
  477. // .#{$namespace}-sub-menu,
  478. // .#{$namespace}-menu-item:not(.is-active),
  479. // .#{$namespace}-sub-menu-content:not(.is-active) {
  480. // background: var(--menu-submenu-opened-background-color);
  481. // }
  482. // }
  483. & > .#{$namespace}-menu {
  484. & > .#{$namespace}-menu-item {
  485. padding-left: calc(
  486. 0px + var(--menu-item-indent) + var(--menu-level) *
  487. var(--menu-item-indent)
  488. );
  489. }
  490. }
  491. & > .#{$namespace}-sub-menu-content {
  492. padding-left: calc(var(--menu-item-indent) - 8px);
  493. }
  494. }
  495. & > .#{$namespace}-menu-item {
  496. padding-left: calc(var(--menu-item-indent) - 8px);
  497. }
  498. }
  499. }
  500. &.is-horizontal {
  501. display: flex;
  502. flex-wrap: nowrap;
  503. max-width: 100%;
  504. height: var(--height-horizontal-height);
  505. border-right: none;
  506. .#{$namespace}-menu-item {
  507. display: inline-flex;
  508. align-items: center;
  509. justify-content: center;
  510. height: var(--menu-item-height);
  511. padding-right: calc(var(--menu-item-padding-x) + 6px);
  512. margin: 0;
  513. margin-right: 2px;
  514. // border-bottom: 2px solid transparent;
  515. border-radius: var(--menu-item-radius);
  516. }
  517. & > .#{$namespace}-sub-menu {
  518. height: var(--menu-item-height);
  519. margin-right: 2px;
  520. &:focus,
  521. &:hover {
  522. outline: none;
  523. }
  524. & .#{$namespace}-sub-menu-content {
  525. height: 100%;
  526. padding-right: 40px;
  527. // border-bottom: 2px solid transparent;
  528. border-radius: var(--menu-item-radius);
  529. }
  530. }
  531. & .#{$namespace}-menu-item:not(.is-disabled):hover,
  532. & .#{$namespace}-menu-item:not(.is-disabled):focus {
  533. outline: none;
  534. }
  535. & > .#{$namespace}-menu-item.is-active {
  536. color: var(--menu-item-active-color);
  537. }
  538. // &.is-light {
  539. // & > .#{$namespace}-sub-menu {
  540. // &.is-active {
  541. // border-bottom: 2px solid var(--menu-item-active-color);
  542. // }
  543. // &:not(.is-active) .#{$namespace}-sub-menu-content {
  544. // &:hover {
  545. // border-bottom: 2px solid var(--menu-item-active-color);
  546. // }
  547. // }
  548. // }
  549. // & > .#{$namespace}-menu-item.is-active {
  550. // border-bottom: 2px solid var(--menu-item-active-color);
  551. // }
  552. // & .#{$namespace}-menu-item:not(.is-disabled):hover,
  553. // & .#{$namespace}-menu-item:not(.is-disabled):focus {
  554. // border-bottom: 2px solid var(--menu-item-active-color);
  555. // }
  556. // }
  557. }
  558. // 折叠菜单
  559. &.is-collapse {
  560. .#{$namespace}-menu__icon {
  561. margin-right: 0;
  562. }
  563. .#{$namespace}-sub-menu__icon-arrow {
  564. display: none;
  565. }
  566. .#{$namespace}-sub-menu-content,
  567. .#{$namespace}-menu-item {
  568. display: flex;
  569. align-items: center;
  570. justify-content: center;
  571. padding: var(--menu-item-collapse-padding-y)
  572. var(--menu-item-collapse-padding-x);
  573. margin: var(--menu-item-collapse-margin-y)
  574. var(--menu-item-collapse-margin-x);
  575. transition: all 0.3s;
  576. &.is-active {
  577. background: var(--menu-item-active-background-color) !important;
  578. border-radius: var(--menu-item-radius);
  579. }
  580. }
  581. &.is-light {
  582. .#{$namespace}-sub-menu-content,
  583. .#{$namespace}-menu-item {
  584. &.is-active {
  585. // color: hsl(var(--primary-foreground)) !important;
  586. background: var(--menu-item-active-background-color) !important;
  587. }
  588. }
  589. }
  590. &.is-rounded {
  591. .#{$namespace}-sub-menu-content,
  592. .#{$namespace}-menu-item {
  593. &.is-collapse-show-title {
  594. // padding: 32px 0 !important;
  595. margin: 4px 8px !important;
  596. }
  597. }
  598. }
  599. }
  600. &__popup-container {
  601. max-width: 240px;
  602. height: unset;
  603. padding: 0;
  604. background: var(--menu-background-color);
  605. }
  606. &__popup {
  607. padding: 4px 0;
  608. border-radius: var(--menu-item-radius);
  609. .#{$namespace}-sub-menu-content,
  610. .#{$namespace}-menu-item {
  611. padding: var(--menu-item-popup-padding-y) var(--menu-item-popup-padding-x);
  612. }
  613. }
  614. &__icon {
  615. flex-shrink: 0;
  616. width: var(--menu-item-icon-size);
  617. height: var(--menu-item-icon-size);
  618. margin-right: 8px;
  619. text-align: center;
  620. vertical-align: middle;
  621. }
  622. }
  623. .#{$namespace}-menu-item {
  624. fill: var(--menu-item-color);
  625. stroke: var(--menu-item-color);
  626. @include menu-item;
  627. &.is-active {
  628. fill: var(--menu-item-active-color);
  629. stroke: var(--menu-item-active-color);
  630. @include menu-item-active;
  631. }
  632. &__content {
  633. display: inline-flex;
  634. align-items: center;
  635. width: 100%;
  636. height: var(--menu-item-height);
  637. }
  638. &.is-collapse-show-title {
  639. padding: 32px 0 !important;
  640. // margin: 4px 8px !important;
  641. .#{$namespace}-menu-tooltip__trigger {
  642. flex-direction: column;
  643. }
  644. .#{$namespace}-menu__icon {
  645. display: block;
  646. font-size: 20px !important;
  647. transition: all 0.25s ease;
  648. }
  649. .#{$namespace}-menu__name {
  650. display: inline-flex;
  651. margin-top: 8px;
  652. margin-bottom: 0;
  653. font-size: 12px;
  654. font-weight: 400;
  655. line-height: normal;
  656. transition: all 0.25s ease;
  657. }
  658. }
  659. &:not(.is-active):hover {
  660. color: var(--menu-item-hover-color);
  661. text-decoration: none;
  662. cursor: pointer;
  663. background: var(--menu-item-hover-background-color) !important;
  664. }
  665. .#{$namespace}-menu-tooltip__trigger {
  666. position: absolute;
  667. top: 0;
  668. left: 0;
  669. box-sizing: border-box;
  670. display: inline-flex;
  671. align-items: center;
  672. justify-content: center;
  673. width: 100%;
  674. height: 100%;
  675. padding: 0 var(--menu-item-padding-x);
  676. font-size: var(--menu-font-size);
  677. line-height: var(--menu-item-height);
  678. }
  679. }
  680. .#{$namespace}-sub-menu {
  681. padding-left: 0;
  682. margin: 0;
  683. list-style: none;
  684. background: var(--menu-submenu-background-color);
  685. fill: var(--menu-item-color);
  686. stroke: var(--menu-item-color);
  687. &.is-active {
  688. div[data-state='open'] > .#{$namespace}-sub-menu-content,
  689. > .#{$namespace}-sub-menu-content {
  690. font-weight: 500;
  691. color: var(--menu-submenu-active-color);
  692. text-decoration: none;
  693. cursor: pointer;
  694. background: var(--menu-submenu-active-background-color);
  695. fill: var(--menu-submenu-active-color);
  696. stroke: var(--menu-submenu-active-color);
  697. }
  698. }
  699. }
  700. .#{$namespace}-sub-menu-content {
  701. height: var(--menu-item-height);
  702. @include menu-item;
  703. &__icon-arrow {
  704. position: absolute;
  705. top: 50%;
  706. right: 10px;
  707. width: inherit;
  708. margin-top: -8px;
  709. margin-right: 0;
  710. // font-size: 16px;
  711. font-weight: normal;
  712. opacity: 1;
  713. transition: transform 0.25s ease;
  714. }
  715. &__title {
  716. @include menu-title;
  717. }
  718. &.is-collapse-show-title {
  719. flex-direction: column;
  720. padding: 32px 0 !important;
  721. // margin: 4px 8px !important;
  722. .#{$namespace}-menu__icon {
  723. display: block;
  724. font-size: 20px !important;
  725. transition: all 0.25s ease;
  726. }
  727. .#{$namespace}-sub-menu-content__title {
  728. display: inline-flex;
  729. flex-shrink: 0;
  730. margin-top: 8px;
  731. margin-bottom: 0;
  732. font-size: 12px;
  733. font-weight: 400;
  734. line-height: normal;
  735. transition: all 0.25s ease;
  736. }
  737. }
  738. &.is-more {
  739. padding-right: 12px !important;
  740. }
  741. // &:not(.is-active):hover {
  742. &:hover {
  743. color: var(--menu-submenu-hover-color);
  744. text-decoration: none;
  745. cursor: pointer;
  746. background: var(--menu-submenu-hover-background-color) !important;
  747. // svg {
  748. // fill: var(--menu-submenu-hover-color);
  749. // }
  750. }
  751. }
  752. </style>