mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat(component): improve fallback skeleton (#2323)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { style } from '@vanilla-extract/css';
|
||||
|
||||
export const fallbackStyle = style({
|
||||
margin: '0 2px',
|
||||
height: '100%',
|
||||
});
|
||||
|
||||
export const fallbackHeaderStyle = style({
|
||||
padding: '0 6px',
|
||||
height: '58px',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
gap: '8px',
|
||||
});
|
||||
18
packages/component/src/components/app-sidebar/fallback.tsx
Normal file
18
packages/component/src/components/app-sidebar/fallback.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Skeleton } from '@mui/material';
|
||||
import type { ReactElement } from 'react';
|
||||
|
||||
import { fallbackHeaderStyle, fallbackStyle } from './fallback.css';
|
||||
import { AppSidebar } from './index';
|
||||
|
||||
export const AppSidebarFallback = (): ReactElement | null => {
|
||||
return (
|
||||
<AppSidebar>
|
||||
<div className={fallbackStyle}>
|
||||
<div className={fallbackHeaderStyle}>
|
||||
<Skeleton variant="circular" width={40} height={40} />
|
||||
<Skeleton variant="rectangular" width={150} height={40} />
|
||||
</div>
|
||||
</div>
|
||||
</AppSidebar>
|
||||
);
|
||||
};
|
||||
@@ -2,9 +2,15 @@ import { IconButton } from '@affine/component';
|
||||
import { SidebarIcon } from '@blocksuite/icons';
|
||||
import type { Meta, StoryFn } from '@storybook/react';
|
||||
import { useAtom } from 'jotai';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { AppSidebar, appSidebarOpenAtom, ResizeIndicator } from '.';
|
||||
import {
|
||||
AppSidebar,
|
||||
AppSidebarFallback,
|
||||
appSidebarOpenAtom,
|
||||
ResizeIndicator,
|
||||
} from '.';
|
||||
import { navHeaderStyle, sidebarButtonStyle } from './index.css';
|
||||
|
||||
export default {
|
||||
@@ -12,42 +18,61 @@ export default {
|
||||
component: AppSidebar,
|
||||
} satisfies Meta;
|
||||
|
||||
const Container = ({ children }: PropsWithChildren) => (
|
||||
<main
|
||||
style={{
|
||||
position: 'relative',
|
||||
width: '100vw',
|
||||
height: '600px',
|
||||
overflow: 'hidden',
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</main>
|
||||
);
|
||||
const Main = () => {
|
||||
const [open, setOpen] = useAtom(appSidebarOpenAtom);
|
||||
return (
|
||||
<div>
|
||||
<div className={navHeaderStyle}>
|
||||
{!open && (
|
||||
<IconButton
|
||||
className={sidebarButtonStyle}
|
||||
onClick={() => {
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
<SidebarIcon width={24} height={24} />
|
||||
</IconButton>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
const Footer = () => <div>Add Page</div>;
|
||||
|
||||
export const Default: StoryFn = () => {
|
||||
const [open, setOpen] = useAtom(appSidebarOpenAtom);
|
||||
const [ref, setRef] = useState<HTMLElement | null>(null);
|
||||
return (
|
||||
<>
|
||||
<main
|
||||
style={{
|
||||
position: 'relative',
|
||||
width: '100vw',
|
||||
height: '600px',
|
||||
overflow: 'hidden',
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
}}
|
||||
>
|
||||
<Container>
|
||||
<AppSidebar footer={<Footer />} ref={setRef}>
|
||||
Test
|
||||
</AppSidebar>
|
||||
<ResizeIndicator targetElement={ref} />
|
||||
<div>
|
||||
<div className={navHeaderStyle}>
|
||||
{!open && (
|
||||
<IconButton
|
||||
className={sidebarButtonStyle}
|
||||
onClick={() => {
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
<SidebarIcon width={24} height={24} />
|
||||
</IconButton>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<Main />
|
||||
</Container>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const Fallback = () => {
|
||||
return (
|
||||
<Container>
|
||||
<AppSidebarFallback />
|
||||
<Main />
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -151,5 +151,6 @@ export const AppSidebar = forwardRef<HTMLElement, AppSidebarProps>(
|
||||
}
|
||||
);
|
||||
|
||||
export { AppSidebarFallback } from './fallback';
|
||||
export type { ResizeIndicatorProps } from './resize-indicator';
|
||||
export { ResizeIndicator } from './resize-indicator';
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
import { style } from '@vanilla-extract/css';
|
||||
|
||||
export const blockSuiteEditorStyle = style({
|
||||
padding: '0 1rem',
|
||||
maxWidth: 'var(--affine-editor-width)',
|
||||
margin: '0 2rem',
|
||||
padding: '0 24px',
|
||||
});
|
||||
|
||||
export const blockSuiteEditorHeaderStyle = style({
|
||||
marginTop: '40px',
|
||||
marginBottom: '40px',
|
||||
});
|
||||
|
||||
@@ -12,7 +12,10 @@ import { createPortal } from 'react-dom';
|
||||
import type { FallbackProps } from 'react-error-boundary';
|
||||
import { ErrorBoundary } from 'react-error-boundary';
|
||||
|
||||
import { blockSuiteEditorStyle } from './index.css';
|
||||
import {
|
||||
blockSuiteEditorHeaderStyle,
|
||||
blockSuiteEditorStyle,
|
||||
} from './index.css';
|
||||
|
||||
export type EditorProps = {
|
||||
page: Page;
|
||||
@@ -136,10 +139,11 @@ const BlockSuiteErrorFallback = (
|
||||
export const BlockSuiteFallback = memo(function BlockSuiteFallback() {
|
||||
return (
|
||||
<div className={blockSuiteEditorStyle}>
|
||||
<Skeleton animation="wave" height={60} />
|
||||
{Array.from({ length: 10 }).map((_, index) => (
|
||||
<Skeleton animation="wave" height={30} key={index} />
|
||||
))}
|
||||
<Skeleton
|
||||
className={blockSuiteEditorHeaderStyle}
|
||||
animation="wave"
|
||||
height={50}
|
||||
/>
|
||||
<Skeleton animation="wave" height={30} width="40%" />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { clsx } from 'clsx';
|
||||
import type { PropsWithChildren, ReactElement } from 'react';
|
||||
|
||||
import { AppSidebarFallback } from '../app-sidebar';
|
||||
import { appStyle, mainContainerStyle, toolStyle } from './index.css';
|
||||
|
||||
export type WorkspaceRootProps = PropsWithChildren<{
|
||||
@@ -32,3 +33,12 @@ export const MainContainer = (props: MainContainerProps): ReactElement => {
|
||||
export const ToolContainer = (props: PropsWithChildren): ReactElement => {
|
||||
return <div className={toolStyle}>{props.children}</div>;
|
||||
};
|
||||
|
||||
export const WorkspaceFallback = (): ReactElement => {
|
||||
return (
|
||||
<AppContainer>
|
||||
<AppSidebarFallback />
|
||||
<MainContainer></MainContainer>
|
||||
</AppContainer>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user