feat: add Modal component to common ui

This commit is contained in:
QiShaoXuan 2022-10-31 15:18:22 +08:00
parent 1bf6546144
commit a11306bf89
8 changed files with 148 additions and 3106 deletions

View File

@ -66,11 +66,11 @@ const BrowserWarning = ({ onClose }: { onClose: () => void }) => {
export const Header = () => {
const [title, setTitle] = useState('');
const [isHover, setIsHover] = useState(false);
const [showWarning, setShowWarning] = useState(shouldShowWarning());
const { contactModalHandler } = useModal();
const { editor } = useEditor();
const [showWarning, setShowWarning] = useState(shouldShowWarning());
useEffect(() => {
if (editor) {
setTitle(editor.model.title || '');

View File

@ -1,5 +1,4 @@
import { createPortal } from 'react-dom';
import Fade from '@mui/material/Fade';
import Modal from '@/ui/modal';
import CloseIcon from '@mui/icons-material/Close';
import {
LogoIcon,
@ -13,7 +12,6 @@ import {
} from './icons';
import logo from './affine-text-logo.png';
import {
StyledModalContainer,
StyledModalWrapper,
StyledBigLink,
StyledSmallLink,
@ -21,7 +19,6 @@ import {
StyledLeftContainer,
StyledRightContainer,
StyledContent,
StyledBackdrop,
StyledLogo,
StyledModalHeader,
StyledModalHeaderLeft,
@ -77,72 +74,68 @@ type TransitionsModalProps = {
};
export const ContactModal = ({ open, onClose }: TransitionsModalProps) => {
return createPortal(
<Fade in={open}>
<StyledModalContainer>
<StyledBackdrop onClick={onClose} />
<StyledModalWrapper>
<StyledModalHeader>
<StyledModalHeaderLeft>
<StyledLogo src={logo.src} alt="" />
<span>Alpha</span>
</StyledModalHeaderLeft>
<StyledCloseButton
onClick={() => {
onClose();
}}
return (
<Modal open={open} onClose={onClose}>
<StyledModalWrapper>
<StyledModalHeader>
<StyledModalHeaderLeft>
<StyledLogo src={logo.src} alt="" />
<span>Alpha</span>
</StyledModalHeaderLeft>
<StyledCloseButton
onClick={() => {
onClose();
}}
>
<CloseIcon width={12} height={12} />
</StyledCloseButton>
</StyledModalHeader>
<StyledContent>
<StyledLeftContainer>
{rightLinkList.map(({ icon, title, subTitle, link }) => {
return (
<StyledBigLink key={title} href={link} target="_blank">
{icon}
<p>{title}</p>
<p>
{subTitle}
<LinkIcon />
</p>
</StyledBigLink>
);
})}
</StyledLeftContainer>
<StyledRightContainer>
<StyledSubTitle>
Get in touch! <br />
Join our community.
</StyledSubTitle>
{linkList.map(({ icon, title, link }) => {
return (
<StyledSmallLink key={title} href={link} target="_blank">
{icon}
{title}
</StyledSmallLink>
);
})}
</StyledRightContainer>
</StyledContent>
<StyledModalFooter>
<p>
<a
href="https://affine.pro/content/blog/affine-alpha-is-coming/index"
target="_blank"
rel="noreferrer"
>
<CloseIcon width={12} height={12} />
</StyledCloseButton>
</StyledModalHeader>
<StyledContent>
<StyledLeftContainer>
{rightLinkList.map(({ icon, title, subTitle, link }) => {
return (
<StyledBigLink key={title} href={link} target="_blank">
{icon}
<p>{title}</p>
<p>
{subTitle}
<LinkIcon />
</p>
</StyledBigLink>
);
})}
</StyledLeftContainer>
<StyledRightContainer>
<StyledSubTitle>
Get in touch! <br />
Join our community.
</StyledSubTitle>
{linkList.map(({ icon, title, link }) => {
return (
<StyledSmallLink key={title} href={link} target="_blank">
{icon}
{title}
</StyledSmallLink>
);
})}
</StyledRightContainer>
</StyledContent>
<StyledModalFooter>
<p>
<a
href="https://affine.pro/content/blog/affine-alpha-is-coming/index"
target="_blank"
rel="noreferrer"
>
How is AFFiNE Alpha different
</a>
</p>
<p>Copyright &copy; 2022 Toeverything</p>
</StyledModalFooter>
</StyledModalWrapper>
</StyledModalContainer>
</Fade>,
document.body
How is AFFiNE Alpha different
</a>
</p>
<p>Copyright &copy; 2022 Toeverything</p>
</StyledModalFooter>
</StyledModalWrapper>
</Modal>
);
};

View File

@ -2,17 +2,6 @@ import { absoluteCenter, displayFlex, styled } from '@/styles';
import bg from './bg.png';
import CloseIcon from '@mui/icons-material/Close';
export const StyledModalContainer = styled('div')(({ theme }) => {
return {
width: '100vw',
height: '100vh',
position: 'fixed',
left: '0',
top: '0',
zIndex: theme.zIndex.modal,
};
});
export const StyledModalWrapper = styled('div')(({ theme }) => {
return {
width: '860px',
@ -143,9 +132,6 @@ export const StyledContent = styled('div')({
letterSpacing: '0.06em',
});
export const StyledBackdrop = styled('div')(({ theme }) => {
return { width: '100%', height: '100%', background: 'rgba(58, 76, 92, 0.2)' };
});
export const StyledLogo = styled('img')({
height: '18px',
width: 'auto',

View File

@ -1,7 +1,8 @@
import { displayFlex, styled } from '@/styles';
import { ThemeModeSwitch } from '@/components/theme-mode-switch';
import { Loading } from '@/components/loading';
import Modal from '@/ui/modal';
import { useState } from 'react';
export const StyledHeader = styled('div')({
height: '60px',
width: '100vw',
@ -12,11 +13,27 @@ export const StyledHeader = styled('div')({
});
const Affine = () => {
const [show, setShow] = useState(false);
return (
<>
<StyledHeader>
<ThemeModeSwitch></ThemeModeSwitch>
<button
onClick={() => {
setShow(true);
}}
>
click me!
</button>
</StyledHeader>
<Modal
open={show}
onClose={() => {
setShow(false);
}}
>
<div>hi</div>
</Modal>
<Loading />
</>
);

View File

@ -0,0 +1,4 @@
import Modal from './modal';
export * from './modal';
export default Modal;

View File

@ -0,0 +1,32 @@
import Fade from '@mui/material/Fade';
import { StyledModal, StyledBackdrop } from './style';
import { ModalUnstyledOwnProps } from '@mui/base/ModalUnstyled';
const Backdrop = ({
open,
...other
}: {
open?: boolean;
className: string;
}) => {
return (
<Fade in={open}>
<StyledBackdrop open={open} {...other} />
</Fade>
);
};
export type ModalProps = ModalUnstyledOwnProps;
export const Modal = (props: ModalProps) => {
const { components, open, children, ...otherProps } = props;
return (
<div>
<StyledModal {...otherProps} open={open} components={{ Backdrop }}>
<Fade in={open}>{children}</Fade>
</StyledModal>
</div>
);
};
export default Modal;

View File

@ -0,0 +1,30 @@
import { displayFlex, fixedCenter, styled } from '@/styles';
import ModalUnstyled from '@mui/base/ModalUnstyled';
export const StyledBackdrop = styled.div<{ open?: boolean }>(({ open }) => {
return {
zIndex: '-1',
position: 'fixed',
right: '0',
bottom: '0',
top: '0',
left: '0',
backgroundColor: 'rgba(58, 76, 92, 0.2)',
};
});
export const StyledModal = styled(ModalUnstyled)(({ theme }) => {
return {
width: '100vw',
height: '100vh',
position: 'fixed',
left: '0',
top: '0',
zIndex: theme.zIndex.modal,
...displayFlex('center', 'center'),
'*': {
'-webkit-tap-highlight-color': 'transparent',
outline: 'none',
},
};
});

File diff suppressed because it is too large Load Diff