mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
feat: reusable dialog component
This commit is contained in:
committed by
Carlos Valente
parent
97691eba05
commit
7fdda1c969
@@ -0,0 +1,43 @@
|
|||||||
|
.dialog {
|
||||||
|
position: fixed;
|
||||||
|
top: 10%;
|
||||||
|
left: 50%;
|
||||||
|
|
||||||
|
z-index: $zindex-dialog;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
|
||||||
|
padding-inline: 1rem;
|
||||||
|
min-width: min(420px, 90vw);
|
||||||
|
|
||||||
|
background-color: $gray-1250;
|
||||||
|
color: $ui-white;
|
||||||
|
border-radius: 3px;
|
||||||
|
box-shadow: $box-shadow-l1;
|
||||||
|
border: 1px solid $gray-1200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
padding-block: 1rem;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
|
||||||
|
max-height: min(80vh, 600px);
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
padding-block: 1rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: end;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import type { ReactNode } from 'react';
|
||||||
|
import { IoClose } from 'react-icons/io5';
|
||||||
|
import { Dialog as BaseDialog } from '@base-ui-components/react/dialog';
|
||||||
|
|
||||||
|
import IconButton from '../buttons/IconButton';
|
||||||
|
|
||||||
|
import style from './Dialog.module.scss';
|
||||||
|
|
||||||
|
interface DialogProps {
|
||||||
|
isOpen: boolean;
|
||||||
|
title: string;
|
||||||
|
showCloseButton?: boolean;
|
||||||
|
bodyElements: ReactNode;
|
||||||
|
footerElements: ReactNode;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Dialog({ isOpen, title, showCloseButton, bodyElements, footerElements, onClose }: DialogProps) {
|
||||||
|
return (
|
||||||
|
<BaseDialog.Root
|
||||||
|
open={isOpen}
|
||||||
|
onOpenChange={(isOpen) => {
|
||||||
|
if (!isOpen) onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<BaseDialog.Portal>
|
||||||
|
<BaseDialog.Popup className={style.dialog}>
|
||||||
|
<div className={style.title}>
|
||||||
|
{title}
|
||||||
|
{showCloseButton && (
|
||||||
|
<IconButton variant='subtle-white' onClick={onClose}>
|
||||||
|
<IoClose />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className={style.body}>{bodyElements}</div>
|
||||||
|
<div className={style.footer}>{footerElements}</div>
|
||||||
|
</BaseDialog.Popup>
|
||||||
|
</BaseDialog.Portal>
|
||||||
|
</BaseDialog.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user