Skip to content

fix(Template - nextjs-app): fix assets import & ThemeProvider position #5273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions examples/nextjs-app/app/components/AppShell.tsx
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>
);
}
5 changes: 5 additions & 0 deletions examples/nextjs-app/app/components/AppShellBar.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.popover {
}
.popover::part(content) {
padding: 0;
}
73 changes: 73 additions & 0 deletions examples/nextjs-app/app/components/AppShellBar.tsx
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>
</>
);
}
8 changes: 2 additions & 6 deletions examples/nextjs-app/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import './globals.css';
import { AppShell } from '@/app/components/AppShell';
import { CssRegistry } from '@/app/CssRegistry';
import { ThemeProvider } from '@ui5/webcomponents-react';
import './globals.css';

export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
Expand All @@ -20,10 +19,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<body>
<div className="appShell">
<CssRegistry>
<ThemeProvider>
<AppShell />
<div className="appScrollContainer">{children}</div>
</ThemeProvider>
<AppShell>{children}</AppShell>
</CssRegistry>
</div>
</body>
Expand Down
2 changes: 0 additions & 2 deletions examples/nextjs-app/app/todos/[id]/page.tsx
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,
Expand Down