2022-10-12 18:44:11 +08:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2022-10-18 00:32:08 +08:00
|
|
|
import { LogoIcon, SunIcon, MoonIcon, MoreIcon, ExportIcon } from './icons';
|
2022-10-13 18:04:06 +08:00
|
|
|
import {
|
|
|
|
StyledHeader,
|
|
|
|
StyledTitle,
|
|
|
|
StyledTitleWrapper,
|
|
|
|
StyledLogo,
|
|
|
|
StyledHeaderRightSide,
|
|
|
|
StyledMoreMenuItem,
|
2022-10-18 00:28:39 +08:00
|
|
|
IconButton,
|
2022-10-13 18:04:06 +08:00
|
|
|
} from './styles';
|
|
|
|
import { Popover } from '@/components/popover';
|
|
|
|
import { useTheme } from '@/styles';
|
|
|
|
import { useEditor } from '@/components/editor-provider';
|
2022-10-18 00:28:39 +08:00
|
|
|
import EditorModeSwitch from '@/components/editor-mode-switch';
|
2022-10-18 00:43:04 +08:00
|
|
|
import { EdgelessIcon, PaperIcon } from '../editor-mode-switch/icons';
|
2022-10-12 18:44:11 +08:00
|
|
|
|
|
|
|
const DarkModeSwitch = () => {
|
2022-10-13 18:04:06 +08:00
|
|
|
const { changeMode, mode } = useTheme();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{mode === 'dark' ? (
|
|
|
|
<SunIcon
|
2022-10-18 00:28:39 +08:00
|
|
|
style={{ cursor: 'pointer', color: '#9096A5' }}
|
2022-10-13 18:04:06 +08:00
|
|
|
onClick={() => {
|
|
|
|
changeMode('light');
|
|
|
|
}}
|
|
|
|
></SunIcon>
|
|
|
|
) : (
|
|
|
|
<MoonIcon
|
2022-10-18 00:28:39 +08:00
|
|
|
style={{ cursor: 'pointer', color: '#9096A5' }}
|
2022-10-13 18:04:06 +08:00
|
|
|
onClick={() => {
|
|
|
|
changeMode('dark');
|
|
|
|
}}
|
|
|
|
></MoonIcon>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const PopoverContent = () => {
|
2022-10-18 00:43:04 +08:00
|
|
|
const { editor, mode, setMode } = useEditor();
|
2022-10-12 18:44:11 +08:00
|
|
|
return (
|
2022-10-18 00:43:04 +08:00
|
|
|
<>
|
|
|
|
<StyledMoreMenuItem
|
|
|
|
onClick={() => {
|
|
|
|
setMode(mode === 'page' ? 'edgeless' : 'page');
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{mode === 'page' ? <EdgelessIcon /> : <PaperIcon />}
|
|
|
|
Convert to {mode === 'page' ? 'edgeless' : 'page'}
|
|
|
|
</StyledMoreMenuItem>
|
2022-10-13 18:04:06 +08:00
|
|
|
<StyledMoreMenuItem
|
|
|
|
onClick={() => {
|
|
|
|
editor && editor.contentParser.onExportHtml();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<ExportIcon />
|
|
|
|
Export to HTML
|
|
|
|
</StyledMoreMenuItem>
|
|
|
|
<StyledMoreMenuItem
|
|
|
|
onClick={() => {
|
|
|
|
editor && editor.contentParser.onExportMarkdown();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<ExportIcon />
|
|
|
|
Export to markdown
|
|
|
|
</StyledMoreMenuItem>
|
2022-10-18 00:43:04 +08:00
|
|
|
</>
|
2022-10-12 18:44:11 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-10-12 10:14:58 +08:00
|
|
|
export const Header = () => {
|
2022-10-12 18:44:11 +08:00
|
|
|
const [title, setTitle] = useState('');
|
2022-10-17 12:55:34 +08:00
|
|
|
const [isHover, setIsHover] = useState(false);
|
|
|
|
|
2022-10-13 18:04:06 +08:00
|
|
|
const { editor } = useEditor();
|
2022-10-12 18:44:11 +08:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-10-13 18:04:06 +08:00
|
|
|
if (editor) {
|
2022-10-13 14:50:04 +08:00
|
|
|
setTitle(editor.model.title || '');
|
2022-10-12 18:44:11 +08:00
|
|
|
editor.model.propsUpdated.on(() => {
|
|
|
|
setTitle(editor.model.title);
|
|
|
|
});
|
2022-10-13 18:04:06 +08:00
|
|
|
}
|
|
|
|
}, [editor]);
|
2022-10-12 18:44:11 +08:00
|
|
|
|
|
|
|
return (
|
2022-10-18 00:28:39 +08:00
|
|
|
<StyledHeader>
|
2022-10-12 18:44:11 +08:00
|
|
|
<StyledLogo>
|
2022-10-18 00:28:39 +08:00
|
|
|
<LogoIcon style={{ color: '#6880FF' }} onClick={() => {}} />
|
2022-10-12 18:44:11 +08:00
|
|
|
</StyledLogo>
|
2022-10-18 00:28:39 +08:00
|
|
|
<StyledTitle
|
|
|
|
onMouseEnter={() => {
|
|
|
|
setIsHover(true);
|
|
|
|
}}
|
|
|
|
onMouseLeave={() => {
|
|
|
|
setIsHover(false);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<EditorModeSwitch
|
|
|
|
isHover={isHover}
|
|
|
|
style={{
|
|
|
|
marginRight: '12px',
|
|
|
|
}}
|
|
|
|
/>
|
2022-10-12 18:44:11 +08:00
|
|
|
<StyledTitleWrapper>{title}</StyledTitleWrapper>
|
|
|
|
</StyledTitle>
|
2022-10-13 18:04:06 +08:00
|
|
|
|
|
|
|
<StyledHeaderRightSide>
|
|
|
|
<DarkModeSwitch />
|
2022-10-18 00:28:39 +08:00
|
|
|
<Popover
|
|
|
|
popoverContent={<PopoverContent />}
|
|
|
|
style={{ marginLeft: '20px' }}
|
|
|
|
>
|
|
|
|
<IconButton>
|
|
|
|
<MoreIcon />
|
|
|
|
</IconButton>
|
2022-10-13 18:04:06 +08:00
|
|
|
</Popover>
|
|
|
|
</StyledHeaderRightSide>
|
2022-10-12 18:44:11 +08:00
|
|
|
</StyledHeader>
|
|
|
|
);
|
2022-10-12 10:14:58 +08:00
|
|
|
};
|