refactor: remove React.FC for component package (#3575)

This commit is contained in:
Garfield Lee
2023-08-04 23:00:28 +08:00
committed by GitHub
parent 7ec4b8fb8c
commit 65fc0ed59c
21 changed files with 165 additions and 149 deletions

View File

@@ -10,7 +10,6 @@ import {
} from '@blocksuite/icons'; } from '@blocksuite/icons';
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name'; import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import { useStaticBlockSuiteWorkspace } from '@toeverything/infra/__internal__/react'; import { useStaticBlockSuiteWorkspace } from '@toeverything/infra/__internal__/react';
import type { FC } from 'react';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { WorkspaceAvatar } from '../../workspace-avatar'; import { WorkspaceAvatar } from '../../workspace-avatar';
@@ -21,9 +20,6 @@ import {
StyleWorkspaceTitle, StyleWorkspaceTitle,
} from './styles'; } from './styles';
export type WorkspaceTypeProps = {
flavour: WorkspaceFlavour;
};
const JoinedWorkspaceIcon = () => { const JoinedWorkspaceIcon = () => {
return <DefaultJoinedWorkspaceIcon style={{ color: '#FF646B' }} />; return <DefaultJoinedWorkspaceIcon style={{ color: '#FF646B' }} />;
}; };
@@ -39,7 +35,11 @@ const LocalDataIcon = () => {
return <DefaultLocalDataIcon style={{ color: '#62CD80' }} />; return <DefaultLocalDataIcon style={{ color: '#62CD80' }} />;
}; };
const WorkspaceType: FC<WorkspaceTypeProps> = ({ flavour }) => { export interface WorkspaceTypeProps {
flavour: WorkspaceFlavour;
}
const WorkspaceType = ({ flavour }: WorkspaceTypeProps) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
// fixme: cloud regression // fixme: cloud regression
const isOwner = true; const isOwner = true;
@@ -66,19 +66,19 @@ const WorkspaceType: FC<WorkspaceTypeProps> = ({ flavour }) => {
); );
}; };
export type WorkspaceCardProps = { export interface WorkspaceCardProps {
currentWorkspaceId: string | null; currentWorkspaceId: string | null;
meta: RootWorkspaceMetadata; meta: RootWorkspaceMetadata;
onClick: (workspaceId: string) => void; onClick: (workspaceId: string) => void;
onSettingClick: (workspaceId: string) => void; onSettingClick: (workspaceId: string) => void;
}; }
export const WorkspaceCard: FC<WorkspaceCardProps> = ({ export const WorkspaceCard = ({
onClick, onClick,
onSettingClick, onSettingClick,
currentWorkspaceId, currentWorkspaceId,
meta, meta,
}) => { }: WorkspaceCardProps) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
const workspace = useStaticBlockSuiteWorkspace(meta.id); const workspace = useStaticBlockSuiteWorkspace(meta.id);
const [name] = useBlockSuiteWorkspaceName(workspace); const [name] = useBlockSuiteWorkspaceName(workspace);

View File

@@ -1,10 +1,9 @@
import { lottieAtom } from '@affine/jotai'; import { lottieAtom } from '@affine/jotai';
import { useAtomValue } from 'jotai'; import { useAtomValue } from 'jotai';
import type { AnimationItem } from 'lottie-web'; import type { AnimationItem } from 'lottie-web';
import type { FC } from 'react';
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
type CustomLottieProps = { interface CustomLottieProps {
options: { options: {
loop?: boolean | number | undefined; loop?: boolean | number | undefined;
autoReverse?: boolean | undefined; autoReverse?: boolean | undefined;
@@ -18,15 +17,15 @@ type CustomLottieProps = {
speed?: number | undefined; speed?: number | undefined;
width?: number | string | undefined; width?: number | string | undefined;
height?: number | string | undefined; height?: number | string | undefined;
}; }
export const InternalLottie: FC<CustomLottieProps> = ({ export const InternalLottie = ({
options, options,
isStopped, isStopped,
speed, speed,
width, width,
height, height,
}) => { }: CustomLottieProps) => {
const element = useRef<HTMLDivElement>(null); const element = useRef<HTMLDivElement>(null);
const lottieInstance = useRef<AnimationItem>(); const lottieInstance = useRef<AnimationItem>();
const lottie = useAtomValue(lottieAtom); const lottie = useAtomValue(lottieAtom);

View File

@@ -28,6 +28,17 @@ import type { ListData, PageListProps, TrashListData } from './type';
import { useSorter } from './use-sorter'; import { useSorter } from './use-sorter';
import { formatDate, useIsSmallDevices } from './utils'; import { formatDate, useIsSmallDevices } from './utils';
interface AllPagesHeadProps {
isPublicWorkspace: boolean;
sorter: ReturnType<typeof useSorter<ListData>>;
createNewPage: () => void;
createNewEdgeless: () => void;
importFile: () => void;
getPageInfo: GetPageInfoById;
propertiesMeta: PropertiesMeta;
workspaceId: string;
}
const AllPagesHead = ({ const AllPagesHead = ({
isPublicWorkspace, isPublicWorkspace,
sorter, sorter,
@@ -37,16 +48,7 @@ const AllPagesHead = ({
getPageInfo, getPageInfo,
propertiesMeta, propertiesMeta,
workspaceId, workspaceId,
}: { }: AllPagesHeadProps) => {
isPublicWorkspace: boolean;
sorter: ReturnType<typeof useSorter<ListData>>;
createNewPage: () => void;
createNewEdgeless: () => void;
importFile: () => void;
getPageInfo: GetPageInfoById;
propertiesMeta: PropertiesMeta;
workspaceId: string;
}) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
const titleList = useMemo( const titleList = useMemo(
() => [ () => [
@@ -235,10 +237,15 @@ const TrashListHead = () => {
); );
}; };
export const PageListTrashView: React.FC<{ interface PageListTrashViewProps {
list: TrashListData[]; list: TrashListData[];
fallback?: React.ReactNode; fallback?: React.ReactNode;
}> = ({ list, fallback }) => { }
export const PageListTrashView = ({
list,
fallback,
}: PageListTrashViewProps) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
const theme = useTheme(); const theme = useTheme();

View File

@@ -8,7 +8,6 @@ import {
OpenInNewIcon, OpenInNewIcon,
ResetIcon, ResetIcon,
} from '@blocksuite/icons'; } from '@blocksuite/icons';
import type React from 'react';
import { useState } from 'react'; import { useState } from 'react';
import { import {
@@ -21,7 +20,7 @@ import {
} from '../../..'; } from '../../..';
import { DisablePublicSharing, MoveToTrash } from './operation-menu-items'; import { DisablePublicSharing, MoveToTrash } from './operation-menu-items';
export type OperationCellProps = { export interface OperationCellProps {
title: string; title: string;
favorite: boolean; favorite: boolean;
isPublic: boolean; isPublic: boolean;
@@ -29,9 +28,9 @@ export type OperationCellProps = {
onToggleFavoritePage: () => void; onToggleFavoritePage: () => void;
onRemoveToTrash: () => void; onRemoveToTrash: () => void;
onDisablePublicSharing: () => void; onDisablePublicSharing: () => void;
}; }
export const OperationCell: React.FC<OperationCellProps> = ({ export const OperationCell = ({
title, title,
favorite, favorite,
isPublic, isPublic,
@@ -39,7 +38,7 @@ export const OperationCell: React.FC<OperationCellProps> = ({
onToggleFavoritePage, onToggleFavoritePage,
onRemoveToTrash, onRemoveToTrash,
onDisablePublicSharing, onDisablePublicSharing,
}) => { }: OperationCellProps) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [openDisableShared, setOpenDisableShared] = useState(false); const [openDisableShared, setOpenDisableShared] = useState(false);
@@ -118,16 +117,16 @@ export const OperationCell: React.FC<OperationCellProps> = ({
); );
}; };
export type TrashOperationCellProps = { export interface TrashOperationCellProps {
onPermanentlyDeletePage: () => void; onPermanentlyDeletePage: () => void;
onRestorePage: () => void; onRestorePage: () => void;
onOpenPage: () => void; onOpenPage: () => void;
}; }
export const TrashOperationCell: React.FC<TrashOperationCellProps> = ({ export const TrashOperationCell = ({
onPermanentlyDeletePage, onPermanentlyDeletePage,
onRestorePage, onRestorePage,
}) => { }: TrashOperationCellProps) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
return ( return (

View File

@@ -10,7 +10,7 @@ import { ProviderComposer } from '..';
test('ProviderComposer', async () => { test('ProviderComposer', async () => {
const Context = createContext('null'); const Context = createContext('null');
const Provider: React.FC<React.PropsWithChildren> = ({ children }) => { const Provider = ({ children }: React.PropsWithChildren) => {
return <Context.Provider value="test1">{children}</Context.Provider>; return <Context.Provider value="test1">{children}</Context.Provider>;
}; };
const ConsumerComponent = () => { const ConsumerComponent = () => {

View File

@@ -1,11 +1,15 @@
import type { FC, PropsWithChildren, ReactNode } from 'react'; import type { ReactNode } from 'react';
import { cloneElement } from 'react'; import { cloneElement } from 'react';
export const ProviderComposer: FC< interface ProviderComposerProps {
PropsWithChildren<{
contexts: any; contexts: any;
}> children: ReactNode;
> = ({ contexts, children }) => }
export const ProviderComposer = ({
contexts,
children,
}: ProviderComposerProps) =>
contexts.reduceRight( contexts.reduceRight(
(kids: ReactNode, parent: any) => (kids: ReactNode, parent: any) =>
cloneElement(parent, { cloneElement(parent, {

View File

@@ -1,17 +1,17 @@
import { Modal, ModalCloseButton, ModalWrapper } from '@affine/component'; import { Modal, ModalCloseButton, ModalWrapper } from '@affine/component';
import type { FC, PropsWithChildren } from 'react'; import type { PropsWithChildren } from 'react';
import { useCallback } from 'react'; import { useCallback } from 'react';
export type SettingModalProps = { export interface SettingModalProps {
open: boolean; open: boolean;
setOpen: (value: boolean) => void; setOpen: (value: boolean) => void;
}; }
export const SettingModal: FC<PropsWithChildren<SettingModalProps>> = ({ export const SettingModal = ({
children, children,
open, open,
setOpen, setOpen,
}) => { }: PropsWithChildren<SettingModalProps>) => {
const handleClose = useCallback(() => { const handleClose = useCallback(() => {
setOpen(false); setOpen(false);
}, [setOpen]); }, [setOpen]);

View File

@@ -1,13 +1,18 @@
import type { FC, HTMLAttributes, ReactNode } from 'react'; import type { HTMLAttributes, ReactNode } from 'react';
import { settingHeader } from './share.css'; import { settingHeader } from './share.css';
export const SettingHeader: FC< interface SettingHeaderProps
{ title: ReactNode; subtitle?: ReactNode } & Omit< extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
HTMLAttributes<HTMLDivElement>, title: ReactNode;
'title' subtitle?: ReactNode;
> }
> = ({ title, subtitle, ...otherProps }) => {
export const SettingHeader = ({
title,
subtitle,
...otherProps
}: SettingHeaderProps) => {
return ( return (
<div className={settingHeader} {...otherProps}> <div className={settingHeader} {...otherProps}>
<div className="title">{title}</div> <div className="title">{title}</div>

View File

@@ -1,18 +1,18 @@
import clsx from 'clsx'; import clsx from 'clsx';
import type { CSSProperties, FC, PropsWithChildren, ReactNode } from 'react'; import type { CSSProperties, PropsWithChildren, ReactNode } from 'react';
import { settingRow } from './share.css'; import { settingRow } from './share.css';
export const SettingRow: FC< interface SettingRowProps {
PropsWithChildren<{
name: ReactNode; name: ReactNode;
desc: ReactNode; desc: ReactNode;
style?: CSSProperties; style?: CSSProperties;
onClick?: () => void; onClick?: () => void;
spreadCol?: boolean; spreadCol?: boolean;
testId?: string; testId?: string;
}> }
> = ({
export const SettingRow = ({
name, name,
desc, desc,
children, children,
@@ -20,7 +20,7 @@ export const SettingRow: FC<
style, style,
spreadCol = true, spreadCol = true,
testId = '', testId = '',
}) => { }: PropsWithChildren<SettingRowProps>) => {
return ( return (
<div <div
className={clsx(settingRow, { className={clsx(settingRow, {

View File

@@ -1,11 +1,15 @@
import type { FC, PropsWithChildren, ReactNode } from 'react'; import type { PropsWithChildren, ReactNode } from 'react';
import { wrapper } from './share.css'; import { wrapper } from './share.css';
export const SettingWrapper: FC<
PropsWithChildren<{ interface SettingWrapperProps {
title?: ReactNode; title?: ReactNode;
}> }
> = ({ title, children }) => {
export const SettingWrapper = ({
title,
children,
}: PropsWithChildren<SettingWrapperProps>) => {
return ( return (
<div className={wrapper}> <div className={wrapper}>
{title ? <div className="title">{title}</div> : null} {title ? <div className="title">{title}</div> : null}

View File

@@ -1,5 +1,4 @@
import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { FC } from 'react';
import { import {
ExportToHtmlMenuItem, ExportToHtmlMenuItem,
@@ -8,9 +7,9 @@ import {
ExportToPngMenuItem, ExportToPngMenuItem,
} from '../page-list/operation-menu-items/export'; } from '../page-list/operation-menu-items/export';
import { actionsStyle, descriptionStyle, menuItemStyle } from './index.css'; import { actionsStyle, descriptionStyle, menuItemStyle } from './index.css';
import type { ShareMenuProps } from './share-menu'; // import type { ShareMenuProps } from './share-menu';
export const Export: FC<ShareMenuProps> = () => { export const Export = () => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
return ( return (
<div className={menuItemStyle}> <div className={menuItemStyle}>

View File

@@ -5,8 +5,7 @@ import type {
import { ExportIcon, PublishIcon, ShareIcon } from '@blocksuite/icons'; import { ExportIcon, PublishIcon, ShareIcon } from '@blocksuite/icons';
import type { Page } from '@blocksuite/store'; import type { Page } from '@blocksuite/store';
import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public'; import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
import type { FC } from 'react'; import { type ReactElement, useRef } from 'react';
import { useRef } from 'react';
import { useCallback, useState } from 'react'; import { useCallback, useState } from 'react';
import { Button } from '../../ui/button'; import { Button } from '../../ui/button';
@@ -16,22 +15,27 @@ import { containerStyle, indicatorContainerStyle, tabStyle } from './index.css';
import { SharePage } from './share-page'; import { SharePage } from './share-page';
import { ShareWorkspace } from './share-workspace'; import { ShareWorkspace } from './share-workspace';
import { StyledIndicator, TabItem } from './styles'; import { StyledIndicator, TabItem } from './styles';
type SharePanel = 'SharePage' | 'Export' | 'ShareWorkspace'; type SharePanel = 'SharePage' | 'Export' | 'ShareWorkspace';
const MenuItems: Record<SharePanel, FC<ShareMenuProps>> = { type ShareMenuComponent<T> = (props: T) => ReactElement;
const MenuItems: Record<SharePanel, ShareMenuComponent<ShareMenuProps>> = {
SharePage: SharePage, SharePage: SharePage,
Export: Export, Export: Export,
ShareWorkspace: ShareWorkspace, ShareWorkspace: ShareWorkspace,
}; };
const tabIcons = { const tabIcons = {
SharePage: <ShareIcon />, SharePage: <ShareIcon />,
Export: <ExportIcon />, Export: <ExportIcon />,
ShareWorkspace: <PublishIcon />, ShareWorkspace: <PublishIcon />,
}; };
export type ShareMenuProps<
export interface ShareMenuProps<
Workspace extends AffineCloudWorkspace | LocalWorkspace = Workspace extends AffineCloudWorkspace | LocalWorkspace =
| AffineCloudWorkspace | AffineCloudWorkspace
| LocalWorkspace, | LocalWorkspace,
> = { > {
workspace: Workspace; workspace: Workspace;
currentPage: Page; currentPage: Page;
onEnableAffineCloud: (workspace: LocalWorkspace) => void; onEnableAffineCloud: (workspace: LocalWorkspace) => void;
@@ -41,7 +45,7 @@ export type ShareMenuProps<
workspace: Workspace, workspace: Workspace,
publish: boolean publish: boolean
) => Promise<void>; ) => Promise<void>;
}; }
function assertInstanceOf<T, U extends T>( function assertInstanceOf<T, U extends T>(
obj: T, obj: T,
@@ -52,7 +56,7 @@ function assertInstanceOf<T, U extends T>(
} }
} }
export const ShareMenu: FC<ShareMenuProps> = props => { export const ShareMenu = (props: ShareMenuProps) => {
const [activeItem, setActiveItem] = useState<SharePanel>('SharePage'); const [activeItem, setActiveItem] = useState<SharePanel>('SharePage');
const [isPublic] = useBlockSuiteWorkspacePageIsPublic(props.currentPage); const [isPublic] = useBlockSuiteWorkspacePageIsPublic(props.currentPage);
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
@@ -84,7 +88,7 @@ export const ShareMenu: FC<ShareMenuProps> = props => {
activeItem: SharePanel; activeItem: SharePanel;
onChangeTab: (selectedItem: SharePanel) => void; onChangeTab: (selectedItem: SharePanel) => void;
} }
const ShareMenu: FC<ShareMenuProps> = ({ activeItem, onChangeTab }) => { const ShareMenu = ({ activeItem, onChangeTab }: ShareMenuProps) => {
const handleButtonClick = (itemName: SharePanel) => { const handleButtonClick = (itemName: SharePanel) => {
onChangeTab(itemName); onChangeTab(itemName);
setActiveItem(itemName); setActiveItem(itemName);

View File

@@ -3,7 +3,6 @@ import { WorkspaceFlavour } from '@affine/env/workspace';
import { Trans } from '@affine/i18n'; import { Trans } from '@affine/i18n';
import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public'; import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
import type { FC } from 'react';
import { useState } from 'react'; import { useState } from 'react';
import { useCallback, useMemo } from 'react'; import { useCallback, useMemo } from 'react';
@@ -17,7 +16,7 @@ import {
import type { ShareMenuProps } from './share-menu'; import type { ShareMenuProps } from './share-menu';
import { StyledDisableButton, StyledInput, StyledLinkSpan } from './styles'; import { StyledDisableButton, StyledInput, StyledLinkSpan } from './styles';
export const LocalSharePage: FC<ShareMenuProps> = props => { export const LocalSharePage = (props: ShareMenuProps) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
return ( return (
<div className={menuItemStyle}> <div className={menuItemStyle}>
@@ -35,7 +34,7 @@ export const LocalSharePage: FC<ShareMenuProps> = props => {
); );
}; };
export const AffineSharePage: FC<ShareMenuProps> = props => { export const AffineSharePage = (props: ShareMenuProps) => {
const [isPublic, setIsPublic] = useBlockSuiteWorkspacePageIsPublic( const [isPublic, setIsPublic] = useBlockSuiteWorkspacePageIsPublic(
props.currentPage props.currentPage
); );
@@ -123,7 +122,7 @@ export const AffineSharePage: FC<ShareMenuProps> = props => {
); );
}; };
export const SharePage: FC<ShareMenuProps> = props => { export const SharePage = (props: ShareMenuProps) => {
if (props.workspace.flavour === WorkspaceFlavour.LOCAL) { if (props.workspace.flavour === WorkspaceFlavour.LOCAL) {
return <LocalSharePage {...props} />; return <LocalSharePage {...props} />;
} else if (props.workspace.flavour === WorkspaceFlavour.AFFINE_CLOUD) { } else if (props.workspace.flavour === WorkspaceFlavour.AFFINE_CLOUD) {

View File

@@ -4,13 +4,12 @@ import type {
} from '@affine/env/workspace'; } from '@affine/env/workspace';
import { WorkspaceFlavour } from '@affine/env/workspace'; import { WorkspaceFlavour } from '@affine/env/workspace';
import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { useAFFiNEI18N } from '@affine/i18n/hooks';
import type { FC } from 'react';
import { Button } from '../../ui/button'; import { Button } from '../../ui/button';
import { descriptionStyle, menuItemStyle } from './index.css'; import { descriptionStyle, menuItemStyle } from './index.css';
import type { ShareMenuProps } from './share-menu'; import type { ShareMenuProps } from './share-menu';
const ShareLocalWorkspace: FC<ShareMenuProps<LocalWorkspace>> = props => { const ShareLocalWorkspace = (props: ShareMenuProps<LocalWorkspace>) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
return ( return (
<div className={menuItemStyle}> <div className={menuItemStyle}>
@@ -29,9 +28,7 @@ const ShareLocalWorkspace: FC<ShareMenuProps<LocalWorkspace>> = props => {
); );
}; };
const ShareAffineWorkspace: FC< const ShareAffineWorkspace = (props: ShareMenuProps<AffineCloudWorkspace>) => {
ShareMenuProps<AffineCloudWorkspace>
> = props => {
// fixme: regression // fixme: regression
const isPublicWorkspace = false; const isPublicWorkspace = false;
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
@@ -54,7 +51,7 @@ const ShareAffineWorkspace: FC<
); );
}; };
export const ShareWorkspace: FC<ShareMenuProps> = props => { export const ShareWorkspace = (props: ShareMenuProps) => {
if (props.workspace.flavour === WorkspaceFlavour.LOCAL) { if (props.workspace.flavour === WorkspaceFlavour.LOCAL) {
return ( return (
<ShareLocalWorkspace {...(props as ShareMenuProps<LocalWorkspace>)} /> <ShareLocalWorkspace {...(props as ShareMenuProps<LocalWorkspace>)} />

View File

@@ -1,7 +1,6 @@
import { useAFFiNEI18N } from '@affine/i18n/hooks'; import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { ArrowLeftSmallIcon, ArrowRightSmallIcon } from '@blocksuite/icons'; import { ArrowLeftSmallIcon, ArrowRightSmallIcon } from '@blocksuite/icons';
import clsx from 'clsx'; import clsx from 'clsx';
import type { FC } from 'react';
import { useState } from 'react'; import { useState } from 'react';
import { Modal, ModalCloseButton, ModalWrapper } from '../..'; import { Modal, ModalCloseButton, ModalWrapper } from '../..';
@@ -26,12 +25,12 @@ import {
videoStyle, videoStyle,
} from './index.css'; } from './index.css';
type TourModalProps = { export interface TourModalProps {
open: boolean; open: boolean;
onClose: () => void; onClose: () => void;
}; }
export const TourModal: FC<TourModalProps> = ({ open, onClose }) => { export const TourModal = ({ open, onClose }: TourModalProps) => {
const t = useAFFiNEI18N(); const t = useAFFiNEI18N();
const [step, setStep] = useState(-1); const [step, setStep] = useState(-1);
const handleClose = () => { const handleClose = () => {

View File

@@ -1,24 +1,24 @@
import * as Avatar from '@radix-ui/react-avatar'; import * as Avatar from '@radix-ui/react-avatar';
import clsx from 'clsx'; import clsx from 'clsx';
import type { CSSProperties, FC } from 'react'; import type { CSSProperties } from 'react';
import * as style from './style.css'; import * as style from './style.css';
export type UserAvatar = { export interface UserAvatar {
size?: number; size?: number;
url?: string; url?: string;
name?: string; name?: string;
className?: string; className?: string;
style?: CSSProperties; style?: CSSProperties;
}; }
export const UserAvatar: FC<UserAvatar> = ({ export const UserAvatar = ({
size = 20, size = 20,
style: propsStyles = {}, style: propsStyles = {},
url, url,
name, name,
className, className,
}) => { }: UserAvatar) => {
return ( return (
<Avatar.Root <Avatar.Root
style={{ style={{

View File

@@ -3,29 +3,26 @@ import * as RadixAvatar from '@radix-ui/react-avatar';
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url'; import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name'; import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
import clsx from 'clsx'; import clsx from 'clsx';
import type React from 'react';
import { DefaultAvatar } from './default-avatar'; import { DefaultAvatar } from './default-avatar';
import { avatarImageStyle, avatarStyle } from './index.css'; import { avatarImageStyle, avatarStyle } from './index.css';
export type WorkspaceAvatarProps = { export interface WorkspaceAvatarProps {
size?: number; size?: number;
workspace: Workspace | null; workspace: Workspace | null;
className?: string; className?: string;
}; }
export type BlockSuiteWorkspaceAvatar = Omit< export interface BlockSuiteWorkspaceAvatar
WorkspaceAvatarProps, extends Omit<WorkspaceAvatarProps, 'workspace'> {
'workspace'
> & {
workspace: Workspace; workspace: Workspace;
}; }
export const BlockSuiteWorkspaceAvatar: React.FC<BlockSuiteWorkspaceAvatar> = ({ export const BlockSuiteWorkspaceAvatar = ({
size, size,
workspace, workspace,
...props ...props
}) => { }: BlockSuiteWorkspaceAvatar) => {
const [avatar] = useBlockSuiteWorkspaceAvatarUrl(workspace); const [avatar] = useBlockSuiteWorkspaceAvatarUrl(workspace);
const [name] = useBlockSuiteWorkspaceName(workspace); const [name] = useBlockSuiteWorkspaceName(workspace);
@@ -46,11 +43,11 @@ export const BlockSuiteWorkspaceAvatar: React.FC<BlockSuiteWorkspaceAvatar> = ({
); );
}; };
export const WorkspaceAvatar: React.FC<WorkspaceAvatarProps> = ({ export const WorkspaceAvatar = ({
size = 20, size = 20,
workspace, workspace,
...props ...props
}) => { }: WorkspaceAvatarProps) => {
if (workspace) { if (workspace) {
return ( return (
<BlockSuiteWorkspaceAvatar {...props} size={size} workspace={workspace} /> <BlockSuiteWorkspaceAvatar {...props} size={size} workspace={workspace} />

View File

@@ -11,26 +11,26 @@ import {
useSensors, useSensors,
} from '@dnd-kit/core'; } from '@dnd-kit/core';
import { SortableContext, useSortable } from '@dnd-kit/sortable'; import { SortableContext, useSortable } from '@dnd-kit/sortable';
import type { CSSProperties, FC } from 'react'; import type { CSSProperties } from 'react';
import { useMemo } from 'react'; import { useMemo } from 'react';
import { WorkspaceCard } from '../../components/card/workspace-card'; import { WorkspaceCard } from '../../components/card/workspace-card';
import { workspaceItemStyle } from './index.css'; import { workspaceItemStyle } from './index.css';
export type WorkspaceListProps = { export interface WorkspaceListProps {
disabled?: boolean; disabled?: boolean;
currentWorkspaceId: string | null; currentWorkspaceId: string | null;
items: (AffineCloudWorkspace | LocalWorkspace)[]; items: (AffineCloudWorkspace | LocalWorkspace)[];
onClick: (workspaceId: string) => void; onClick: (workspaceId: string) => void;
onSettingClick: (workspaceId: string) => void; onSettingClick: (workspaceId: string) => void;
onDragEnd: (event: DragEndEvent) => void; onDragEnd: (event: DragEndEvent) => void;
}; }
const SortableWorkspaceItem: FC< interface SortableWorkspaceItemProps extends Omit<WorkspaceListProps, 'items'> {
Omit<WorkspaceListProps, 'items'> & {
item: RootWorkspaceMetadata; item: RootWorkspaceMetadata;
} }
> = props => {
const SortableWorkspaceItem = (props: SortableWorkspaceItemProps) => {
const { setNodeRef, attributes, listeners, transform } = useSortable({ const { setNodeRef, attributes, listeners, transform } = useSortable({
id: props.item.id, id: props.item.id,
}); });
@@ -63,7 +63,7 @@ const SortableWorkspaceItem: FC<
); );
}; };
export const WorkspaceList: FC<WorkspaceListProps> = props => { export const WorkspaceList = (props: WorkspaceListProps) => {
const sensors = useSensors( const sensors = useSensors(
useSensor(PointerSensor, { useSensor(PointerSensor, {
activationConstraint: { activationConstraint: {

View File

@@ -1,26 +1,27 @@
import { clsx } from 'clsx'; import { clsx } from 'clsx';
import type { import type {
FC,
HTMLAttributes, HTMLAttributes,
PropsWithChildren, PropsWithChildren,
ReactElement, ReactElement,
ReactNode,
} from 'react'; } from 'react';
import { AppSidebarFallback } from '../app-sidebar'; import { AppSidebarFallback } from '../app-sidebar';
import { appStyle, mainContainerStyle, toolStyle } from './index.css'; import { appStyle, mainContainerStyle, toolStyle } from './index.css';
export type WorkspaceRootProps = PropsWithChildren<{ export interface WorkspaceRootProps {
resizing?: boolean; resizing?: boolean;
useNoisyBackground?: boolean; useNoisyBackground?: boolean;
useBlurBackground?: boolean; useBlurBackground?: boolean;
}>; children: ReactNode;
}
export const AppContainer: FC<WorkspaceRootProps> = ({ export const AppContainer = ({
resizing, resizing,
useNoisyBackground, useNoisyBackground,
useBlurBackground, useBlurBackground,
children, children,
}) => { }: WorkspaceRootProps) => {
const noisyBackground = useNoisyBackground && environment.isDesktop; const noisyBackground = useNoisyBackground && environment.isDesktop;
return ( return (
<div <div
@@ -36,18 +37,17 @@ export const AppContainer: FC<WorkspaceRootProps> = ({
); );
}; };
export type MainContainerProps = PropsWithChildren<{ export interface MainContainerProps extends HTMLAttributes<HTMLDivElement> {
className?: string; className?: string;
padding?: boolean; padding?: boolean;
}> & }
HTMLAttributes<HTMLDivElement>;
export const MainContainer = ({ export const MainContainer = ({
className, className,
padding, padding,
children, children,
...props ...props
}: MainContainerProps): ReactElement => { }: PropsWithChildren<MainContainerProps>): ReactElement => {
return ( return (
<div <div
{...props} {...props}

View File

@@ -1,6 +1,5 @@
import clsx from 'clsx'; import clsx from 'clsx';
import { import {
type FC,
forwardRef, forwardRef,
type HTMLAttributes, type HTMLAttributes,
type PropsWithChildren, type PropsWithChildren,
@@ -10,6 +9,7 @@ import {
import { Loading } from '../loading'; import { Loading } from '../loading';
import { button, buttonIcon } from './style.css'; import { button, buttonIcon } from './style.css';
export type ButtonType = export type ButtonType =
| 'default' | 'default'
| 'primary' | 'primary'
@@ -18,9 +18,11 @@ export type ButtonType =
| 'warning' | 'warning'
| 'success' | 'success'
| 'processing'; | 'processing';
export type ButtonSize = 'default' | 'large' | 'extraLarge'; export type ButtonSize = 'default' | 'large' | 'extraLarge';
export type ButtonProps = PropsWithChildren &
Omit<HTMLAttributes<HTMLButtonElement>, 'type'> & { export interface ButtonProps
extends Omit<HTMLAttributes<HTMLButtonElement>, 'type'> {
type?: ButtonType; type?: ButtonType;
disabled?: boolean; disabled?: boolean;
icon?: ReactElement; icon?: ReactElement;
@@ -29,7 +31,8 @@ export type ButtonProps = PropsWithChildren &
block?: boolean; block?: boolean;
size?: ButtonSize; size?: ButtonSize;
loading?: boolean; loading?: boolean;
}; }
const defaultProps = { const defaultProps = {
type: 'default', type: 'default',
disabled: false, disabled: false,
@@ -39,7 +42,7 @@ const defaultProps = {
loading: false, loading: false,
}; };
const ButtonIcon: FC<ButtonProps> = props => { const ButtonIcon = (props: PropsWithChildren<ButtonProps>) => {
const { const {
size, size,
icon, icon,
@@ -65,6 +68,7 @@ const ButtonIcon: FC<ButtonProps> = props => {
</div> </div>
); );
}; };
export const Button = forwardRef<HTMLButtonElement, ButtonProps>( export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
(props, ref) => { (props, ref) => {
const { const {

View File

@@ -1,14 +1,13 @@
import { assignInlineVars } from '@vanilla-extract/dynamic'; import { assignInlineVars } from '@vanilla-extract/dynamic';
import type { FC } from 'react';
import { loading, speedVar } from './styles.css'; import { loading, speedVar } from './styles.css';
export type LoadingProps = { export interface LoadingProps {
size?: number; size?: number;
speed?: number; speed?: number;
}; }
export const Loading: FC<LoadingProps> = ({ size, speed = 1.2 }) => { export const Loading = ({ size, speed = 1.2 }: LoadingProps) => {
return ( return (
<svg <svg
className={loading} className={loading}