menu.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. <script lang="ts" setup>
  2. import type {
  3. MenuItemClicked,
  4. MenuItemRegistered,
  5. MenuProps,
  6. MenuProvider,
  7. } from '../interface';
  8. import {
  9. type VNodeArrayChildren,
  10. computed,
  11. nextTick,
  12. reactive,
  13. ref,
  14. toRef,
  15. useSlots,
  16. watch,
  17. watchEffect,
  18. } from 'vue';
  19. import { useNamespace } from '@vben-core/hooks';
  20. import { IcRoundMoreHoriz } from '@vben-core/icons';
  21. import { isHttpUrl } from '@vben-core/toolkit';
  22. import { UseResizeObserverReturn, useResizeObserver } 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. openMenu,
  107. openedMenus,
  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: ReturnType<typeof setTimeout> | null;
  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. b(),
  279. is(mode, true),
  280. is(theme, true),
  281. is('rounded', rounded),
  282. is('collapse', collapse),
  283. ]"
  284. :style="menuStyle"
  285. role="menu"
  286. >
  287. <template v-if="mode === 'horizontal' && getSlot.showSlotMore">
  288. <template v-for="item in getSlot.slotDefault" :key="item.key">
  289. <component :is="item" />
  290. </template>
  291. <SubMenu is-sub-menu-more path="sub-menu-more">
  292. <template #title>
  293. <IcRoundMoreHoriz />
  294. </template>
  295. <template v-for="item in getSlot.slotMore" :key="item.key">
  296. <component :is="item" />
  297. </template>
  298. </SubMenu>
  299. </template>
  300. <template v-else>
  301. <slot></slot>
  302. </template>
  303. </ul>
  304. </template>
  305. <style lang="scss">
  306. $namespace: vben;
  307. @mixin menu-item-active {
  308. color: var(--menu-item-active-color);
  309. text-decoration: none;
  310. cursor: pointer;
  311. background: var(--menu-item-active-background-color);
  312. }
  313. @mixin menu-item {
  314. position: relative;
  315. display: flex;
  316. // gap: 12px;
  317. align-items: center;
  318. height: var(--menu-item-height);
  319. padding: var(--menu-item-padding-y) var(--menu-item-padding-x);
  320. margin: 0 var(--menu-item-margin-x) var(--menu-item-margin-y)
  321. var(--menu-item-margin-x);
  322. font-size: var(--menu-font-size);
  323. color: var(--menu-item-color);
  324. text-decoration: none;
  325. white-space: nowrap;
  326. list-style: none;
  327. cursor: pointer;
  328. background: var(--menu-item-background-color);
  329. border: none;
  330. border-radius: var(--menu-item-radius);
  331. transition:
  332. background 0.15s ease,
  333. color 0.15s ease,
  334. padding 0.15s ease,
  335. border-color 0.15s ease;
  336. &.is-disabled {
  337. cursor: not-allowed;
  338. background: none !important;
  339. opacity: 0.25;
  340. }
  341. .#{$namespace}-menu__icon {
  342. transition: transform 0.25s;
  343. }
  344. &:hover {
  345. .#{$namespace}-menu__icon {
  346. transform: scale(1.3);
  347. }
  348. }
  349. &:hover,
  350. &:focus {
  351. outline: none;
  352. }
  353. * {
  354. vertical-align: bottom;
  355. }
  356. }
  357. @mixin menu-title {
  358. max-width: var(--menu-title-width);
  359. overflow: hidden;
  360. text-overflow: ellipsis;
  361. white-space: nowrap;
  362. opacity: 1;
  363. }
  364. .#{$namespace}-menu__popup-container,
  365. .#{$namespace}-menu {
  366. --menu-title-width: 140px;
  367. --menu-item-icon-width: 20px;
  368. --menu-item-height: 38px;
  369. --menu-item-padding-y: 26px;
  370. --menu-item-padding-x: 12px;
  371. --menu-item-popup-padding-y: 22px;
  372. --menu-item-popup-padding-x: 12px;
  373. --menu-item-margin-y: 4px;
  374. --menu-item-margin-x: 0px;
  375. --menu-item-collapse-padding-y: 25px;
  376. --menu-item-collapse-padding-x: 0px;
  377. --menu-item-collapse-margin-y: 4px;
  378. --menu-item-collapse-margin-x: 0px;
  379. --menu-item-radius: 0px;
  380. --menu-item-indent: 16px;
  381. --menu-font-size: 14px;
  382. --menu-dark-background: 0deg 0% 100% / 10%;
  383. --menu-light-background: 192deg 1% 93%;
  384. &.is-dark {
  385. --menu-background-color: hsl(var(--menu-dark));
  386. // --menu-submenu-opened-background-color: hsl(var(--menu-opened-dark));
  387. --menu-item-background-color: var(--menu-background-color);
  388. --menu-item-color: hsl(var(--dark-foreground) / 80%);
  389. --menu-item-hover-color: hsl(var(--primary-foreground));
  390. --menu-item-hover-background-color: hsl(var(--menu-dark-background));
  391. --menu-item-active-color: hsl(var(--primary-foreground));
  392. --menu-item-active-background-color: hsl(var(--primary));
  393. --menu-submenu-hover-color: hsl(var(--dark-foreground));
  394. --menu-submenu-hover-background-color: hsl(var(--menu-dark-background));
  395. --menu-submenu-active-color: hsl(var(--dark-foreground));
  396. --menu-submenu-active-background-color: transparent;
  397. --menu-submenu-background-color: var(--menu-background-color);
  398. }
  399. &.is-light {
  400. --menu-background-color: hsl(var(--menu));
  401. // --menu-submenu-opened-background-color: hsl(var(--menu-opened));
  402. --menu-item-background-color: var(--menu-background-color);
  403. --menu-item-color: hsl(var(--foreground));
  404. --menu-item-hover-color: var(--menu-item-color);
  405. --menu-item-hover-background-color: hsl(var(--menu-light-background));
  406. --menu-item-active-color: hsl(var(--primary-foreground));
  407. --menu-item-active-background-color: hsl(var(--primary));
  408. --menu-submenu-hover-color: hsl(var(--primary));
  409. --menu-submenu-hover-background-color: hsl(var(--menu-light-background));
  410. --menu-submenu-active-color: hsl(var(--primary));
  411. --menu-submenu-active-background-color: transparent;
  412. --menu-submenu-background-color: var(--menu-background-color);
  413. }
  414. &.is-rounded {
  415. --menu-item-margin-x: 8px;
  416. --menu-item-collapse-margin-x: 6px;
  417. --menu-item-radius: 6px;
  418. }
  419. &.is-horizontal:not(.is-rounded) {
  420. --menu-item-height: 60px;
  421. --menu-item-radius: 0px;
  422. }
  423. &.is-horizontal.is-rounded {
  424. --menu-item-height: 40px;
  425. --menu-item-radius: 6px;
  426. --menu-item-padding-x: 12px;
  427. }
  428. // .vben-menu__popup,
  429. &.is-horizontal {
  430. --menu-item-padding-y: 0px;
  431. --menu-item-padding-x: 10px;
  432. --menu-item-margin-y: 0px;
  433. --menu-item-margin-x: 1px;
  434. --menu-background-color: transparent;
  435. &.is-dark {
  436. --menu-item-hover-color: var(--foreground);
  437. --menu-item-hover-background-color: hsl(var(--menu-dark-background));
  438. --menu-item-active-color: hsl(var(--foreground));
  439. --menu-item-active-background-color: hsl(var(--menu-dark-background));
  440. --menu-submenu-active-color: hsl(var(--foreground));
  441. --menu-submenu-active-background-color: hsl(var(--menu-dark-background));
  442. --menu-submenu-hover-color: hsl(var(--foreground));
  443. --menu-submenu-hover-background-color: hsl(var(--menu-dark-background));
  444. }
  445. &.is-light {
  446. --menu-item-active-color: hsl(var(--foreground));
  447. --menu-item-active-background-color: hsl(var(--menu-light-background));
  448. --menu-item-hover-background-color: hsl(var(--menu-light-background));
  449. --menu-item-hover-color: hsl(var(--primary));
  450. --menu-submenu-hover-color: hsl(var(--primary));
  451. --menu-submenu-hover-background-color: hsl(var(--menu-light-background));
  452. --menu-submenu-active-color: hsl(var(--foreground));
  453. --menu-submenu-active-background-color: hsl(var(--menu-light-background));
  454. }
  455. }
  456. }
  457. .#{$namespace}-menu {
  458. position: relative;
  459. box-sizing: border-box;
  460. padding-left: 0;
  461. margin: 0;
  462. list-style: none;
  463. background: hsl(var(--menu-background-color));
  464. // 垂直菜单
  465. &.is-vertical {
  466. &:not(.#{$namespace}-menu.is-collapse) {
  467. & .#{$namespace}-menu-item,
  468. & .#{$namespace}-sub-menu-content,
  469. & .#{$namespace}-menu-item-group__title {
  470. padding-left: calc(
  471. var(--menu-item-indent) + var(--menu-level) * var(--menu-item-indent)
  472. );
  473. white-space: nowrap;
  474. }
  475. & > .#{$namespace}-sub-menu {
  476. // .#{$namespace}-menu {
  477. // background: var(--menu-submenu-opened-background-color);
  478. // .#{$namespace}-sub-menu,
  479. // .#{$namespace}-menu-item:not(.is-active),
  480. // .#{$namespace}-sub-menu-content:not(.is-active) {
  481. // background: var(--menu-submenu-opened-background-color);
  482. // }
  483. // }
  484. & > .#{$namespace}-menu {
  485. & > .#{$namespace}-menu-item {
  486. padding-left: calc(
  487. 0px + var(--menu-item-indent) + var(--menu-level) *
  488. var(--menu-item-indent)
  489. );
  490. }
  491. }
  492. & > .#{$namespace}-sub-menu-content {
  493. padding-left: calc(var(--menu-item-indent) - 8px);
  494. }
  495. }
  496. & > .#{$namespace}-menu-item {
  497. padding-left: calc(var(--menu-item-indent) - 8px);
  498. }
  499. }
  500. }
  501. &.is-horizontal {
  502. display: flex;
  503. flex-wrap: nowrap;
  504. max-width: 100%;
  505. height: var(--height-horizontal-height);
  506. border-right: none;
  507. .#{$namespace}-menu-item {
  508. display: inline-flex;
  509. align-items: center;
  510. justify-content: center;
  511. height: var(--menu-item-height);
  512. padding-right: calc(var(--menu-item-padding-x) + 6px);
  513. margin: 0;
  514. margin-right: 2px;
  515. // border-bottom: 2px solid transparent;
  516. border-radius: var(--menu-item-radius);
  517. }
  518. & > .#{$namespace}-sub-menu {
  519. height: var(--menu-item-height);
  520. margin-right: 2px;
  521. &:focus,
  522. &:hover {
  523. outline: none;
  524. }
  525. & .#{$namespace}-sub-menu-content {
  526. height: 100%;
  527. padding-right: 40px;
  528. // border-bottom: 2px solid transparent;
  529. border-radius: var(--menu-item-radius);
  530. }
  531. }
  532. & .#{$namespace}-menu-item:not(.is-disabled):hover,
  533. & .#{$namespace}-menu-item:not(.is-disabled):focus {
  534. outline: none;
  535. }
  536. & > .#{$namespace}-menu-item.is-active {
  537. color: var(--menu-item-active-color);
  538. }
  539. // &.is-light {
  540. // & > .#{$namespace}-sub-menu {
  541. // &.is-active {
  542. // border-bottom: 2px solid var(--menu-item-active-color);
  543. // }
  544. // &:not(.is-active) .#{$namespace}-sub-menu-content {
  545. // &:hover {
  546. // border-bottom: 2px solid var(--menu-item-active-color);
  547. // }
  548. // }
  549. // }
  550. // & > .#{$namespace}-menu-item.is-active {
  551. // border-bottom: 2px solid var(--menu-item-active-color);
  552. // }
  553. // & .#{$namespace}-menu-item:not(.is-disabled):hover,
  554. // & .#{$namespace}-menu-item:not(.is-disabled):focus {
  555. // border-bottom: 2px solid var(--menu-item-active-color);
  556. // }
  557. // }
  558. }
  559. // 折叠菜单
  560. &.is-collapse {
  561. .#{$namespace}-menu__icon {
  562. margin-right: 0;
  563. }
  564. .#{$namespace}-sub-menu__icon-arrow {
  565. display: none;
  566. }
  567. .#{$namespace}-sub-menu-content,
  568. .#{$namespace}-menu-item {
  569. display: flex;
  570. align-items: center;
  571. justify-content: center;
  572. padding: var(--menu-item-collapse-padding-y)
  573. var(--menu-item-collapse-padding-x);
  574. margin: var(--menu-item-collapse-margin-y)
  575. var(--menu-item-collapse-margin-x);
  576. transition: all 0.3s;
  577. &.is-active {
  578. background: var(--menu-item-active-background-color) !important;
  579. border-radius: var(--menu-item-radius);
  580. }
  581. }
  582. &.is-light {
  583. .#{$namespace}-sub-menu-content,
  584. .#{$namespace}-menu-item {
  585. &.is-active {
  586. color: hsl(var(--primary-foreground)) !important;
  587. background: var(--menu-item-active-background-color) !important;
  588. }
  589. }
  590. }
  591. &.is-rounded {
  592. .#{$namespace}-sub-menu-content,
  593. .#{$namespace}-menu-item {
  594. &.is-collapse-show-title {
  595. // padding: 32px 0 !important;
  596. margin: 4px 8px !important;
  597. }
  598. }
  599. }
  600. }
  601. &__popup-container {
  602. max-width: 240px;
  603. height: unset;
  604. padding: 0;
  605. background: var(--menu-background-color);
  606. }
  607. &__popup {
  608. padding: 4px 0;
  609. border-radius: var(--menu-item-radius);
  610. .#{$namespace}-sub-menu-content,
  611. .#{$namespace}-menu-item {
  612. padding: var(--menu-item-popup-padding-y) var(--menu-item-popup-padding-x);
  613. }
  614. }
  615. &__icon {
  616. flex-shrink: 0;
  617. // width: var(--menu-item-icon-width);
  618. max-height: var(--menu-item-icon-width);
  619. margin-right: 12px;
  620. font-size: 20px;
  621. text-align: center;
  622. vertical-align: middle;
  623. }
  624. }
  625. .#{$namespace}-menu-item {
  626. fill: var(--menu-item-color);
  627. stroke: var(--menu-item-color);
  628. @include menu-item;
  629. &.is-active {
  630. fill: var(--menu-item-active-color);
  631. stroke: var(--menu-item-active-color);
  632. @include menu-item-active;
  633. }
  634. &__content {
  635. display: inline-flex;
  636. align-items: center;
  637. width: 100%;
  638. height: var(--menu-item-height);
  639. }
  640. &.is-collapse-show-title {
  641. padding: 32px 0 !important;
  642. // margin: 4px 8px !important;
  643. .#{$namespace}-menu-tooltip__trigger {
  644. flex-direction: column;
  645. }
  646. .#{$namespace}-menu__icon {
  647. display: block;
  648. font-size: 20px !important;
  649. transition: all 0.25s ease;
  650. }
  651. .#{$namespace}-menu__name {
  652. display: inline-flex;
  653. margin-top: 8px;
  654. margin-bottom: 0;
  655. font-size: 12px;
  656. font-weight: 400;
  657. line-height: normal;
  658. transition: all 0.25s ease;
  659. }
  660. }
  661. &:not(.is-active):hover {
  662. color: var(--menu-item-hover-color);
  663. text-decoration: none;
  664. cursor: pointer;
  665. background: var(--menu-item-hover-background-color) !important;
  666. }
  667. .#{$namespace}-menu-tooltip__trigger {
  668. position: absolute;
  669. top: 0;
  670. left: 0;
  671. box-sizing: border-box;
  672. display: inline-flex;
  673. align-items: center;
  674. justify-content: center;
  675. width: 100%;
  676. height: 100%;
  677. padding: 0 var(--menu-item-padding-x);
  678. font-size: var(--menu-font-size);
  679. line-height: var(--menu-item-height);
  680. }
  681. }
  682. .#{$namespace}-sub-menu {
  683. padding-left: 0;
  684. margin: 0;
  685. list-style: none;
  686. background: var(--menu-submenu-background-color);
  687. fill: var(--menu-item-color);
  688. stroke: var(--menu-item-color);
  689. &.is-active {
  690. div[data-state='open'] > .#{$namespace}-sub-menu-content,
  691. > .#{$namespace}-sub-menu-content {
  692. color: var(--menu-submenu-active-color);
  693. text-decoration: none;
  694. cursor: pointer;
  695. background: var(--menu-submenu-active-background-color);
  696. fill: var(--menu-submenu-active-color);
  697. stroke: var(--menu-submenu-active-color);
  698. }
  699. }
  700. }
  701. .#{$namespace}-sub-menu-content {
  702. height: var(--menu-item-height);
  703. @include menu-item;
  704. &__icon-arrow {
  705. position: absolute;
  706. top: 50%;
  707. right: 6px;
  708. width: inherit;
  709. margin-top: -8px;
  710. margin-right: 0;
  711. font-size: 16px;
  712. font-weight: normal;
  713. opacity: 1;
  714. transition: transform 0.25s ease;
  715. }
  716. &__title {
  717. @include menu-title;
  718. }
  719. &.is-collapse-show-title {
  720. flex-direction: column;
  721. padding: 32px 0 !important;
  722. // margin: 4px 8px !important;
  723. .#{$namespace}-menu__icon {
  724. display: block;
  725. font-size: 20px !important;
  726. transition: all 0.25s ease;
  727. }
  728. .#{$namespace}-sub-menu-content__title {
  729. display: inline-flex;
  730. flex-shrink: 0;
  731. margin-top: 8px;
  732. margin-bottom: 0;
  733. font-size: 12px;
  734. font-weight: 400;
  735. line-height: normal;
  736. transition: all 0.25s ease;
  737. }
  738. }
  739. &.is-more {
  740. padding-right: 12px !important;
  741. }
  742. // &:not(.is-active):hover {
  743. &:hover {
  744. color: var(--menu-submenu-hover-color);
  745. text-decoration: none;
  746. cursor: pointer;
  747. background: var(--menu-submenu-hover-background-color) !important;
  748. svg {
  749. fill: var(--menu-submenu-hover-color);
  750. }
  751. }
  752. }
  753. </style>