diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-03-28 23:37:15 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-05-16 00:54:56 +0200 |
commit | 04555cc62c9cded08c3090288fa372d961c50737 (patch) | |
tree | 4566893892216446dfe24490c98881316b97cb41 /packages/renderer/src/components/NotificationBanner.tsx | |
parent | design: Increase location bar UI density (diff) | |
download | sophie-04555cc62c9cded08c3090288fa372d961c50737.tar.gz sophie-04555cc62c9cded08c3090288fa372d961c50737.tar.zst sophie-04555cc62c9cded08c3090288fa372d961c50737.zip |
feat: New window banner
* Add renderer code for notification banners with buttons
* Handle new window open requests by denying them and displaying
a notification
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/renderer/src/components/NotificationBanner.tsx')
-rw-r--r-- | packages/renderer/src/components/NotificationBanner.tsx | 99 |
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 | |||
21 | import { Typography } from '@mui/material'; | ||
22 | import Alert, { AlertColor } from '@mui/material/Alert'; | ||
23 | import Box from '@mui/material/Box'; | ||
24 | import { styled } from '@mui/material/styles'; | ||
25 | import React, { ReactNode } from 'react'; | ||
26 | |||
27 | const 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 | |||
47 | const NotificationBannerText = styled(Typography)(({ theme }) => ({ | ||
48 | fontSize: 'inherit', | ||
49 | paddingTop: theme.spacing(1), | ||
50 | paddingInlineEnd: theme.spacing(2), | ||
51 | flexGrow: 9999, | ||
52 | })); | ||
53 | |||
54 | const 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 | |||
67 | export 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 | |||
94 | NotificationBanner.defaultProps = { | ||
95 | severity: 'success', | ||
96 | icon: false, | ||
97 | buttons: undefined, | ||
98 | children: undefined, | ||
99 | }; | ||