112 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-10-12 18:44:11 +08:00
import React, { useEffect, useState } from 'react';
2022-10-12 10:14:58 +08:00
import { styled } from '@/styles';
2022-10-12 18:44:11 +08:00
import { LogoIcon, PaperIcon, EdgelessIcon, SunIcon, MoonIcon } from './icons';
2022-10-12 10:14:58 +08:00
const StyledHeader = styled('div')({
height: '60px',
2022-10-12 18:44:11 +08:00
width: '100vw',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
position: 'relative',
padding: '0 22px',
2022-10-12 10:14:58 +08:00
});
2022-10-12 18:44:11 +08:00
const StyledTitle = styled('div')({
width: '720px',
height: '100%',
position: 'absolute',
left: 0,
right: 0,
top: 0,
margin: 'auto',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
fontWeight: '600',
fontSize: '20px',
});
const StyledTitleWrapper = styled('div')({
maxWidth: '720px',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
position: 'relative',
});
const StyledLogo = styled('div')({});
const StyledModeSwitch = styled('div')({
height: '100%',
display: 'flex',
alignItems: 'center',
marginRight: '15px',
});
const ModeSwitch = () => {
const [mode, setMode] = useState<'page' | 'edgeless'>('page');
const handleModeSwitch = (mode: 'page' | 'edgeless') => {
const event = new CustomEvent('affine.switch-mode', { detail: mode });
window.dispatchEvent(event);
setMode(mode);
};
return (
<StyledModeSwitch>
<PaperIcon
color={mode === 'page' ? '#6880FF' : '#a6abb7'}
onClick={() => {
handleModeSwitch('page');
}}
style={{ cursor: 'pointer' }}
></PaperIcon>
<EdgelessIcon
color={mode === 'edgeless' ? '#6880FF' : '#a6abb7'}
onClick={() => {
handleModeSwitch('edgeless');
}}
style={{ cursor: 'pointer' }}
></EdgelessIcon>
</StyledModeSwitch>
);
};
const DarkModeSwitch = () => {
const [darkMode, setDarkMode] = useState(false);
return (
<div>
<SunIcon></SunIcon>
<MoonIcon></MoonIcon>
</div>
);
};
2022-10-12 10:14:58 +08:00
export const Header = () => {
2022-10-12 18:44:11 +08:00
const [title, setTitle] = useState('');
useEffect(() => {
setTimeout(() => {
const editor = window.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 14:50:04 +08:00
}, 500);
2022-10-12 18:44:11 +08:00
}, []);
return (
<StyledHeader>
<StyledLogo>
<LogoIcon color={'#6880FF'} onClick={() => {}} />
</StyledLogo>
<StyledTitle>
<ModeSwitch />
<StyledTitleWrapper>{title}</StyledTitleWrapper>
</StyledTitle>
</StyledHeader>
);
2022-10-12 10:14:58 +08:00
};