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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
import CloseIcon from '@mui/icons-material/Close';
import Button from '@mui/material/Button';
import IconButton from '@mui/material/IconButton';
import Typography from '@mui/material/Typography';
import { styled } from '@mui/material/styles';
import React, { useId } from 'react';
const SlideInDialogRoot = styled('div', {
name: 'SlideInDialog-Root',
shouldForwardProp: (propName) => propName !== 'dialog',
})<{ dialog: boolean }>(({ theme, dialog }) => {
return {
maxHeight: '100%',
maxWidth: '100%',
overflow: 'hidden',
display: 'flex',
flexDirection: 'column',
'.SlideInDialog-title': {
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
padding: theme.spacing(1),
paddingLeft: theme.spacing(2),
borderBottom: `1px solid ${theme.palette.divider}`,
'& h2': {
flexGrow: 1,
},
'.MuiIconButton-root': {
flexGrow: 0,
flexShrink: 0,
marginLeft: theme.spacing(2),
},
},
'.MuiFormControlLabel-root': {
marginLeft: 0,
paddingTop: theme.spacing(1),
paddingLeft: theme.spacing(1),
'& + .MuiFormControlLabel-root': {
paddingTop: 0,
},
},
'.SlideInDialog-buttons': {
padding: theme.spacing(1),
display: 'flex',
flexDirection: 'row',
justifyContent: 'flex-end',
...(dialog
? {
marginTop: theme.spacing(1),
borderTop: `1px solid ${theme.palette.divider}`,
}
: {}),
},
};
});
export default function SlideInDialog({
close,
dialog,
title,
buttons,
children,
}: {
close: () => void;
dialog?: boolean;
title: string;
buttons: React.ReactNode | ((close: () => void) => React.ReactNode);
children?: React.ReactNode;
}): JSX.Element {
const titleId = useId();
return (
<SlideInDialogRoot
dialog={dialog ?? SlideInDialog.defaultProps.dialog}
aria-labelledby={dialog ? titleId : undefined}
>
{dialog && (
<div className="SlideInDialog-title">
<Typography variant="h6" component="h2" id={titleId}>
{title}
</Typography>
<IconButton aria-label="Close" onClick={close}>
<CloseIcon />
</IconButton>
</div>
)}
{children}
<div className="SlideInDialog-buttons">
{typeof buttons === 'function' ? buttons(close) : buttons}
{!dialog && (
<Button color="inherit" onClick={close}>
Close
</Button>
)}
</div>
</SlideInDialogRoot>
);
}
SlideInDialog.defaultProps = {
dialog: false,
children: undefined,
};
|