diff options
Diffstat (limited to 'packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx')
-rw-r--r-- | packages/renderer/src/components/sidebar/ToggleLocationBarButton.tsx | 79 |
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 | |||
21 | import IconChevronLeft from '@mui/icons-material/KeyboardDoubleArrowLeft'; | ||
22 | import IconChevronRight from '@mui/icons-material/KeyboardDoubleArrowRight'; | ||
23 | import CircularProgress from '@mui/material/CircularProgress'; | ||
24 | import IconButton from '@mui/material/IconButton'; | ||
25 | import { useTheme } from '@mui/material/styles'; | ||
26 | import { observer } from 'mobx-react-lite'; | ||
27 | import React from 'react'; | ||
28 | import { useTranslation } from 'react-i18next'; | ||
29 | |||
30 | import type RendererStore from '../../stores/RendererStore.js'; | ||
31 | import { getLocaltionBarID } from '../locationBar/LocationBar.js'; | ||
32 | |||
33 | function 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 | |||
48 | function 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 | |||
79 | export default observer(ToggleLocationBarButton); | ||