Fix alert styles and overlays
* Update alert styles * Fix Overlay component to take onClick event handler as a prop
This commit is contained in:
parent
0e10ac5a48
commit
d4ad809dc9
4 changed files with 44 additions and 25 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
.AlertWrapper {
|
.wrapper {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
@ -10,7 +10,17 @@
|
||||||
z-index: 31;
|
z-index: 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
.Alert {
|
.overlay {
|
||||||
|
isolation: isolate;
|
||||||
|
position: fixed;
|
||||||
|
z-index: 9;
|
||||||
|
top: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert {
|
||||||
animation: $duration-modal-open cubic-bezier(0.16, 1, 0.3, 1) 0s 1 normal none
|
animation: $duration-modal-open cubic-bezier(0.16, 1, 0.3, 1) 0s 1 normal none
|
||||||
running openModalDesktop;
|
running openModalDesktop;
|
||||||
background: var(--dialog-bg);
|
background: var(--dialog-bg);
|
||||||
|
|
@ -52,9 +62,21 @@
|
||||||
align-self: center;
|
align-self: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
.Button {
|
& > * {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes openModalDesktop {
|
||||||
|
0% {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.96);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
// opacity: 1;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,44 +21,43 @@ const Alert = (props: Props) => {
|
||||||
return (
|
return (
|
||||||
<AlertDialog.Root open={props.open}>
|
<AlertDialog.Root open={props.open}>
|
||||||
<AlertDialog.Portal>
|
<AlertDialog.Portal>
|
||||||
<AlertDialog.Overlay className="Overlay" onClick={props.cancelAction} />
|
<Overlay
|
||||||
<div className="AlertWrapper">
|
open={props.open}
|
||||||
|
visible={true}
|
||||||
|
onClick={props.cancelAction}
|
||||||
|
/>
|
||||||
|
<div className={styles.wrapper}>
|
||||||
<AlertDialog.Content
|
<AlertDialog.Content
|
||||||
className="Alert"
|
className={styles.alert}
|
||||||
onEscapeKeyDown={props.cancelAction}
|
onEscapeKeyDown={props.cancelAction}
|
||||||
>
|
>
|
||||||
{props.title ? (
|
{props.title && (
|
||||||
<AlertDialog.Title>{props.title}</AlertDialog.Title>
|
<AlertDialog.Title>{props.title}</AlertDialog.Title>
|
||||||
) : (
|
|
||||||
''
|
|
||||||
)}
|
)}
|
||||||
<AlertDialog.Description className="description">
|
<AlertDialog.Description className={styles.description}>
|
||||||
{props.message}
|
{props.message}
|
||||||
</AlertDialog.Description>
|
</AlertDialog.Description>
|
||||||
<div className="buttons">
|
<div className={styles.buttons}>
|
||||||
<AlertDialog.Cancel asChild>
|
<AlertDialog.Cancel asChild>
|
||||||
<Button
|
<Button
|
||||||
contained={true}
|
bound={true}
|
||||||
onClick={props.cancelAction}
|
onClick={props.cancelAction}
|
||||||
text={props.cancelActionText}
|
text={props.cancelActionText}
|
||||||
/>
|
/>
|
||||||
</AlertDialog.Cancel>
|
</AlertDialog.Cancel>
|
||||||
{props.primaryAction ? (
|
{props.primaryAction && (
|
||||||
<AlertDialog.Action asChild>
|
<AlertDialog.Action asChild>
|
||||||
<Button
|
<Button
|
||||||
className={props.primaryActionClassName}
|
className={props.primaryActionClassName}
|
||||||
contained={true}
|
bound={true}
|
||||||
onClick={props.primaryAction}
|
onClick={props.primaryAction}
|
||||||
text={props.primaryActionText}
|
text={props.primaryActionText}
|
||||||
/>
|
/>
|
||||||
</AlertDialog.Action>
|
</AlertDialog.Action>
|
||||||
) : (
|
|
||||||
''
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</AlertDialog.Content>
|
</AlertDialog.Content>
|
||||||
</div>
|
</div>
|
||||||
<Overlay open={props.open} visible={true} />
|
|
||||||
</AlertDialog.Portal>
|
</AlertDialog.Portal>
|
||||||
</AlertDialog.Root>
|
</AlertDialog.Root>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
.overlay {
|
.overlay {
|
||||||
|
pointer-events: auto;
|
||||||
isolation: isolate;
|
isolation: isolate;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: 9;
|
z-index: 9;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import styles from './index.module.scss'
|
||||||
interface Props {
|
interface Props {
|
||||||
visible: boolean
|
visible: boolean
|
||||||
open: boolean
|
open: boolean
|
||||||
|
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
|
|
@ -12,13 +13,7 @@ const defaultProps = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Overlay = React.forwardRef<HTMLDivElement, Props>(function Overlay(
|
const Overlay = React.forwardRef<HTMLDivElement, Props>(function Overlay(
|
||||||
{
|
{ visible: displayed, open, onClick }: Props,
|
||||||
visible: displayed,
|
|
||||||
open,
|
|
||||||
}: {
|
|
||||||
visible: boolean
|
|
||||||
open: boolean
|
|
||||||
},
|
|
||||||
forwardedRef
|
forwardedRef
|
||||||
) {
|
) {
|
||||||
const [visible, setVisible] = useState(open)
|
const [visible, setVisible] = useState(open)
|
||||||
|
|
@ -42,7 +37,9 @@ const Overlay = React.forwardRef<HTMLDivElement, Props>(function Overlay(
|
||||||
}, [open])
|
}, [open])
|
||||||
|
|
||||||
function handleClick(event: React.MouseEvent<HTMLDivElement, MouseEvent>) {
|
function handleClick(event: React.MouseEvent<HTMLDivElement, MouseEvent>) {
|
||||||
event.stopPropagation()
|
// event.stopPropagation()
|
||||||
|
console.log('Hey!')
|
||||||
|
if (onClick) onClick(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
return visible ? (
|
return visible ? (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue