From 1372bf784fcdb36205a6bdb25d1d377e957aaff0 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Thu, 11 Jan 2024 13:26:34 +0800 Subject: [PATCH] feat: app sidebar support collapse (#1997) --- web/app/components/app-sidebar/basic.tsx | 4 +- web/app/components/app-sidebar/index.tsx | 70 +++++++++++++++++-- web/app/components/app-sidebar/navLink.tsx | 8 ++- .../vender/line/layout/align-left-01.svg | 5 ++ .../vender/line/layout/align-right-01.svg | 5 ++ .../src/vender/line/layout/AlignLeft01.json | 39 +++++++++++ .../src/vender/line/layout/AlignLeft01.tsx | 16 +++++ .../src/vender/line/layout/AlignRight01.json | 39 +++++++++++ .../src/vender/line/layout/AlignRight01.tsx | 16 +++++ .../icons/src/vender/line/layout/index.ts | 2 + 10 files changed, 193 insertions(+), 11 deletions(-) create mode 100644 web/app/components/base/icons/assets/vender/line/layout/align-left-01.svg create mode 100644 web/app/components/base/icons/assets/vender/line/layout/align-right-01.svg create mode 100644 web/app/components/base/icons/src/vender/line/layout/AlignLeft01.json create mode 100644 web/app/components/base/icons/src/vender/line/layout/AlignLeft01.tsx create mode 100644 web/app/components/base/icons/src/vender/line/layout/AlignRight01.json create mode 100644 web/app/components/base/icons/src/vender/line/layout/AlignRight01.tsx diff --git a/web/app/components/app-sidebar/basic.tsx b/web/app/components/app-sidebar/basic.tsx index 610e770133..36bcdd9e7d 100644 --- a/web/app/components/app-sidebar/basic.tsx +++ b/web/app/components/app-sidebar/basic.tsx @@ -15,7 +15,7 @@ export type IAppBasicProps = { hoverTip?: string textStyle?: { main?: string; extra?: string } isExtraInLine?: boolean - mode?: 'expand' | 'collapse' + mode?: string } const ApiSvg = @@ -56,7 +56,7 @@ const ICON_MAP = { notion: , } -export default function AppBasic({ icon, icon_background, name, type, hoverTip, textStyle, mode = 'expand', iconType = 'app', isExtraInLine }: IAppBasicProps) { +export default function AppBasic({ icon, icon_background, name, type, hoverTip, textStyle, mode = 'expand', iconType = 'app' }: IAppBasicProps) { return (
{icon && icon_background && iconType === 'app' && ( diff --git a/web/app/components/app-sidebar/index.tsx b/web/app/components/app-sidebar/index.tsx index 2ad50c4055..1c6b844684 100644 --- a/web/app/components/app-sidebar/index.tsx +++ b/web/app/components/app-sidebar/index.tsx @@ -1,8 +1,12 @@ -import React from 'react' +import React, { useCallback, useState } from 'react' import NavLink from './navLink' import type { NavIcon } from './navLink' import AppBasic from './basic' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' +import { + AlignLeft01, + AlignRight01, +} from '@/app/components/base/icons/src/vender/line/layout' export type IAppDetailNavProps = { iconType?: 'app' | 'dataset' | 'notion' @@ -20,23 +24,77 @@ export type IAppDetailNavProps = { } const AppDetailNav = ({ title, desc, icon, icon_background, navigation, extraInfo, iconType = 'app' }: IAppDetailNavProps) => { + const localeMode = localStorage.getItem('app-detail-collapse-or-expand') || 'expand' const media = useBreakpoints() const isMobile = media === MediaType.mobile const mode = isMobile ? 'collapse' : 'expand' + const [modeState, setModeState] = useState(isMobile ? mode : localeMode) + const expand = modeState === 'expand' + + const handleToggle = useCallback(() => { + setModeState((prev) => { + const next = prev === 'expand' ? 'collapse' : 'expand' + localStorage.setItem('app-detail-collapse-or-expand', next) + return next + }) + }, []) return ( -
-
- +
+
+
-
) } diff --git a/web/app/components/app-sidebar/navLink.tsx b/web/app/components/app-sidebar/navLink.tsx index 4cfec7e848..d1df610d5e 100644 --- a/web/app/components/app-sidebar/navLink.tsx +++ b/web/app/components/app-sidebar/navLink.tsx @@ -18,7 +18,7 @@ export type NavLinkProps = { selected: NavIcon normal: NavIcon } - mode?: 'expand' | 'collapse' + mode?: string } export default function NavLink({ @@ -45,13 +45,15 @@ export default function NavLink({ href={href} className={classNames( isActive ? 'bg-primary-50 text-primary-600 font-semibold' : 'text-gray-700 hover:bg-gray-100 hover:text-gray-700', - 'group flex items-center rounded-md px-2 py-2 text-sm font-normal', + 'group flex items-center h-9 rounded-md py-2 text-sm font-normal', + mode === 'expand' ? 'px-3' : 'px-2.5', )} >