aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/ServiceSwitcher.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/components/ServiceSwitcher.tsx')
-rw-r--r--packages/renderer/src/components/ServiceSwitcher.tsx88
1 files changed, 88 insertions, 0 deletions
diff --git a/packages/renderer/src/components/ServiceSwitcher.tsx b/packages/renderer/src/components/ServiceSwitcher.tsx
new file mode 100644
index 0000000..b454451
--- /dev/null
+++ b/packages/renderer/src/components/ServiceSwitcher.tsx
@@ -0,0 +1,88 @@
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 Tab from '@mui/material/Tab';
22import Tabs from '@mui/material/Tabs';
23import { alpha, styled } from '@mui/material/styles';
24import { observer } from 'mobx-react-lite';
25import React, { useState } from 'react';
26
27import ServiceIcon from './ServiceIcon';
28import { useStore } from './StoreProvider';
29
30const ServiceSwitcherRoot = styled(Tabs, {
31 name: 'ServiceSwitcher',
32 slot: 'Root',
33})(({ theme }) => ({
34 '.MuiTabs-indicator': {
35 width: 3,
36 ...(theme.direction === 'ltr'
37 ? {
38 left: 0,
39 right: 'auto',
40 }
41 : {
42 left: 'auto',
43 right: 0,
44 }),
45 },
46}));
47
48const ServiceSwitcherTab = styled(Tab, {
49 name: 'ServiceSwitcher',
50 slot: 'Tab',
51})(({ theme }) => ({
52 minWidth: 0,
53 transition: theme.transitions.create('background-color', {
54 duration: theme.transitions.duration.shortest,
55 }),
56 '&.Mui-selected': {
57 backgroundColor:
58 theme.palette.mode === 'dark'
59 ? alpha(theme.palette.text.primary, 0.16)
60 : alpha(theme.palette.primary.light, 0.3),
61 },
62}));
63
64export default observer(() => {
65 const { services } = useStore();
66 // TODO Move this to the `SharedStore`.
67 const [selectedService, setSelectedService] = useState<string | boolean>(
68 false,
69 );
70
71 return (
72 <ServiceSwitcherRoot
73 variant="scrollable"
74 orientation="vertical"
75 value={selectedService}
76 onChange={(_event, newValue: string) => setSelectedService(newValue)}
77 >
78 {services.map((service) => (
79 <ServiceSwitcherTab
80 key={service.id}
81 value={service.id}
82 icon={<ServiceIcon name={service.name} />}
83 aria-label={service.name}
84 />
85 ))}
86 </ServiceSwitcherRoot>
87 );
88});