diff --git a/packages/frontend/component/src/components/app-sidebar/index.css.ts b/packages/frontend/component/src/components/app-sidebar/index.css.ts index c1836aebc8..8691d0352b 100644 --- a/packages/frontend/component/src/components/app-sidebar/index.css.ts +++ b/packages/frontend/component/src/components/app-sidebar/index.css.ts @@ -1,21 +1,12 @@ -import { baseTheme } from '@toeverything/theme'; import type { ComplexStyleRule } from '@vanilla-extract/css'; -import { createVar, style } from '@vanilla-extract/css'; +import { style } from '@vanilla-extract/css'; export const floatingMaxWidth = 768; -export const navWidthVar = createVar('nav-width'); export const navWrapperStyle = style({ - vars: { - [navWidthVar]: '256px', - }, - position: 'relative', - width: navWidthVar, - minWidth: navWidthVar, - height: '100%', zIndex: 3, paddingBottom: '8px', - backgroundColor: 'transparent', + backgroundColor: 'var(--affine-background-primary-color)', '@media': { print: { display: 'none', @@ -23,23 +14,7 @@ export const navWrapperStyle = style({ }, }, selectors: { - '&[data-is-floating="true"]': { - position: 'absolute', - width: `calc(${navWidthVar})`, - zIndex: 4, - backgroundColor: 'var(--affine-background-primary-color)', - }, - '&[data-open="false"]': { - marginLeft: `calc(${navWidthVar} * -1)`, - }, - '&[data-enable-animation="true"]': { - transition: 'margin-left .3s .05s, width .3s .05s', - }, - '&[data-is-floating="false"].has-background': { - backgroundColor: 'var(--affine-white-60)', - borderRight: '1px solid var(--affine-border-color)', - }, - '&.has-border': { + '&[data-has-border=true]': { borderRight: '1px solid var(--affine-border-color)', }, }, @@ -63,7 +38,6 @@ export const navStyle = style({ height: '100%', display: 'flex', flexDirection: 'column', - zIndex: parseInt(baseTheme.zIndexModal), }); export const navHeaderStyle = style({ diff --git a/packages/frontend/component/src/components/app-sidebar/index.tsx b/packages/frontend/component/src/components/app-sidebar/index.tsx index 69bc06f419..4292c0c042 100644 --- a/packages/frontend/component/src/components/app-sidebar/index.tsx +++ b/packages/frontend/component/src/components/app-sidebar/index.tsx @@ -1,18 +1,16 @@ -import { assignInlineVars } from '@vanilla-extract/dynamic'; -import clsx from 'clsx'; import { useAtom, useAtomValue } from 'jotai'; import { debounce } from 'lodash-es'; import type { PropsWithChildren, ReactElement } from 'react'; -import { useEffect, useRef, useState } from 'react'; +import { useEffect } from 'react'; import { Skeleton } from '../../ui/skeleton'; +import { ResizePanel } from '../resize-panel'; import { fallbackHeaderStyle, fallbackStyle } from './fallback.css'; import { floatingMaxWidth, navBodyStyle, navHeaderStyle, navStyle, - navWidthVar, navWrapperStyle, sidebarFloatMaskStyle, } from './index.css'; @@ -23,7 +21,6 @@ import { appSidebarResizingAtom, appSidebarWidthAtom, } from './index.jotai'; -import { ResizeIndicator } from './resize-indicator'; import type { SidebarHeaderProps } from './sidebar-header'; import { SidebarHeader } from './sidebar-header'; @@ -33,30 +30,19 @@ export type AppSidebarProps = PropsWithChildren< } >; -function useEnableAnimation() { - const [enable, setEnable] = useState(false); - useEffect(() => { - window.setTimeout(() => { - setEnable(true); - }, 500); - }, []); - return enable; -} - export type History = { stack: string[]; current: number; }; +const MAX_WIDTH = 480; +const MIN_WIDTH = 256; + export function AppSidebar(props: AppSidebarProps): ReactElement { const [open, setOpen] = useAtom(appSidebarOpenAtom); - const appSidebarWidth = useAtomValue(appSidebarWidthAtom); - const [appSidebarFloating, setAppSidebarFloating] = useAtom( - appSidebarFloatingAtom - ); - - const isResizing = useAtomValue(appSidebarResizingAtom); - const navRef = useRef(null); + const [width, setWidth] = useAtom(appSidebarWidthAtom); + const [floating, setFloating] = useAtom(appSidebarFloatingAtom); + const [resizing, setResizing] = useAtom(appSidebarResizingAtom); useEffect(() => { function onResize() { @@ -64,7 +50,7 @@ export function AppSidebar(props: AppSidebarProps): ReactElement { `(max-width: ${floatingMaxWidth}px)` ).matches; const isOverflowWidth = window.matchMedia( - `(max-width: ${appSidebarWidth / 0.4}px)` + `(max-width: ${width / 0.4}px)` ).matches; const isFloating = isFloatingMaxWidth || isOverflowWidth; if ( @@ -75,7 +61,7 @@ export function AppSidebar(props: AppSidebarProps): ReactElement { // so that the sidebar can be closed on mobile by default setOpen(!isFloating); } - setAppSidebarFloating(isFloating && !!open); + setFloating(isFloating && !!open); } const dOnResize = debounce(onResize, 50); @@ -83,33 +69,34 @@ export function AppSidebar(props: AppSidebarProps): ReactElement { return () => { window.removeEventListener('resize', dOnResize); }; - }, [appSidebarWidth, open, setAppSidebarFloating, setOpen]); - - // disable animation to avoid UI flash - const enableAnimation = useEnableAnimation(); + }, [open, setFloating, setOpen, width]); + const transparent = environment.isDesktop && !props.hasBackground; const isMacosDesktop = environment.isDesktop && environment.isMacOs; + const hasRightBorder = !environment.isDesktop || !transparent; return ( <> -
-
+
setOpen(false)} /> @@ -132,15 +118,12 @@ export function AppSidebar(props: AppSidebarProps): ReactElement { } export const AppSidebarFallback = (): ReactElement | null => { - const appSidebarWidth = useAtomValue(appSidebarWidthAtom); + const width = useAtomValue(appSidebarWidthAtom); return (