aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/NotificationBanner.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/components/NotificationBanner.tsx')
-rw-r--r--packages/renderer/src/components/NotificationBanner.tsx99
1 files changed, 99 insertions, 0 deletions
diff --git a/packages/renderer/src/components/NotificationBanner.tsx b/packages/renderer/src/components/NotificationBanner.tsx
new file mode 100644
index 0000000..d591e14
--- /dev/null
+++ b/packages/renderer/src/components/NotificationBanner.tsx
@@ -0,0 +1,99 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import { Typography } from '@mui/material';
22import Alert, { AlertColor } from '@mui/material/Alert';
23import Box from '@mui/material/Box';
24import { styled } from '@mui/material/styles';
25import React, { ReactNode } from 'react';
26
27const NotificationBannerRoot = styled(Alert)(({ theme }) => ({
28 paddingTop: 7,
29 paddingBottom: 6,
30 // Match the height of the location bar.
31 minHeight: 53,
32 borderRadius: 0,
33 borderBottom: `1px solid ${theme.palette.divider}`,
34 '.MuiAlert-message': {
35 flexGrow: 1,
36 paddingTop: 0,
37 paddingBottom: 4,
38 display: 'flex',
39 flexWrap: 'wrap',
40 justifyContent: 'center',
41 },
42 '.MuiAlert-action': {
43 paddingInlineStart: 0,
44 },
45}));
46
47const NotificationBannerText = styled(Typography)(({ theme }) => ({
48 fontSize: 'inherit',
49 paddingTop: theme.spacing(1),
50 paddingInlineEnd: theme.spacing(2),
51 flexGrow: 9999,
52}));
53
54const NotificationBannerButtons = styled(Box)(({ theme }) => ({
55 fontSize: 'inherit',
56 paddingTop: theme.spacing(0.5),
57 paddingInlineEnd: theme.spacing(0.5),
58 display: 'flex',
59 flexWrap: 'wrap',
60 flexGrow: 1,
61 gap: theme.spacing(1),
62 '.MuiButton-root': {
63 flexGrow: 1,
64 },
65}));
66
67export default function NotificationBanner({
68 severity,
69 icon,
70 onClose,
71 buttons,
72 children,
73}: {
74 severity?: AlertColor;
75 icon?: ReactNode;
76 onClose: () => void;
77 buttons?: ReactNode;
78 children?: ReactNode;
79}): JSX.Element {
80 return (
81 <NotificationBannerRoot
82 severity={severity ?? 'success'}
83 icon={icon ?? false}
84 onClose={onClose}
85 >
86 <NotificationBannerText>{children}</NotificationBannerText>
87 {buttons && (
88 <NotificationBannerButtons>{buttons}</NotificationBannerButtons>
89 )}
90 </NotificationBannerRoot>
91 );
92}
93
94NotificationBanner.defaultProps = {
95 severity: 'success',
96 icon: false,
97 buttons: undefined,
98 children: undefined,
99};