Using a dialog for confirm delete alert.

This commit is contained in:
Eric van der Vlist 2023-01-09 15:52:50 +01:00
parent 1f3c1c750e
commit 1f1b57e4b4
4 changed files with 86 additions and 47 deletions

View File

@ -0,0 +1,33 @@
import { Component, JSXElement } from 'solid-js';
import { Alert as MuiAlert } from '@suid/material';
import { AlertColor } from '@suid/material/Alert';
import Dialog from '../dialog';
interface Props {
open: boolean;
closeHandler: (event: any, reason?: string) => void;
severity?: AlertColor;
icon?: JSXElement;
action?: JSXElement;
children?: JSXElement;
}
const Alert: Component<Props> = ({
open,
closeHandler,
severity,
icon,
action,
children,
}) => {
return (
<Dialog open={open()} closeHandler={closeHandler} maxWidth={false}>
<MuiAlert severity={severity} icon={icon} action={action}>
{children}
</MuiAlert>
</Dialog>
);
};
export default Alert;

View File

@ -0,0 +1 @@
export { default } from './Alert';

View File

@ -1,4 +1,4 @@
import { Component, JSXElement } from 'solid-js'; import { Component, JSXElement, Show } from 'solid-js';
import { import {
Dialog as MuiDialog, Dialog as MuiDialog,
DialogContent, DialogContent,
@ -10,7 +10,8 @@ import CloseIcon from '@suid/icons-material/Close';
const Dialog: Component<{ const Dialog: Component<{
open: boolean; open: boolean;
fullScreen?: boolean; fullScreen?: boolean;
title: JSXElement; maxWidth?: boolean;
title?: JSXElement;
closeHandler: (event: any, reason?: string) => void; closeHandler: (event: any, reason?: string) => void;
children: JSXElement; children: JSXElement;
}> = (props) => { }> = (props) => {
@ -21,6 +22,7 @@ const Dialog: Component<{
PaperProps={{ sx: { minWidth: '300px' } }} PaperProps={{ sx: { minWidth: '300px' } }}
fullScreen={props.fullScreen} fullScreen={props.fullScreen}
> >
<Show when={props.title}>
<DialogTitle <DialogTitle
sx={{ sx={{
backgroundColor: 'rgba(14, 116, 144, 0.7)', backgroundColor: 'rgba(14, 116, 144, 0.7)',
@ -35,10 +37,12 @@ const Dialog: Component<{
</IconButton> </IconButton>
{props.title} {props.title}
</DialogTitle> </DialogTitle>
</Show>
<DialogContent <DialogContent
sx={{ sx={{
width: 'calc(100% - 60px)', width: 'calc(100% - 60px)',
paddingBottom: '2000px', paddingBottom:
props.maxWidth === undefined || props.maxWidth ? '2000px' : '2px',
}} }}
> >
{props.children} {props.children}

View File

@ -3,10 +3,11 @@ import { peekCachedSignal } from '../../workers/cached-signals';
import Tree from '../tree'; import Tree from '../tree';
import TrkIcon from '../../icons/human-footprints-svgrepo-com.svg?component-solid'; import TrkIcon from '../../icons/human-footprints-svgrepo-com.svg?component-solid';
import { TrksegViewer } from '../trkseg'; import { TrksegViewer } from '../trkseg';
import { Alert, Button, IconButton } from '@suid/material'; import { Button, IconButton } from '@suid/material';
import DeleteIcon from '@suid/icons-material/Delete'; import DeleteIcon from '@suid/icons-material/Delete';
import QuestionMarkIcon from '@suid/icons-material/QuestionMark'; import QuestionMarkIcon from '@suid/icons-material/QuestionMark';
import dispatch from '../../workers/dispatcher-main'; import dispatch from '../../workers/dispatcher-main';
import Alert from '../alert';
interface Props { interface Props {
trkId: string; trkId: string;
@ -64,7 +65,7 @@ const TrkViewer: Component<Props> = ({ trkId, restrictToHierarchy }) => {
</div> </div>
<div> <div>
<IconButton onClick={confirmDeleteHandler}> <IconButton onClick={confirmDeleteHandler}>
<DeleteIcon /> <DeleteIcon fill='white' />
</IconButton> </IconButton>
</div> </div>
</> </>
@ -82,8 +83,9 @@ const TrkViewer: Component<Props> = ({ trkId, restrictToHierarchy }) => {
</For> </For>
} }
/> />
<Show when={confirmDelete()}>
<Alert <Alert
open={confirmDelete}
closeHandler={cancelDeleteHandler}
severity='warning' severity='warning'
icon={<QuestionMarkIcon />} icon={<QuestionMarkIcon />}
action={ action={
@ -109,7 +111,6 @@ const TrkViewer: Component<Props> = ({ trkId, restrictToHierarchy }) => {
> >
Delete this track ? Delete this track ?
</Alert> </Alert>
</Show>
</> </>
); );
}; };