-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathAppShell.tsx
More file actions
111 lines (107 loc) · 4.3 KB
/
AppShell.tsx
File metadata and controls
111 lines (107 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import navBackIcon from '@ui5/webcomponents-icons/dist/nav-back.js';
import paletteIcon from '@ui5/webcomponents-icons/dist/palette.js';
import { Avatar } from '@ui5/webcomponents-react/Avatar';
import { Breadcrumbs } from '@ui5/webcomponents-react/Breadcrumbs';
import { Button, type ButtonDomRef } from '@ui5/webcomponents-react/Button';
import { DynamicPage } from '@ui5/webcomponents-react/DynamicPage';
import { DynamicPageTitle } from '@ui5/webcomponents-react/DynamicPageTitle';
import { List, type ListPropTypes } from '@ui5/webcomponents-react/List';
import { ResponsivePopover } from '@ui5/webcomponents-react/ResponsivePopover';
import { ShellBar } from '@ui5/webcomponents-react/ShellBar';
import { ShellBarItem, type ShellBarItemPropTypes } from '@ui5/webcomponents-react/ShellBarItem';
import { ListItemStandard } from '@ui5/webcomponents-react/ListItemStandard';
import { Title } from '@ui5/webcomponents-react/Title';
import { useRef, useState } from 'react';
import { Outlet, useLocation, useMatches, useNavigate } from 'react-router';
import { SingleTodoHandle } from './main.tsx';
import { Todo } from './mockImplementations/mockData.ts';
import classes from './AppShell.module.css';
import { getTheme, setTheme } from '@ui5/webcomponents-base/dist/config/Theme.js';
import ListMode from '@ui5/webcomponents/dist/types/ListSelectionMode.js';
const THEMES = [
{ key: 'sap_horizon', value: 'Morning Horizon (Light)' },
{ key: 'sap_horizon_dark', value: 'Evening Horizon (Dark)' },
{ key: 'sap_horizon_hcb', value: 'Horizon High Contrast Black' },
{ key: 'sap_horizon_hcw', value: 'Horizon High Contrast White' },
];
function AppShell() {
const popoverOpenerRef = useRef<ButtonDomRef | undefined>(undefined);
const [popoverOpen, setPopoverOpen] = useState(false);
const navigate = useNavigate();
const location = useLocation();
const matches = useMatches();
const [currentTheme, setCurrentTheme] = useState(getTheme);
const detailViewMatch = matches.find((match) => Boolean(match.handle));
const detailViewMatchHandle = detailViewMatch?.handle as SingleTodoHandle;
const detailViewMatchData = detailViewMatch?.data as Todo;
const handleLogoClick = () => {
navigate('/');
};
const handleThemeSwitchItemClick: ShellBarItemPropTypes['onClick'] = (e) => {
popoverOpenerRef.current = e.detail.targetRef as ButtonDomRef;
setPopoverOpen(true);
};
const handleThemeSwitch: ListPropTypes['onSelectionChange'] = (e) => {
const { targetItem } = e.detail;
void setTheme(targetItem.dataset.key!);
setCurrentTheme(targetItem.dataset.key!);
setPopoverOpen(false);
};
return (
<>
<ShellBar
logo={<img src="/vite.svg" alt={'Vite Logo'} />}
primaryTitle="UI5 Web Components for React Examples"
secondaryTitle="Vite.js"
profile={
<Avatar>
<img src="/person.png" alt="Profile Avatar" />
</Avatar>
}
onLogoClick={handleLogoClick}
startButton={
<Button
icon={navBackIcon}
onClick={() => {
navigate(-1);
}}
disabled={!location.key || location.key === 'default'}
/>
}
>
<ShellBarItem icon={paletteIcon} text="Change Theme" onClick={handleThemeSwitchItemClick} />
</ShellBar>
<DynamicPage
className={classes.dynamicPage}
titleArea={
<DynamicPageTitle
heading={<Title>{detailViewMatchHandle?.getTitle(detailViewMatchData) ?? 'My To-Do List'}</Title>}
breadcrumbs={<Breadcrumbs>{detailViewMatchHandle?.getBreadCrumbItems(detailViewMatchData)}</Breadcrumbs>}
/>
}
>
<Outlet />
</DynamicPage>
<ResponsivePopover
className={classes.popover}
open={popoverOpen}
opener={popoverOpenerRef.current}
onClose={() => {
setPopoverOpen(false);
}}
>
<List onSelectionChange={handleThemeSwitch} headerText="Change Theme" selectionMode={ListMode.Single}>
{THEMES.map((theme) => (
<ListItemStandard
key={theme.key}
selected={currentTheme === theme.key}
data-key={theme.key}
text={theme.value}
/>
))}
</List>
</ResponsivePopover>
</>
);
}
export default AppShell;