-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Template - nextjs-app): fix assets import & ThemeProvider position (
#5273) This PR also adds a theme-switch popover to the shellbar.
- Loading branch information
Showing
5 changed files
with
91 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,19 @@ | ||
'use client'; | ||
|
||
import navBackIcon from '@ui5/webcomponents-icons/dist/nav-back.js'; | ||
import { Button, ShellBar } from '@ui5/webcomponents-react'; | ||
import '@ui5/webcomponents-react/dist/Assets.js'; | ||
import { usePathname, useRouter } from 'next/navigation'; | ||
import { AppShellBar } from '@/app/components/AppShellBar'; | ||
import { ThemeProvider } from '@ui5/webcomponents-react'; | ||
import { ReactNode } from 'react'; | ||
|
||
export function AppShell() { | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
interface AppShellProps { | ||
children?: ReactNode | ReactNode[]; | ||
} | ||
|
||
export function AppShell({ children }: AppShellProps) { | ||
return ( | ||
<> | ||
<ShellBar | ||
primaryTitle={'UI5 Web Components for React Examples'} | ||
secondaryTitle={'NextJS - App Router'} | ||
startButton={ | ||
pathname !== '/' && ( | ||
<Button | ||
icon={navBackIcon} | ||
onClick={() => { | ||
router.back(); | ||
}} | ||
/> | ||
) | ||
} | ||
/> | ||
</> | ||
<ThemeProvider> | ||
<AppShellBar /> | ||
<div className="appScrollContainer">{children}</div> | ||
</ThemeProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.popover { | ||
} | ||
.popover::part(content) { | ||
padding: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use client'; | ||
|
||
import navBackIcon from '@ui5/webcomponents-icons/dist/nav-back.js'; | ||
import paletteIcon from '@ui5/webcomponents-icons/dist/palette.js'; | ||
import { | ||
Button, | ||
List, | ||
ListMode, | ||
ListPropTypes, | ||
ResponsivePopover, | ||
ResponsivePopoverDomRef, | ||
ShellBar, | ||
ShellBarItem, | ||
ShellBarItemPropTypes, | ||
StandardListItem | ||
} from '@ui5/webcomponents-react'; | ||
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'; | ||
|
||
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 popoverRef = useRef<ResponsivePopoverDomRef | null>(null); | ||
const [currentTheme, setCurrentTheme] = useState(getTheme); | ||
|
||
const handleThemeSwitchItemClick: ShellBarItemPropTypes['onClick'] = (e) => { | ||
popoverRef.current?.showAt(e.detail.targetRef); | ||
}; | ||
const handleThemeSwitch: ListPropTypes['onSelectionChange'] = (e) => { | ||
const { targetItem } = e.detail; | ||
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 ref={popoverRef} className={classes.popover}> | ||
<List onSelectionChange={handleThemeSwitch} headerText="Change Theme" mode={ListMode.SingleSelect}> | ||
{THEMES.map((theme) => ( | ||
<StandardListItem key={theme.key} selected={currentTheme === theme.key} data-key={theme.key}> | ||
{theme.value} | ||
</StandardListItem> | ||
))} | ||
</List> | ||
</ResponsivePopover> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
'use client'; | ||
|
||
import { Todo, todos } from '@/app/mockData/todos'; | ||
import { | ||
DatePicker, | ||
|