menu.vue 21 KB

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