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