From e7c97a84e0103e45b77bc78f2c5c2d0ec9004632 Mon Sep 17 00:00:00 2001 From: yeweili <782312713@qq.com> Date: Mon, 31 Jul 2023 10:41:45 +0800 Subject: [PATCH] =?UTF-8?q?chore():=20=E5=88=A0=E9=99=A4=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E6=9E=84=E4=BB=B6=20Refs=20CMDB=5FINSTANCE-1?= =?UTF-8?q?54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bricks/frame-bricks/src/index.ts | 2 - .../src/nw-nav-menu/NavMenu.module.css | 38 --- .../src/nw-nav-menu/NavMenu.spec.tsx | 143 --------- .../frame-bricks/src/nw-nav-menu/NavMenu.tsx | 179 ----------- .../ThreeLevelMenuPopoverContent.module.css | 211 ------------- .../ThreeLevelMenuPopoverContent.spec.tsx | 219 ------------- .../ThreeLevelMenuPopoverContent.tsx | 146 --------- .../src/nw-nav-menu/index.spec.ts | 20 -- bricks/frame-bricks/src/nw-nav-menu/index.tsx | 76 ----- bricks/frame-bricks/src/nw-nav-menu/utils.tsx | 76 ----- .../src/nw-side-bar/SideBar.module.css | 182 ----------- .../src/nw-side-bar/SideBar.spec.tsx | 105 ------- .../frame-bricks/src/nw-side-bar/SideBar.tsx | 294 ------------------ .../src/nw-side-bar/SidebarMenu.module.css | 96 ------ .../src/nw-side-bar/SidebarMenu.spec.tsx | 26 -- .../src/nw-side-bar/SidebarMenu.tsx | 213 ------------- .../src/nw-side-bar/index.spec.ts | 20 -- bricks/frame-bricks/src/nw-side-bar/index.tsx | 114 ------- .../frame-bricks/src/nw-side-bar/mockData.ts | 273 ---------------- 19 files changed, 2433 deletions(-) delete mode 100644 bricks/frame-bricks/src/nw-nav-menu/NavMenu.module.css delete mode 100644 bricks/frame-bricks/src/nw-nav-menu/NavMenu.spec.tsx delete mode 100644 bricks/frame-bricks/src/nw-nav-menu/NavMenu.tsx delete mode 100644 bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.module.css delete mode 100644 bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.spec.tsx delete mode 100644 bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.tsx delete mode 100644 bricks/frame-bricks/src/nw-nav-menu/index.spec.ts delete mode 100644 bricks/frame-bricks/src/nw-nav-menu/index.tsx delete mode 100644 bricks/frame-bricks/src/nw-nav-menu/utils.tsx delete mode 100644 bricks/frame-bricks/src/nw-side-bar/SideBar.module.css delete mode 100644 bricks/frame-bricks/src/nw-side-bar/SideBar.spec.tsx delete mode 100644 bricks/frame-bricks/src/nw-side-bar/SideBar.tsx delete mode 100644 bricks/frame-bricks/src/nw-side-bar/SidebarMenu.module.css delete mode 100644 bricks/frame-bricks/src/nw-side-bar/SidebarMenu.spec.tsx delete mode 100644 bricks/frame-bricks/src/nw-side-bar/SidebarMenu.tsx delete mode 100644 bricks/frame-bricks/src/nw-side-bar/index.spec.ts delete mode 100644 bricks/frame-bricks/src/nw-side-bar/index.tsx delete mode 100644 bricks/frame-bricks/src/nw-side-bar/mockData.ts diff --git a/bricks/frame-bricks/src/index.ts b/bricks/frame-bricks/src/index.ts index a30a590b8..b8bb870a7 100644 --- a/bricks/frame-bricks/src/index.ts +++ b/bricks/frame-bricks/src/index.ts @@ -2,5 +2,3 @@ import "./i18n"; import "./side-bar"; import "./nav-menu"; import "./drop-menu"; -import "./nw-nav-menu"; -import "./nw-side-bar"; diff --git a/bricks/frame-bricks/src/nw-nav-menu/NavMenu.module.css b/bricks/frame-bricks/src/nw-nav-menu/NavMenu.module.css deleted file mode 100644 index e9680a100..000000000 --- a/bricks/frame-bricks/src/nw-nav-menu/NavMenu.module.css +++ /dev/null @@ -1,38 +0,0 @@ -.navMenuContainer { - /* border-bottom: none; */ - line-height: 40px; - &:global(.ant-menu) { - background: none !important; - > :global(.ant-menu-item) > a { - color: #ffffff !important; - } - .menuItemIcon { - vertical-align: middle; - } - } - &:global(.ant-menu-horizontal) { - border-bottom: none !important; - } - &:global(.ant-menu-horizontal:not(.ant-menu-dark)) > :global(.ant-menu-item) { - margin: 0 10px !important; - } - > :global(.ant-menu-item) { - .textStyle { - color: hsla(0, 0%, 100%, 0.7); - } - .iconStyle { - color: hsla(0, 0%, 100%, 0.7) !important; - } - } - - > :global(.ant-menu-item-active), - :global(.ant-menu-item-selected) { - border-bottom: 2px solid #3aa2eb !important; - .textStyle { - color: #ffffff; - } - .iconStyle { - color: #ffffff !important; - } - } -} diff --git a/bricks/frame-bricks/src/nw-nav-menu/NavMenu.spec.tsx b/bricks/frame-bricks/src/nw-nav-menu/NavMenu.spec.tsx deleted file mode 100644 index 145ff6c1f..000000000 --- a/bricks/frame-bricks/src/nw-nav-menu/NavMenu.spec.tsx +++ /dev/null @@ -1,143 +0,0 @@ -import React from "react"; -import { Menu } from "antd"; -import { mount } from "enzyme"; -import { NavMenu } from "./NavMenu"; -import { SidebarMenuItem } from "@next-core/brick-types"; -import * as brickKit from "@next-core/brick-kit"; - -jest.spyOn(brickKit, "getHistory").mockReturnValue({ - location: { - pathname: "/page-1-2", - }, - // eslint-disable-next-line @typescript-eslint/no-empty-function - listen: () => {}, - // eslint-disable-next-line @typescript-eslint/no-empty-function - createHref: () => {}, -} as any); - -const sideBarMenuItem = [ - { - type: "subMenu", - title: "subMenu", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - useBrick: { - brick: "span", - properties: { - textContent: "subMenu", - }, - }, - items: [ - { - type: "group", - title: "group-1", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - useBrick: { - brick: "span", - properties: { - textContent: "group-1", - }, - }, - items: [ - { - text: "subMenu-group-item-1", - type: "default", - to: "/page-1-1", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - text: "subMenu-group-item-2", - type: "default", - to: "/page-1-2", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - ], - }, - ], - }, - { - type: "group", - title: "group-2", - items: [ - { - type: "default", - text: "group-2-item-1", - }, - ], - }, - { - type: "group", - title: "empty-group-should-not-render", - items: [], - }, - { - type: "default", - text: "page-3", - }, - { - type: "default", - text: "page-4", - }, - { - type: "default", - text: "page-5", - divider: true, - }, -] as SidebarMenuItem[]; - -describe("NavMenu", () => { - it("should work", () => { - const wrapper = mount(); - - expect(wrapper.find(Menu).prop("selectedKeys")).toEqual(["0.0.1"]); - - expect(wrapper.find(Menu.SubMenu).length).toBe(2); - - expect(wrapper.find(Menu.Item).length).toBe(2); - }); - - it("should work while customItem was true", () => { - const wrapper = mount(); - - expect(wrapper.find(Menu.SubMenu).length).toBe(0); - }); - - it("should be rendered as divider when item property `divider` is true", () => { - const wrapper = mount(); - - expect(wrapper.find(Menu.Divider).length).toBe(1); - }); - - it("property `ShowTooltip` should decide whether to show item tooltip ", () => { - const wrapper = mount( - - ); - - expect(wrapper.find(Menu.Item).get(0).props["title"]).toBe("page-3"); - - wrapper.setProps({ - showTooltip: false, - }); - - expect(wrapper.find(Menu.Item).get(0).props["title"]).toBe(""); - }); -}); diff --git a/bricks/frame-bricks/src/nw-nav-menu/NavMenu.tsx b/bricks/frame-bricks/src/nw-nav-menu/NavMenu.tsx deleted file mode 100644 index a2cb23020..000000000 --- a/bricks/frame-bricks/src/nw-nav-menu/NavMenu.tsx +++ /dev/null @@ -1,179 +0,0 @@ -/* eslint-disable @typescript-eslint/no-use-before-define */ -import React, { useState, useEffect } from "react"; -import { Menu, Popover } from "antd"; -import { UnregisterCallback, Location } from "history"; -import { getHistory } from "@next-core/brick-kit"; -import { initMenuItemAndMatchCurrentPathKeys } from "@next-libs/basic-components"; -import { - SidebarMenuItem, - SidebarMenuGroups, - SidebarMenuSimpleItems, - isDivider, - isGroup, - isSubMenu, - renderBrickCom, - renderDivider, - renderLinkCom, - renderSpanCom, -} from "./utils"; -import style from "./NavMenu.module.css"; -import { ThreeLevelMenuPopoverContent } from "./ThreeLevelMenuPopoverContent"; - -interface SidebarMenuProps { - menuItems?: SidebarMenuItem[]; - isCustom?: boolean; - selectedKeys?: string[]; - showTooltip?: boolean; -} - -export function NavMenu(props: SidebarMenuProps): React.ReactElement { - const { menuItems, showTooltip } = props; - - const history = getHistory(); - const [location, setLocation] = useState(history.location); - const unListen: UnregisterCallback = history.listen((location) => { - setLocation(location); - }); - const { pathname, search } = location; - - const [selectedKey, setSelectedKey] = useState([]); - - const setSelected = async (): Promise => { - const { selectedKeys } = initMenuItemAndMatchCurrentPathKeys( - menuItems, - pathname, - search, - "" - ); - setSelectedKey(selectedKeys); - }; - - useEffect(() => { - setSelected(); - return unListen; - }, []); - - const renderSimpleMenuItem = ( - item: SidebarMenuSimpleItems - ): React.ReactNode => { - return ( - - {item.useBrick - ? renderBrickCom(item) - : renderLinkCom(item, style.textStyle, {}, style.iconStyle)} - - ); - }; - - const renderGroupMenu = (item: SidebarMenuGroups): React.ReactNode => { - if (item.items?.length > 0) { - return ( - - {item.items?.map((innerItem) => renderMenuItem(innerItem))} - - ); - } - }; - - const renderSubMenu = (item: SidebarMenuGroups): React.ReactNode => { - if (item.items?.length > 0) { - return ( - - {item.items.map((innerItem) => renderMenuItem(innerItem))} - - ); - } - }; - - const renderThreeLevelMenu = (item: SidebarMenuGroups): React.ReactNode => { - return ( - - { - // 阻止滚动穿透 - if (visible) { - document.body.style.overflow = "hidden"; - document.body.style.touchAction = "none"; - } else { - document.body.style.overflow = ""; - document.body.style.touchAction = ""; - } - }} - content={ - - } - > -
{ - e.stopPropagation(); - }} - > -
- {item.useBrick ? renderBrickCom(item) : renderSpanCom(item)} -
-
-
-
- ); - }; - - const renderMenuItem = ( - item: SidebarMenuItem, - groupAsSubMenu?: boolean - ): React.ReactNode => { - return isDivider(item) - ? renderDivider() - : isSubMenu(item, groupAsSubMenu) - ? renderSubMenu(item) - : isGroup(item) - ? renderGroupMenu(item) - : renderSimpleMenuItem(item); - }; - - return ( - - {menuItems.map((item) => - isSubMenu(item, true) && - item.childLayout === "category" && - item.items?.length - ? renderThreeLevelMenu(item) - : renderMenuItem(item, true) - )} - - ); -} diff --git a/bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.module.css b/bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.module.css deleted file mode 100644 index e7751f2bc..000000000 --- a/bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.module.css +++ /dev/null @@ -1,211 +0,0 @@ -html[data-theme="light"] { - --menu-header-background: linear-gradient( - 90deg, - rgb(230, 236, 245, 0.7) 0%, - rgb(255, 255, 255, 0.7) 100% - ); -} - -html[data-theme="dark-v2"] { - --menu-header-background: linear-gradient(90deg, #343b4d 0%, #2a2a2b 100%); -} - -.wrapper { - display: flex; - max-height: 456px; -} - -.groupList { - padding: 12px 0; - display: flex; - flex-direction: column; - gap: 8px; - overflow-y: scroll; - border-right: 1px solid var(--color-text-divider-line); - scrollbar-width: none; - - &::-webkit-scrollbar { - width: 0; - background: transparent; - } - - .groupItem { - width: 160px; - flex-shrink: 0; - position: relative; - height: 36px; - display: flex; - align-items: center; - cursor: pointer; - - &::before { - content: ""; - position: absolute; - width: 5px; - height: 5px; - background: var(--color-secondary-text); - border-radius: 50%; - left: 11px; - bottom: 50%; - transform: translateY(50%); - opacity: 0; - } - - &::after { - content: ""; - position: absolute; - width: 28px; - height: 2px; - background: var(--color-brand); - left: 24px; - bottom: 0; - opacity: 0; - } - - .groupItemText { - display: block; - margin-left: 24px; - margin-right: 10px; - font-size: 14px; - color: var(--color-normal-text); - line-height: 20px; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - } - - &.groupItemChecked { - &::before { - opacity: 1; - } - } - - &.groupItemActive { - &::before { - background: var(--color-brand); - } - - &::after { - opacity: 1; - } - - .groupItemText { - color: var(--color-brand); - } - } - - &:hover { - &::before { - background: var(--color-brand); - } - - &::after { - opacity: 1; - } - - .groupItemText { - color: var(--color-brand); - } - } - } -} - -.menuContainer { - display: flex; - flex-direction: column; - - .menuHeader { - height: 44px; - flex-shrink: 0; - display: flex; - align-items: center; - background: var(--menu-header-background); - - .menuHeaderText { - margin-left: 20px; - font-size: 16px; - font-weight: var(--font-weight-500); - color: var(--color-normal-text); - line-height: 20px; - } - } - - .menuItemsContainer { - padding: 12px 0; - overflow-y: scroll; - display: grid; - grid-template-columns: repeat(2, 160px); - gap: 2px 0; - scrollbar-width: none; - - &::-webkit-scrollbar { - width: 0; - background: transparent; - } - - .menuItem { - height: 36px; - position: relative; - display: flex; - align-items: center; - cursor: pointer; - - &::before { - content: ""; - position: absolute; - width: 4px; - height: 4px; - background: var(--color-normal-text); - border-radius: 50%; - left: 12px; - bottom: 50%; - transform: translateY(50%); - opacity: 0; - } - - .menuItemText { - display: block; - margin-left: 24px; - margin-right: 10px; - font-size: 14px; - color: var(--color-normal-text); - line-height: 20px; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; - } - - &.menuItemChecked { - &::before { - opacity: 1; - } - - .menuItemText { - font-weight: var(--font-weight-500); - color: var(--color-strong-text); - line-height: 22px; - } - } - - &.menuItemActive { - &::before { - background: var(--color-brand); - } - - .menuItemText { - color: var(--color-brand); - } - } - - &:hover { - &::before { - background: var(--color-brand); - } - - .menuItemText { - color: var(--color-brand); - } - } - } - } -} diff --git a/bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.spec.tsx b/bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.spec.tsx deleted file mode 100644 index e2bfb5a3b..000000000 --- a/bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.spec.tsx +++ /dev/null @@ -1,219 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import { ThreeLevelMenuPopoverContent } from "./ThreeLevelMenuPopoverContent"; -import { SidebarMenuGroups } from "./utils"; -import * as brickKit from "@next-core/brick-kit"; -import { act } from "react-dom/test-utils"; - -jest.spyOn(brickKit, "getHistory").mockReturnValue({ - location: { - pathname: "/page-1-2", - }, - // eslint-disable-next-line @typescript-eslint/no-empty-function - listen: () => {}, - // eslint-disable-next-line @typescript-eslint/no-empty-function - createHref: () => {}, -} as any); - -jest.useFakeTimers(); - -const menuItem = { - type: "subMenu", - title: "menu-item-04", - items: [ - { - instanceId: "5fc6bcc946b0e", - sort: 0, - key: "3.0", - text: "menu-group-04-01", - to: "/nlicro-test2", - type: "group", - title: "menu-group-04-01", - items: [ - { - instanceId: "3.0.0", - key: "3.0.0", - sort: 0, - text: "menu-item-3.0.0", - to: "/nlicro-test772", - type: "default", - }, - { - instanceId: "3.0.1", - key: "3.0.1", - sort: 0, - text: "menu-item-3.0.1", - to: "/nlicro-test2/chart", - type: "default", - }, - { - instanceId: "3.0.2", - key: "3.0.2", - sort: 0, - text: "menu-item-3.0.2", - to: "/nlicro-test772", - type: "default", - }, - ], - }, - { - instanceId: "5fc6bcc946b72", - sort: 0, - key: "3.1", - text: "menu-group-04-02", - to: "/nlicro-test2", - type: "group", - title: "menu-group-04-02", - items: [ - { - instanceId: "3.1.0", - key: "3.1.0", - sort: 0, - text: "menu-item-3.1.0", - to: "/nlicro-test772", - type: "default", - }, - { - instanceId: "3.1.1", - key: "3.1.1", - sort: 0, - text: "menu-item-3.1.1", - to: "/nlicro-test772", - type: "default", - }, - { - instanceId: "3.1.2", - key: "3.1.2", - sort: 0, - text: "menu-item-3.1.2", - to: "/nlicro-test772", - type: "default", - }, - ], - }, - { - instanceId: "5fc6bcc946bd6", - sort: 0, - key: "3.2", - text: "menu-group-04-03", - to: "/nlicro-test2", - type: "group", - title: "menu-group-04-03", - items: [ - { - instanceId: "3.2.0", - key: "3.2.0", - sort: 0, - text: "menu-item-3.2.0", - to: "/nlicro-test772", - type: "default", - }, - { - instanceId: "3.2.1", - key: "3.2.1", - sort: 0, - text: "menu-item-3.2.1", - to: "/nlicro-test772", - type: "default", - }, - { - instanceId: "3.2.2", - key: "3.2.2", - sort: 0, - text: "menu-item-3.2.2", - to: "/nlicro-test772", - type: "default", - }, - ], - }, - { - instanceId: "5fc6bcc946c3a", - sort: 0, - key: "3.3", - text: "menu-group-04-04", - to: "/nlicro-test2", - type: "default", - title: "menu-group-04-04", - }, - { - instanceId: "5fc6bcc946c9e", - sort: 0, - key: "3.4", - text: "menu-group-04-05", - to: "/nlicro-test2", - type: "subMenu", - title: "menu-group-04-05", - }, - ], - defaultExpanded: false, - childLayout: "category", -} as SidebarMenuGroups; - -describe("ThreeLevelMenuPopoverContent", () => { - it("should work without selectedKey", async () => { - const wrapper = mount( - - ); - - expect(wrapper.find(".groupItem")).toHaveLength(4); - expect(wrapper.find(".groupItemChecked")).toHaveLength(0); - expect( - wrapper.find(".groupItem").at(0).hasClass("groupItemActive") - ).toBeTruthy(); - expect(wrapper.find(".menuContainer")).toHaveLength(1); - expect(wrapper.find(".menuHeaderText").text()).toBe("menu-group-04-01"); - - await act(async () => { - wrapper.find(".groupItem").at(1).simulate("mouseenter"); - jest.runAllTimers(); - }); - wrapper.update(); - - expect( - wrapper.find(".groupItem").at(1).hasClass("groupItemActive") - ).toBeTruthy(); - expect(wrapper.find(".menuHeaderText").text()).toBe("menu-group-04-02"); - expect(wrapper.find(".menuItem")).toHaveLength(3); - - wrapper.find(".menuItem").at(1).simulate("click"); - expect( - wrapper.find(".menuItem").at(1).hasClass("menuItemActive") - ).toBeTruthy(); - - // cancel key update - await act(async () => { - wrapper.find(".groupItem").at(2).simulate("mouseenter"); - wrapper.find(".menuContainer").simulate("mouseenter"); - jest.runAllTimers(); - }); - wrapper.update(); - - expect( - wrapper.find(".groupItem").at(1).hasClass("groupItemActive") - ).toBeTruthy(); - expect(wrapper.find(".menuHeaderText").text()).toBe("menu-group-04-02"); - expect(wrapper.find(".menuItem")).toHaveLength(3); - }); - - it("should work with selectedKey", () => { - const wrapper = mount( - - ); - - expect( - wrapper.find(".groupItem").at(0).hasClass("groupItemChecked") - ).toBeTruthy(); - expect( - wrapper.find(".groupItem").at(0).hasClass("groupItemActive") - ).toBeTruthy(); - - expect(wrapper.find(".menuItem")).toHaveLength(3); - expect( - wrapper.find(".menuItem").at(0).hasClass("menuItemChecked") - ).toBeTruthy(); - expect(wrapper.find(".menuItemActive")).toHaveLength(0); - }); -}); diff --git a/bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.tsx b/bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.tsx deleted file mode 100644 index 8c42cb9e1..000000000 --- a/bricks/frame-bricks/src/nw-nav-menu/ThreeLevelMenuPopoverContent.tsx +++ /dev/null @@ -1,146 +0,0 @@ -import React, { useEffect, useMemo, useState } from "react"; -import classnames from "classnames"; -import styles from "./ThreeLevelMenuPopoverContent.module.css"; -import { - SidebarMenuGroups, - SidebarMenuSimpleItems, - isSubMenu, - isGroup, - renderLinkCom, -} from "./utils"; -import { debounce } from "lodash"; - -interface ThreeLevelMenuPopoverContentProps { - menuItem: SidebarMenuGroups; - selectedKey: string[]; -} - -export function ThreeLevelMenuPopoverContent( - props: ThreeLevelMenuPopoverContentProps -): React.ReactElement { - const { menuItem, selectedKey } = props; - const [curGroupKey, setCurrentGroupKey] = useState(); - const [activeKeys, setActiveKeys] = useState([]); - - const { relatedGroupKeys, relatedMenuItemKeys } = useMemo(() => { - const selectedKeySet = new Set(selectedKey); - const relatedGroupKeys: string[] = []; - const relatedMenuItemKeys: string[] = []; - - menuItem.items.map((group) => { - let childrenSelected = false; - if (group.type === "group") { - group.items?.map((item) => { - if (selectedKeySet.has(item.key)) { - childrenSelected = true; - relatedMenuItemKeys.push(item.key); - } - }); - } - if (childrenSelected || selectedKeySet.has(group.key)) { - relatedGroupKeys.push(group.key); - } - }); - return { relatedGroupKeys, relatedMenuItemKeys }; - }, [menuItem, selectedKey]); - - useEffect(() => { - if (relatedGroupKeys[0]) { - setCurrentGroupKey(relatedGroupKeys[0]); - setActiveKeys([relatedGroupKeys[0]]); - } else { - const defaultGroupKey = menuItem.items[0].key; - setCurrentGroupKey(defaultGroupKey); - setActiveKeys([defaultGroupKey]); - } - }, []); - - const curGroup = useMemo(() => { - return menuItem.items.find( - (v) => v.key === curGroupKey && v.type === "group" - ) as SidebarMenuGroups; - }, [menuItem, curGroupKey]); - - const debouncedUpdateGroup = useMemo(() => { - return debounce((item: SidebarMenuSimpleItems) => { - setCurrentGroupKey(item.key); - setActiveKeys([item.key]); - }, 200); - }, []); - - return ( -
{ - e.stopPropagation(); - }} - > -
- {menuItem.items - ?.filter((v) => !isSubMenu(v)) - .map((item) => { - return ( -
{ - debouncedUpdateGroup(item as SidebarMenuSimpleItems); - }} - > - {isGroup(item) ? ( -
{item.title}
- ) : ( - renderLinkCom( - item as SidebarMenuSimpleItems, - styles.groupItemText, - { width: "100%" } - ) - )} -
- ); - })} -
- {curGroup && ( -
{ - debouncedUpdateGroup.cancel(); - }} - > -
-
{curGroup.title}
-
-
- {( - curGroup.items?.filter( - (v) => !isSubMenu(v, true) - ) as SidebarMenuSimpleItems[] - ).map((item) => { - return ( -
{ - setActiveKeys([curGroup.key, item.key]); - }} - > - {renderLinkCom(item, styles.menuItemText, { width: "100%" })} -
- ); - })} -
-
- )} -
- ); -} diff --git a/bricks/frame-bricks/src/nw-nav-menu/index.spec.ts b/bricks/frame-bricks/src/nw-nav-menu/index.spec.ts deleted file mode 100644 index 85ada6a93..000000000 --- a/bricks/frame-bricks/src/nw-nav-menu/index.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -import ReactDOM from "react-dom"; -import "./"; - -const spyOnRender = jest - .spyOn(ReactDOM, "render") - .mockImplementation(() => null); -const unmountComponentAtNode = jest - .spyOn(ReactDOM, "unmountComponentAtNode") - .mockImplementation(() => null); - -describe("frame-bricks.nw-nav-menu", () => { - it("should create a custom element", () => { - const element = document.createElement("frame-bricks.nw-nav-menu"); - expect(spyOnRender).not.toBeCalled(); - document.body.appendChild(element); - expect(spyOnRender).toBeCalled(); - document.body.removeChild(element); - expect(unmountComponentAtNode).toBeCalled(); - }); -}); diff --git a/bricks/frame-bricks/src/nw-nav-menu/index.tsx b/bricks/frame-bricks/src/nw-nav-menu/index.tsx deleted file mode 100644 index dbbbb4d9d..000000000 --- a/bricks/frame-bricks/src/nw-nav-menu/index.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import React from "react"; -import ReactDOM from "react-dom"; -import { BrickWrapper, UpdatingElement, property } from "@next-core/brick-kit"; -import { NavMenu } from "./NavMenu"; -import { SidebarSubMenu } from "@next-core/brick-types"; - -/** - * @id frame-bricks.nw-nav-bar - * @author weiliye - * @history - * 1.x.0: 新增构件 `frame-bricks.nw-nav-bar` - * @docKind brick - * @noInheritDoc - */ -export class NavMenuElement extends UpdatingElement { - /** - * @kind SidebarSubMenu - * @required false - * @default - - * @description 菜单项 - */ - @property({ - attribute: false, - }) - menu: SidebarSubMenu; - - /** - * @default - * @required false - * @description 选择菜单 - */ - @property({ - attribute: false, - }) - selectedKeys: string[]; - - /** - * @required false - * @default - - * @description 是否在hover菜单项的时候显示tooltip - */ - @property({ - type: Boolean, - }) - showTooltip: boolean; - - connectedCallback(): void { - // Don't override user's style settings. - // istanbul ignore else - if (!this.style.display) { - this.style.display = "inline-block"; - } - this._render(); - } - - disconnectedCallback(): void { - ReactDOM.unmountComponentAtNode(this); - } - - protected _render(): void { - // istanbul ignore else - if (this.isConnected) { - ReactDOM.render( - - - , - this - ); - } - } -} - -customElements.define("frame-bricks.nw-nav-menu", NavMenuElement); diff --git a/bricks/frame-bricks/src/nw-nav-menu/utils.tsx b/bricks/frame-bricks/src/nw-nav-menu/utils.tsx deleted file mode 100644 index 3cb65a8e3..000000000 --- a/bricks/frame-bricks/src/nw-nav-menu/utils.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import React from "react"; -import { - SidebarMenuSimpleItem, - SidebarMenuGroup, - UseBrickConf, -} from "@next-core/brick-types"; -import { Menu } from "antd"; -import { BrickAsComponent } from "@next-core/brick-kit"; -import { Link, GeneralIcon } from "@next-libs/basic-components"; -import style from "./NavMenu.module.css"; -import classNames from "classnames"; - -type MenuItemBrick = { - useBrick?: UseBrickConf; - instanceId?: string; - divider?: boolean; -}; -export type SidebarMenuSimpleItems = SidebarMenuSimpleItem & MenuItemBrick; -export type SidebarMenuGroups = SidebarMenuGroup & MenuItemBrick; -export type SidebarMenuItem = SidebarMenuSimpleItems | SidebarMenuGroups; - -export function isDivider(item: SidebarMenuItem): boolean { - return item?.divider; -} - -export const renderDivider = (): React.ReactElement => { - return ( - - ); -}; - -export function isGroup(item: SidebarMenuItem): item is SidebarMenuGroups { - return item.type === "group"; -} - -export function isSubMenu( - item: SidebarMenuItem, - groupAsSubMenu?: boolean -): item is SidebarMenuGroups { - return item.type === "subMenu" || (groupAsSubMenu && item.type === "group"); -} - -export const renderBrickCom = (item: SidebarMenuItem): React.ReactElement => { - return ; -}; - -export const renderLinkCom = ( - item: SidebarMenuSimpleItems, - classnames?: string | string[], - linkStyle?: React.CSSProperties, - iconClassname?: string -): React.ReactElement => { - return ( - - {item.icon && ( - - - - )} - {item.text} - - ); -}; - -export const renderSpanCom = ( - item: SidebarMenuGroups, - className?: string -): React.ReactElement => { - return ( - <> - - {item.title} - - - ); -}; diff --git a/bricks/frame-bricks/src/nw-side-bar/SideBar.module.css b/bricks/frame-bricks/src/nw-side-bar/SideBar.module.css deleted file mode 100644 index 4b0214243..000000000 --- a/bricks/frame-bricks/src/nw-side-bar/SideBar.module.css +++ /dev/null @@ -1,182 +0,0 @@ -.sideBarContainer { - position: fixed; - display: flex; - flex-direction: column; - width: var(--side-bar-collapsed-width); - transition: all var(--side-bar-collapse-transition-duration) - var(--side-bar-collapse-transition-timing-function); - - &.dragging { - transition: none; - } - border-right: 1px solid; - border-image: var(--v8-left-sidebar-border-right) 1; - - &::before { - content: ""; - position: absolute; - left: 0; - right: 0; - top: 0; - bottom: 0; - z-index: -1; - background: #2d3c59 !important; - transition: all var(--side-bar-collapse-transition-duration) - var(--side-bar-collapse-transition-timing-function); - } - - .menuTitle { - display: flex; - align-items: center; - margin-top: 14px; - height: 52px; - padding: 0 22px; - - .newMenuItemIcon { - width: 16px; - height: 16px; - vertical-align: middle; - margin-top: 3px; - display: flex; - align-items: center; - justify-content: center; - transition: all var(--side-bar-collapse-transition-duration) - var(--side-bar-collapse-transition-timing-function); - - svg { - font-size: 20px; - color: rgb(87, 104, 156, 1); - } - - > :global(.anticon) { - margin-right: 0; - color: var(--color-normal-text); - line-height: inherit !important; - } - } - - .menuTitlePoint { - width: 16px; - height: 16px; - display: flex; - align-items: center; - justify-content: center; - transition: all var(--side-bar-collapse-transition-duration) - var(--side-bar-collapse-transition-timing-function); - - &::before { - content: ""; - width: 4px; - height: 4px; - margin-right: 7px; - margin-left: 5px; - background: var(--antd-text-color); - border-radius: 50%; - } - } - - .menuTitleText { - flex: 1; - font-size: 16px; - font-weight: 500; - color: #242c4f; - padding: 0; - overflow: hidden; - white-space: nowrap; - text-overflow: ellipsis; - } - } - - .sideBarFooter { - height: 60px; - display: flex; - align-items: center; - justify-content: flex-end; - - .fixedIcon { - display: flex; - justify-content: center; - align-items: center; - margin-right: 8px; - width: 20px; - height: 20px; - visibility: hidden; - opacity: 0; - transition: all var(--side-bar-collapse-transition-duration) - var(--side-bar-collapse-transition-timing-function); - - &:hover path[fill] { - fill: #0071eb; - } - } - } - - .resizeLine { - height: 100%; - width: 2px; - display: inline-block; - position: absolute; - right: -2px; - - &:hover, - &:active { - background-color: rgba(26, 122, 255, 1); - cursor: all-scroll; - } - } -} - -.sideBarContainer.expanded, -.sideBarContainer.hovered { - .menuTitle { - padding: 0 12px; - } - - .menuTitleText { - padding: 0 12px; - } - - .menuTitlePoint { - width: 0; - opacity: 0; - } - - .newMenuItemIcon { - width: 0; - opacity: 0; - } - - .fixedIcon { - visibility: visible; - opacity: 1; - } -} - -.sideBarContainer.hovered { - box-shadow: var(--left-sidebar-shadow); -} - -.sidebarContentContainer { - border-right: 0; - flex: 1; - overflow-y: auto; - box-shadow: 0 -17px 10px -16px rgb(0 0 0 / 8%) inset; - scrollbar-width: none; - - &::-webkit-scrollbar { - width: 0; - background: transparent; - } -} - -.hiddenSidebarContentContainerShadow { - box-shadow: none !important; -} - -:global(html:not([data-theme="dark-v2"]) body.compact-layout) { - .sideBarContainer { - &::before { - background: #f4f5f8; - } - } -} diff --git a/bricks/frame-bricks/src/nw-side-bar/SideBar.spec.tsx b/bricks/frame-bricks/src/nw-side-bar/SideBar.spec.tsx deleted file mode 100644 index 7c4d8955b..000000000 --- a/bricks/frame-bricks/src/nw-side-bar/SideBar.spec.tsx +++ /dev/null @@ -1,105 +0,0 @@ -import React from "react"; -import { shallow, mount } from "enzyme"; -import { ExpandedState, SideBar } from "./SideBar"; -import { SidebarMenu } from "./SidebarMenu"; -import { menuData1 } from "./mockData"; - -import * as brickKit from "@next-core/brick-kit"; -import { act } from "@testing-library/react"; - -jest.spyOn(brickKit, "getHistory").mockReturnValue({ - location: { - pathname: "/page-1", - }, - // eslint-disable-next-line @typescript-eslint/no-empty-function - listen: () => {}, - // eslint-disable-next-line @typescript-eslint/no-empty-function - createHref: () => {}, -} as any); - -jest.mock("@next-libs/storage", () => ({ - JsonStorage: jest.fn(() => { - let mockStorageValue: any; - return { - getItem: () => mockStorageValue, - setItem: (_: string, value: any): void => (mockStorageValue = value), - removeItem: jest.fn(), - }; - }), -})); - -jest.spyOn(window, "requestAnimationFrame").mockImplementation((cb) => { - cb(0); - return 1; -}); - -describe("SideBar", () => { - it("should work when ExpandedState is expanded", () => { - const wrapper = mount( - - ); - - expect(wrapper.find(".sideBarContainer").hasClass("expanded")).toBe(true); - }); - - it("should work with no props", async () => { - const wrapper = mount(); - - await act(async () => { - await (global as any).flushPromises(); - }); - wrapper.update(); - - expect(wrapper.find(SidebarMenu).length).toBe(1); - - expect(wrapper).toBeTruthy(); - }); - - it("should work while customItem was true", () => { - const wrapper = mount( - - ); - - expect(wrapper.find(".ant-menu-item").length).toEqual(1); - }); - - it("should handle resize", () => { - const wrapper = mount( - - ); - const getSideBarWidth = (): string | number => - wrapper.find(".sideBarContainer").prop("style").width; - wrapper.find(".resizeLine").invoke("onMouseDown")({} as any); - act(() => { - window.dispatchEvent( - new MouseEvent("mousemove", { - clientX: 310, - }) - ); - }); - wrapper.update(); - expect(wrapper.find(".sideBarContainer").hasClass("dragging")).toBe(true); - expect(getSideBarWidth()).toBe(310); - act(() => { - window.dispatchEvent(new MouseEvent("mouseup")); - }); - wrapper.update(); - expect(getSideBarWidth()).toBe(310); - expect(wrapper.find(".sideBarContainer").hasClass("dragging")).toBe(false); - }); -}); diff --git a/bricks/frame-bricks/src/nw-side-bar/SideBar.tsx b/bricks/frame-bricks/src/nw-side-bar/SideBar.tsx deleted file mode 100644 index 068bb0210..000000000 --- a/bricks/frame-bricks/src/nw-side-bar/SideBar.tsx +++ /dev/null @@ -1,294 +0,0 @@ -import React, { useState, useEffect, useRef, useMemo } from "react"; -import styles from "./SideBar.module.css"; -import { useTranslation } from "react-i18next"; -import { NS_FRAME_BRICKS, K } from "../i18n/constants"; -import * as SideBarComponent from "./SidebarMenu"; -import { SidebarSubMenu, NavTip } from "@next-core/brick-types"; -import { ReactComponent as FixedSvg } from "../images/fixed.svg"; -import { ReactComponent as ToFixedSvg } from "../images/toFixed.svg"; -import classNames from "classnames"; -import { Tooltip } from "antd"; -import { JsonStorage } from "@next-libs/storage"; -import { SideBarElement } from "./index"; -import ResizeObserver from "rc-resize-observer"; -import { debounce } from "lodash"; -import moment from "moment"; -import { GeneralIcon } from "@next-libs/basic-components"; -import { debounceByAnimationFrame } from "@next-core/brick-utils"; -import { getCssPropertyValue } from "@next-core/brick-kit"; - -interface SideBarProps { - menu?: SidebarSubMenu; - wrapperDOM?: SideBarElement; - expandedState?: ExpandedState; - hiddenFixedIcon?: boolean; - onSideBarFixed?: (isFiexed: boolean) => void; - onSideBarResize?: (value: string) => void; -} - -export enum ExpandedState { - Collapsed = "collapsed", - Hovered = "hovered", - Expanded = "expanded", -} - -export const SIDE_BAR_HAS_BEEN_USED = "side-bar-has-been-used"; -export const SIDE_BAR_EXPAND_STATE = "side-bar-expand-state"; -const DEPRECATED_RESIZE_WIDTH = "resize-width"; -export const SIDE_BAR_RESIZE_WIDTH = "side-bar-resize-width"; -const sideBarWidth = - parseInt(getCssPropertyValue("--side-bar-width"), 10) || 208; -const sideBarCollapsedWidth = - parseInt(getCssPropertyValue("--side-bar-collapsed-width"), 10) || 60; - -export function SideBar(props: SideBarProps): React.ReactElement { - const { - menu = {} as SidebarSubMenu, - onSideBarFixed, - onSideBarResize, - hiddenFixedIcon, - wrapperDOM, - } = props; - const contentContainerRef = useRef(); - const storage = React.useMemo(() => new JsonStorage(localStorage), []); - const [resizeWidth, setResizeWidth] = useState(() => { - // Use parseInt to compatible non-number types - let width = parseInt( - storage.getItem(SIDE_BAR_RESIZE_WIDTH) || - storage.getItem(DEPRECATED_RESIZE_WIDTH), - 10 - ); - if (width < sideBarWidth || Number.isNaN(width)) { - width = sideBarWidth; - } - storage.removeItem(DEPRECATED_RESIZE_WIDTH); - return width; - }); - const [dragging, setDragging] = useState(); - const [sideBarWidthTransitioning, setSideBarWidthTransitioning] = - useState(); - const [expandedState, setExpandedState] = useState( - ExpandedState.Expanded - ); - const [showFirstUsedTooltip, setShowFirstUsedTooltip] = useState( - !storage.getItem(SIDE_BAR_HAS_BEEN_USED) - ); - const [tipList, setTipList] = useState([]); - - const [showContentShadow, setShowContentShadow] = useState(true); - const [sidebarContentHeight, setSidebarContentHeight] = useState(0); - const { t } = useTranslation(NS_FRAME_BRICKS); - // istanbul ignore next - const handleFixedIconClick = (): void => { - setShowFirstUsedTooltip(false); - storage.setItem(SIDE_BAR_HAS_BEEN_USED, true); - - const currentState = - expandedState === ExpandedState.Expanded - ? ExpandedState.Collapsed - : ExpandedState.Expanded; - - setExpandedState(currentState); - storage.setItem(SIDE_BAR_EXPAND_STATE, currentState); - onSideBarFixed?.(currentState === ExpandedState.Expanded); - }; - - const handleMouseEnter = (): void => { - expandedState !== ExpandedState.Expanded && - setSideBarWidthTransitioning(true); - setExpandedState( - expandedState === ExpandedState.Expanded - ? expandedState - : ExpandedState.Hovered - ); - }; - - const handleMouseLeave = (): void => { - expandedState !== ExpandedState.Expanded && - setSideBarWidthTransitioning(true); - setExpandedState( - expandedState === ExpandedState.Expanded - ? expandedState - : ExpandedState.Collapsed - ); - }; - - useEffect(() => { - storage.setItem(SIDE_BAR_RESIZE_WIDTH, resizeWidth); - }, [resizeWidth]); - - useEffect(() => { - switch (expandedState) { - case ExpandedState.Expanded: { - wrapperDOM && (wrapperDOM.style.width = resizeWidth + "px"); - break; - } - case ExpandedState.Hovered: - case ExpandedState.Collapsed: - default: { - wrapperDOM && - (wrapperDOM.style.width = "var(--side-bar-collapsed-width)"); - } - } - }, [wrapperDOM, expandedState, resizeWidth]); - // istanbul ignore next - useEffect(() => { - const currentDom = contentContainerRef.current; - - const handleScroll = (e: any) => { - if ( - e.target.scrollHeight - e.target.scrollTop - e.target.offsetHeight <= - 0 - ) { - setShowContentShadow(false); - } else { - setShowContentShadow(true); - } - }; - currentDom?.addEventListener("scroll", handleScroll); - return () => { - currentDom?.removeEventListener("scroll", handleScroll); - }; - }, [contentContainerRef]); - - const handleResizeDown = (e: any) => { - setDragging(true); - - // Prevent text selection when dragging - if (e.cancelable) { - e.preventDefault(); - } - - const drag = debounceByAnimationFrame((e: any) => { - const width = e.clientX >= sideBarWidth ? e.clientX : sideBarWidth; - - setResizeWidth(width); - onSideBarResize?.(`${width}px`); - }); - const dragEnd = (e: any) => { - setDragging(false); - e.preventDefault(); - - window.removeEventListener("mousemove", drag); - window.removeEventListener("mouseup", dragEnd); - }; - - window.addEventListener("mousemove", drag, { passive: true }); - window.addEventListener("mouseup", dragEnd); - }; - - useEffect(() => { - const currentDom = contentContainerRef.current; - if (currentDom.scrollHeight <= currentDom.clientHeight) { - setShowContentShadow(false); - } else { - setShowContentShadow(true); - } - }, [contentContainerRef, sidebarContentHeight]); - // istanbul ignore next - const handleShowTips = ((e: CustomEvent): void => { - const list = (e.detail ?? []).filter((item) => { - const isTipClosing = - item.closable && - storage.getItem(item.tipKey) && - moment().unix() <= storage.getItem(item.tipKey); - return !isTipClosing; - }); - const top = `calc(var(--app-bar-height) + ${list.length * 32}px)`; - - wrapperDOM.style.top = top; - setTipList(list); - }) as EventListener; - - React.useEffect(() => { - window.addEventListener("app.bar.tips", handleShowTips); - return () => { - window.removeEventListener("app.bar.tips", handleShowTips); - }; - }, []); - - const sidebarHeight = useMemo(() => { - return `calc(100vh - var(--app-bar-height) + 1px - ${ - tipList.length * 32 - }px)`; - }, [tipList]); - - return ( -
{ - if (e.target === e.currentTarget && e.propertyName === "width") { - setSideBarWidthTransitioning(false); - } - }} - data-testid="side-bar" - > - { - setSidebarContentHeight(height); - }, 100)} - > -
- -
-
-
- {!hiddenFixedIcon && ( - - {/* - {expandedState === ExpandedState.Expanded ? ( - - ) : ( - - )} - */} - - )} -
- {expandedState === ExpandedState.Expanded && ( -
- )} -
- ); -} diff --git a/bricks/frame-bricks/src/nw-side-bar/SidebarMenu.module.css b/bricks/frame-bricks/src/nw-side-bar/SidebarMenu.module.css deleted file mode 100644 index c83177334..000000000 --- a/bricks/frame-bricks/src/nw-side-bar/SidebarMenu.module.css +++ /dev/null @@ -1,96 +0,0 @@ -.menuContainer { - &:global(.ant-menu) { - background: #2d3c59; - border-right: none !important; - - :global(.ant-menu-submenu-title) { - margin: 0; - } - > :global(.ant-menu-submenu) { - color: hsla(0, 0%, 100%, 0.7) !important; - :global(.ant-menu-submenu-arrow) { - color: hsla(0, 0%, 100%, 0.7) !important; - } - } - > :global(.ant-menu-item) a { - color: hsla(0, 0%, 100%, 0.7) !important; - } - > :global(.ant-menu-submenu), - > :global(.ant-menu-item) { - margin: 0 !important; - .iconStyle { - color: hsla(0, 0%, 100%, 0.7) !important; - } - } - - > :global(.ant-menu-submenu-active), - > :global(.ant-menu-submenu-selected) { - :global(.ant-menu-submenu-title) { - color: #ffffff !important; - - :global(.ant-menu-submenu-arrow) { - color: #ffffff !important; - } - } - - .iconStyle { - color: #ffffff !important; - } - } - - :global(.ant-menu-submenu-title):hover { - color: #ffffff !important; - } - :global(.ant-menu-submenu-title):active { - background: #344561 !important; - } - :global(.ant-menu-submenu-open) { - background: #344561 !important; - } - > :global(.ant-menu-item-active), - > :global(.ant-menu-item-selected) { - background: #344561 !important; - a { - color: #ffffff !important; - .iconStyle { - color: #ffffff !important; - } - } - } - :global(.ant-menu-item-selected)::after { - border-right: 2px solid #3aa2eb !important; - } - :global(.ant-menu-item-only-child):active { - background: #344561 !important; - } - } - - :global(.ant-menu-submenu) { - :global(.ant-menu) { - background: #344561 !important; - } - :global(.ant-menu-item) { - margin: 0 !important; - } - a { - color: hsla(0, 0%, 100%, 0.7) !important; - } - :global(.ant-menu-item-active) a { - color: #ffffff !important; - } - - :global(.ant-menu-item-active):active { - background: #344561 !important; - } - - :global(.ant-menu-item-selected) { - background: #3aa2eb !important; - a { - color: #ffffff !important; - } - } - :global(.ant-menu-item-selected)::after { - border-right: none !important; - } - } -} diff --git a/bricks/frame-bricks/src/nw-side-bar/SidebarMenu.spec.tsx b/bricks/frame-bricks/src/nw-side-bar/SidebarMenu.spec.tsx deleted file mode 100644 index 25c6b1b62..000000000 --- a/bricks/frame-bricks/src/nw-side-bar/SidebarMenu.spec.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import React from "react"; -import { shallow, mount } from "enzyme"; -import { SidebarMenu } from "./SidebarMenu"; -import { createHistory } from "@next-core/brick-kit"; -import { GeneralIcon } from "@next-libs/basic-components"; -import { Menu } from "antd"; -import { menuData1, menuData2 } from "./mockData"; - -createHistory(); - -describe("SidebarMenu", () => { - it("should render GeneralIcon correctly", () => { - const wrapper = mount( - - ); - // Menu.Item in Menu.SubMenu should not render GeneralIcon - // Menu.SubMenu only render title's GeneralIcon - expect(wrapper.find(Menu.SubMenu).find(GeneralIcon)).toHaveLength(1); - expect(wrapper.find(GeneralIcon)).toHaveLength(6); // 3 + 2 + 1 - }); - - it("should work", () => { - const wrapper = mount(); - expect(wrapper.find(GeneralIcon)).toHaveLength(3); - }); -}); diff --git a/bricks/frame-bricks/src/nw-side-bar/SidebarMenu.tsx b/bricks/frame-bricks/src/nw-side-bar/SidebarMenu.tsx deleted file mode 100644 index 033a74dc8..000000000 --- a/bricks/frame-bricks/src/nw-side-bar/SidebarMenu.tsx +++ /dev/null @@ -1,213 +0,0 @@ -/* eslint-disable @typescript-eslint/no-use-before-define */ -import React, { useEffect, useState } from "react"; -import { Menu } from "antd"; -import { isEmpty, uniq } from "lodash"; -import { UnregisterCallback, Location } from "history"; -import { getHistory, getRuntime } from "@next-core/brick-kit"; -import { - SidebarMenuSimpleItem, - SidebarMenuItem, - SidebarMenuGroup, -} from "@next-core/brick-types"; -import classNames from "classnames"; -import { - GeneralIcon, - Link, - initMenuItemAndMatchCurrentPathKeys, -} from "@next-libs/basic-components"; -import style from "./SidebarMenu.module.css"; - -interface SidebarMenuProps { - menuItems: SidebarMenuItem[]; - collapsed?: boolean; - sideBarWidthTransitioning?: boolean; -} - -function isGroup(item: SidebarMenuItem): item is SidebarMenuGroup { - return item.type === "group"; -} - -function isSubMenu(item: SidebarMenuItem): item is SidebarMenuGroup { - return item.type === "subMenu"; -} - -export function SidebarMenu(props: SidebarMenuProps): React.ReactElement { - const { menuItems, collapsed, sideBarWidthTransitioning } = props; - - const history = getHistory(); - const [location, setLocation] = useState(history.location); - const unlisten: UnregisterCallback = history.listen((location) => { - setLocation(location); - }); - const { pathname, search } = location; - const showTextUi = React.useMemo( - () => getRuntime()?.getFeatureFlags()["show-sidebar-text-ui"], - [] - ); - - let { selectedKeys, openedKeys } = initMenuItemAndMatchCurrentPathKeys( - menuItems, - pathname, - search, - "" - ); - if (collapsed) { - openedKeys = []; - } - - useEffect(() => { - return unlisten; - }, []); - - const renderSimpleMenuItem = ( - item: SidebarMenuSimpleItem, - showEmptyIcon?: boolean, - iconClassname?: string - ): React.ReactNode => { - return ( - - - {showEmptyIcon ? ( - - ) : ( - item.icon && ( - - - - ) - )} - - {item.text} - - - - ); - }; - - const renderGroupMenu = ( - item: SidebarMenuGroup, - showEmptyIcon?: boolean - ): React.ReactNode => { - if (item.items?.length > 0) { - return ( - - - - {item.title} - - - } - > - {item.items.map((innerItem) => - renderMenuItem(innerItem, showEmptyIcon) - )} - - ); - } - }; - - const renderSubMenu = ( - item: SidebarMenuGroup, - iconClassName: string - ): React.ReactNode => { - if (item.items?.length > 0) { - return ( - - {item.icon && ( - - - - )} - - {item.title} - - - } - > - {item.items.map((innerItem) => renderMenuItem(innerItem, true))} - - ); - } - }; - - const renderMenuItem = ( - item: SidebarMenuItem, - showEmptyIcon?: boolean - ): React.ReactNode => { - return isSubMenu(item) - ? renderSubMenu(item, style.iconStyle) - : isGroup(item) - ? renderGroupMenu(item, showEmptyIcon) - : renderSimpleMenuItem(item, showEmptyIcon, style.iconStyle); - }; - - return ( - - {menuItems.map((item) => renderMenuItem(item))} - - ); -} diff --git a/bricks/frame-bricks/src/nw-side-bar/index.spec.ts b/bricks/frame-bricks/src/nw-side-bar/index.spec.ts deleted file mode 100644 index cfeeb0b67..000000000 --- a/bricks/frame-bricks/src/nw-side-bar/index.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -import ReactDOM from "react-dom"; -import "./"; - -const spyOnRender = jest - .spyOn(ReactDOM, "render") - .mockImplementation(() => null); -const unmountComponentAtNode = jest - .spyOn(ReactDOM, "unmountComponentAtNode") - .mockImplementation(() => null); - -describe("frame-bricks.side-bar", () => { - it("should create a custom element", () => { - const element = document.createElement("frame-bricks.nw-side-bar"); - expect(spyOnRender).not.toBeCalled(); - document.body.appendChild(element); - expect(spyOnRender).toBeCalled(); - document.body.removeChild(element); - expect(unmountComponentAtNode).toBeCalled(); - }); -}); diff --git a/bricks/frame-bricks/src/nw-side-bar/index.tsx b/bricks/frame-bricks/src/nw-side-bar/index.tsx deleted file mode 100644 index c75961aa4..000000000 --- a/bricks/frame-bricks/src/nw-side-bar/index.tsx +++ /dev/null @@ -1,114 +0,0 @@ -import React from "react"; -import ReactDOM from "react-dom"; -import { - BrickWrapper, - property, - UpdatingElement, - event, - EventEmitter, -} from "@next-core/brick-kit"; -import { ExpandedState, SideBar } from "./SideBar"; -import { SidebarSubMenu } from "@next-core/brick-types"; - -/** - * @id frame-bricks.side-bar - * @author nlicroshan - * @history - * 1.x.0: 新增构件 `frame-bricks.side-bar` - * @docKind brick - * @noInheritDoc - */ -export class SideBarElement extends UpdatingElement { - /** - * @kind SidebarSubMenu - * @required false - * @default - - * @description 菜单项 - */ - @property({ - attribute: false, - }) - menu: SidebarSubMenu; - - /** - * @kind ExpandedState - * @required false - * @default collapsed - * @description 展开状态,默认折叠收起, 数据会做通过 localStorage 存储 - */ - @property({ - attribute: false, - }) - expandedState: ExpandedState; - - /** - * @default false - * @required false - * @description 是否隐藏固定按钮 - */ - @property({ - type: Boolean, - }) - hiddenFixedIcon: boolean; - - /** - * @detail - * @description - */ - @event({ type: "side.bar.fixed" }) - _handleSideBarFixed: EventEmitter; - handleSideBarFixed = (isFixed: boolean): void => { - this._handleSideBarFixed.emit(isFixed); - }; - - /** - * @detail - * @description - */ - @event({ type: "side.bar.resize" }) - _handleSideBarResize: EventEmitter; - // istanbul ignore next - handleSideBarResize = (value: string): void => { - this._handleSideBarResize.emit(value); - }; - - connectedCallback(): void { - // Don't override user's style settings. - // istanbul ignore else - if (!this.style.display) { - this.style.display = "block"; - this.style.transition = - "width var(--side-bar-collapse-transition-duration) var(--side-bar-collapse-transition-timing-function)"; - this.style.position = "fixed"; - this.style.left = "0px"; - this.style.top = "var(--app-bar-height)"; - this.style.zIndex = "999"; - } - this._render(); - } - - disconnectedCallback(): void { - ReactDOM.unmountComponentAtNode(this); - } - - protected _render(): void { - // istanbul ignore else - if (this.isConnected) { - ReactDOM.render( - - - , - this - ); - } - } -} - -customElements.define("frame-bricks.nw-side-bar", SideBarElement); diff --git a/bricks/frame-bricks/src/nw-side-bar/mockData.ts b/bricks/frame-bricks/src/nw-side-bar/mockData.ts deleted file mode 100644 index 246b4e45c..000000000 --- a/bricks/frame-bricks/src/nw-side-bar/mockData.ts +++ /dev/null @@ -1,273 +0,0 @@ -import { SidebarSubMenu } from "@next-core/brick-types"; - -export const menuData1 = { - title: "二级菜单标题", - link: "/nlicro-test/aaaa", - menuItems: [ - { - text: "item1", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - text: "item2", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - text: "item3", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - type: "group", - title: "group", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - items: [ - { - text: "group-item1", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - text: "group-item2", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - ], - }, - { - type: "group", - title: "empty-group-should-not-render", - items: [], - }, - { - type: "subMenu", - title: "empty-subMenu-should-not-render", - items: [], - }, - { - type: "subMenu", - title: "subMenu", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - items: [ - { - text: "subMenu-item1", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - text: "subMenu-item2", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - ], - }, - ], - defaultCollapsedBreakpoint: 0, -} as SidebarSubMenu; - -export const menuData2 = { - title: "二级菜单标题", - link: "/nlicro-test/aaaa", - menuItems: [ - { - type: "subMenu", - title: "subMenu", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - items: [ - { - type: "group", - title: "group1", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - items: [ - { - text: "subMenu-group-item11", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - text: "subMenu-group-item12", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - ], - }, - { - type: "group", - title: "group2", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - items: [ - { - text: "subMenu-group-item21", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - text: "subMenu-group-item22", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - ], - }, - ], - }, - { - type: "group", - title: "group", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - items: [ - { - type: "subMenu", - title: "subMenu1", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - items: [ - { - text: "group-subMenu-item11", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - text: "group-subMenu-item12", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - ], - }, - { - type: "subMenu", - title: "subMenu2", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - items: [ - { - text: "group-subMenu-item21", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - { - text: "group-subMenu-item22", - type: "default", - icon: { - color: "geekblue", - icon: "anchor", - lib: "fa", - prefix: "fas", - }, - }, - ], - }, - ], - }, - ], - defaultCollapsedBreakpoint: 0, -} as SidebarSubMenu;