aboutsummaryrefslogtreecommitdiffstats
path: root/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx')
-rw-r--r--packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx79
1 files changed, 79 insertions, 0 deletions
diff --git a/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx b/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx
new file mode 100644
index 0000000..64b4ca9
--- /dev/null
+++ b/packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx
@@ -0,0 +1,79 @@
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 IconChevronLeft from '@mui/icons-material/KeyboardDoubleArrowLeft';
22import IconChevronRight from '@mui/icons-material/KeyboardDoubleArrowRight';
23import CircularProgress from '@mui/material/CircularProgress';
24import IconButton from '@mui/material/IconButton';
25import { useTheme } from '@mui/material/styles';
26import { observer } from 'mobx-react-lite';
27import React from 'react';
28import { useTranslation } from 'react-i18next';
29
30import type RendererStore from '../../stores/RendererStore.js';
31import { getLocaltionBarID } from '../locationBar/LocationBar.js';
32
33function ToggleLocationBarIcon({
34 loading,
35 show,
36}: {
37 loading: boolean;
38 show: boolean;
39}): JSX.Element {
40 const { direction } = useTheme();
41 if (loading) {
42 return <CircularProgress color="inherit" size="1.5rem" />;
43 }
44 const left = direction === 'ltr' ? show : !show;
45 return left ? <IconChevronLeft /> : <IconChevronRight />;
46}
47
48function ToggleLocationBarButton({
49 store: {
50 shared: { locationBarVisible, canToggleLocationBar },
51 settings,
52 },
53}: {
54 store: RendererStore;
55}): JSX.Element {
56 const { t } = useTranslation();
57 const { selectedService } = settings;
58
59 return (
60 /* eslint-disable react/jsx-props-no-spreading -- Conditionally set the aria-controls prop. */
61 <IconButton
62 disabled={!canToggleLocationBar}
63 aria-pressed={locationBarVisible}
64 {...(selectedService === undefined
65 ? {}
66 : { 'aria-controls': getLocaltionBarID(selectedService) })}
67 aria-label={t('toolbar.toggleLocationBar')}
68 onClick={() => settings.toggleLocationBar()}
69 >
70 {/* eslint-enable react/jsx-props-no-spreading */}
71 <ToggleLocationBarIcon
72 loading={selectedService?.loading ?? false}
73 show={locationBarVisible}
74 />
75 </IconButton>
76 );
77}
78
79export default observer(ToggleLocationBarButton);