diff options
Diffstat (limited to 'packages/renderer/src/components/ServiceIcon.tsx')
-rw-r--r-- | packages/renderer/src/components/ServiceIcon.tsx | 119 |
1 files changed, 0 insertions, 119 deletions
diff --git a/packages/renderer/src/components/ServiceIcon.tsx b/packages/renderer/src/components/ServiceIcon.tsx deleted file mode 100644 index 83b2a5f..0000000 --- a/packages/renderer/src/components/ServiceIcon.tsx +++ /dev/null | |||
@@ -1,119 +0,0 @@ | |||
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 Badge from '@mui/material/Badge'; | ||
22 | import { styled, useTheme } from '@mui/material/styles'; | ||
23 | import { Service } from '@sophie/shared'; | ||
24 | import { observer } from 'mobx-react-lite'; | ||
25 | import React from 'react'; | ||
26 | |||
27 | const ServiceIconRoot = styled('div', { | ||
28 | name: 'ServiceIcon', | ||
29 | slot: 'Root', | ||
30 | })(({ theme }) => ({ | ||
31 | width: 36, | ||
32 | height: 36, | ||
33 | borderRadius: theme.shape.borderRadius, | ||
34 | background: 'currentColor', | ||
35 | display: 'flex', | ||
36 | justifyContent: 'center', | ||
37 | alignItems: 'center', | ||
38 | })); | ||
39 | |||
40 | const ServiceIconText = styled('div', { | ||
41 | name: 'ServiceIcon', | ||
42 | slot: 'Text', | ||
43 | })(({ theme }) => ({ | ||
44 | display: 'inline-block', | ||
45 | flex: 0, | ||
46 | fontSize: theme.typography.pxToRem(24), | ||
47 | color: theme.palette.primary.contrastText, | ||
48 | })); | ||
49 | |||
50 | const IndirectMessageBadge = styled(Badge)(({ theme }) => ({ | ||
51 | '& .MuiBadge-dot': { | ||
52 | // The indirect message badge floats ouside the icon in the middle. | ||
53 | top: '50%', | ||
54 | ...(theme.direction === 'ltr' | ||
55 | ? { | ||
56 | left: theme.spacing(-1), | ||
57 | } | ||
58 | : { | ||
59 | right: theme.spacing(-1), | ||
60 | }), | ||
61 | background: | ||
62 | theme.palette.mode === 'dark' | ||
63 | ? theme.palette.text.primary | ||
64 | : 'currentColor', | ||
65 | }, | ||
66 | })); | ||
67 | |||
68 | const DirectMessageBadge = styled(Badge)(({ theme }) => ({ | ||
69 | '& .MuiBadge-badge': { | ||
70 | // Move the badge closer to the icon so that even "99+" messages can fit in the sidebar. | ||
71 | ...(theme.direction === 'ltr' | ||
72 | ? { | ||
73 | right: theme.spacing(0.25), | ||
74 | } | ||
75 | : { | ||
76 | left: theme.spacing(0.25), | ||
77 | }), | ||
78 | top: theme.spacing(0.25), | ||
79 | // Set the badge apart from the icon with a shadow (a border would be too heavy). | ||
80 | boxShadow: theme.shadows[1], | ||
81 | // Add a bit more emphasis to the badge. | ||
82 | fontWeight: 700, | ||
83 | }, | ||
84 | })); | ||
85 | |||
86 | function ServiceIcon({ service }: { service: Service }): JSX.Element { | ||
87 | const { direction } = useTheme(); | ||
88 | const { | ||
89 | settings: { name }, | ||
90 | directMessageCount, | ||
91 | indirectMessageCount, | ||
92 | } = service; | ||
93 | |||
94 | return ( | ||
95 | <IndirectMessageBadge | ||
96 | badgeContent={indirectMessageCount} | ||
97 | variant="dot" | ||
98 | anchorOrigin={{ | ||
99 | vertical: 'top', | ||
100 | horizontal: direction === 'ltr' ? 'left' : 'right', | ||
101 | }} | ||
102 | > | ||
103 | <DirectMessageBadge | ||
104 | badgeContent={directMessageCount} | ||
105 | color="error" | ||
106 | anchorOrigin={{ | ||
107 | vertical: 'top', | ||
108 | horizontal: direction === 'ltr' ? 'right' : 'left', | ||
109 | }} | ||
110 | > | ||
111 | <ServiceIconRoot> | ||
112 | <ServiceIconText>{name.length > 0 ? name[0] : '?'}</ServiceIconText> | ||
113 | </ServiceIconRoot> | ||
114 | </DirectMessageBadge> | ||
115 | </IndirectMessageBadge> | ||
116 | ); | ||
117 | } | ||
118 | |||
119 | export default observer(ServiceIcon); | ||