-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathAppShellBar.tsx
More file actions
80 lines (75 loc) · 2.92 KB
/
AppShellBar.tsx
File metadata and controls
80 lines (75 loc) · 2.92 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
'use client';
import navBackIcon from '@ui5/webcomponents-icons/dist/nav-back.js';
import paletteIcon from '@ui5/webcomponents-icons/dist/palette.js';
import { Button, type ButtonDomRef } from '@ui5/webcomponents-react/Button';
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 { usePathname, useRouter } from 'next/navigation';
import { useRef, useState } from 'react';
import classes from './AppShellBar.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' },
];
export function AppShellBar() {
const router = useRouter();
const pathname = usePathname();
const popoverOpenerRef = useRef<ButtonDomRef | undefined>(undefined);
const [popoverOpen, setPopoverOpen] = useState(false);
const [currentTheme, setCurrentTheme] = useState(getTheme);
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!);
};
return (
<>
<ShellBar
primaryTitle={'UI5 Web Components for React Examples'}
secondaryTitle={'NextJS - App Router'}
startButton={
pathname !== '/' && (
<Button
icon={navBackIcon}
onClick={() => {
router.back();
}}
/>
)
}
>
<ShellBarItem icon={paletteIcon} text="Change Theme" onClick={handleThemeSwitchItemClick} />
</ShellBar>
<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>
</>
);
}