Spaces:
Running
Running
File size: 1,887 Bytes
f23825d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
import { keyframes } from "@emotion/react"
import styled from "@emotion/styled"
import {
Content,
DialogProps as Props,
Overlay,
Portal,
Root,
} from "@radix-ui/react-dialog"
import { FC } from "react"
const overlayShow = keyframes`
from {
opacity: 0;
}
to {
opacity: 1;
}
`
const contentShow = keyframes`
from {
opacity: 0;
transform: translate(-50%, -48%) scale(0.96);
}
to {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
`
const StyledOverlay = styled(Overlay)`
background-color: rgba(0, 0, 0, 0.3);
position: fixed;
inset: 0;
animation: ${overlayShow} 150ms cubic-bezier(0.16, 1, 0.3, 1);
`
const StyledContent = styled(Content)`
background-color: ${({ theme }) => theme.backgroundColor};
border-radius: 0.5rem;
box-shadow: 0 0.5rem 3rem ${({ theme }) => theme.shadowColor};
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin-bottom: 1rem;
max-width: 30rem;
max-height: 85vh;
padding: 1rem;
animation: ${contentShow} 150ms cubic-bezier(0.16, 1, 0.3, 1);
display: flex;
flex-direction: column;
pointer-events: auto;
overflow: hidden;
&:focus {
outline: none;
}
`
export type DialogProps = Props & {
style?: React.CSSProperties
}
export const Dialog: FC<DialogProps> = ({ children, style, ...props }) => (
<Root {...props}>
<Portal>
<StyledOverlay />
<StyledContent style={style}>{children}</StyledContent>
</Portal>
</Root>
)
export const DialogTitle = styled.div`
font-size: 1.25rem;
color: ${({ theme }) => theme.textColor};
margin-bottom: 1.5rem;
`
export const DialogContent = styled.div`
overflow-x: hidden;
overflow-y: auto;
margin-bottom: 1rem;
`
export const DialogActions = styled.div`
display: flex;
justify-content: flex-end;
& > *:not(:last-child) {
margin-right: 1rem;
}
`
|