Skip to content

Commit 391dd13

Browse files
authored
chore: update Next.js App Router and Vite examples to v2 (#6270)
1 parent 747aa12 commit 391dd13

17 files changed

+282
-836
lines changed

examples/nextjs-app/app/components/AppShellBar.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ import paletteIcon from '@ui5/webcomponents-icons/dist/palette.js';
55
import {
66
Button,
77
List,
8-
ListMode,
98
ListPropTypes,
109
ResponsivePopover,
1110
ResponsivePopoverDomRef,
1211
ShellBar,
1312
ShellBarItem,
1413
ShellBarItemPropTypes,
15-
StandardListItem
14+
ListItemStandard,
15+
ButtonDomRef
1616
} from '@ui5/webcomponents-react';
1717
import { usePathname, useRouter } from 'next/navigation';
1818
import { useRef, useState } from 'react';
1919
import classes from './AppShellBar.module.css';
2020
import { getTheme, setTheme } from '@ui5/webcomponents-base/dist/config/Theme.js';
21+
import ListMode from '@ui5/webcomponents/dist/types/ListSelectionMode.js';
2122

2223
const THEMES = [
2324
{ key: 'sap_horizon', value: 'Morning Horizon (Light)' },
@@ -29,15 +30,17 @@ const THEMES = [
2930
export function AppShellBar() {
3031
const router = useRouter();
3132
const pathname = usePathname();
32-
const popoverRef = useRef<ResponsivePopoverDomRef | null>(null);
33+
const popoverOpenerRef = useRef<ButtonDomRef | undefined>(undefined);
34+
const [popoverOpen, setPopoverOpen] = useState(false);
3335
const [currentTheme, setCurrentTheme] = useState(getTheme);
3436

3537
const handleThemeSwitchItemClick: ShellBarItemPropTypes['onClick'] = (e) => {
36-
popoverRef.current?.showAt(e.detail.targetRef);
38+
popoverOpenerRef.current = e.detail.targetRef as ButtonDomRef;
39+
setPopoverOpen(true);
3740
};
3841
const handleThemeSwitch: ListPropTypes['onSelectionChange'] = (e) => {
3942
const { targetItem } = e.detail;
40-
setTheme(targetItem.dataset.key!);
43+
void setTheme(targetItem.dataset.key!);
4144
setCurrentTheme(targetItem.dataset.key!);
4245
};
4346

@@ -59,12 +62,19 @@ export function AppShellBar() {
5962
>
6063
<ShellBarItem icon={paletteIcon} text="Change Theme" onClick={handleThemeSwitchItemClick} />
6164
</ShellBar>
62-
<ResponsivePopover ref={popoverRef} className={classes.popover}>
63-
<List onSelectionChange={handleThemeSwitch} headerText="Change Theme" mode={ListMode.SingleSelect}>
65+
<ResponsivePopover
66+
className={classes.popover}
67+
open={popoverOpen}
68+
opener={popoverOpenerRef.current}
69+
onClose={(e) => {
70+
setPopoverOpen(false);
71+
}}
72+
>
73+
<List onSelectionChange={handleThemeSwitch} headerText="Change Theme" selectionMode={ListMode.Single}>
6474
{THEMES.map((theme) => (
65-
<StandardListItem key={theme.key} selected={currentTheme === theme.key} data-key={theme.key}>
75+
<ListItemStandard key={theme.key} selected={currentTheme === theme.key} data-key={theme.key}>
6676
{theme.value}
67-
</StandardListItem>
77+
</ListItemStandard>
6878
))}
6979
</List>
7080
</ResponsivePopover>

examples/nextjs-app/app/components/TodoList.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use client';
2-
32
import { Todo } from '@/app/mockData/todos';
4-
import { List, ListItemType, ListPropTypes, StandardListItem, ValueState } from '@ui5/webcomponents-react';
3+
import { List, ListPropTypes, ListItemStandard } from '@ui5/webcomponents-react';
54
import { useRouter } from 'next/navigation';
65

6+
import ListItemType from '@ui5/webcomponents/dist/types/ListItemType.js';
7+
import ValueState from '@ui5/webcomponents-base/dist/types/ValueState.js';
8+
79
interface TodoListProps {
810
items: Todo[];
911
}
@@ -18,15 +20,15 @@ export function TodoList({ items }: TodoListProps) {
1820
<List onItemClick={handleTodoClick}>
1921
{items.map((todo) => {
2022
return (
21-
<StandardListItem
23+
<ListItemStandard
2224
key={todo.id}
2325
data-id={todo.id}
2426
type={ListItemType.Navigation}
2527
additionalText={`${!todo.completed ? 'Not ' : ''}Completed`}
26-
additionalTextState={todo.completed ? ValueState.Success : ValueState.None}
28+
additionalTextState={todo.completed ? ValueState.Positive : ValueState.None}
2729
>
2830
{todo.title}
29-
</StandardListItem>
31+
</ListItemStandard>
3032
);
3133
})}
3234
</List>

examples/nextjs-app/app/globals.css

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55

66
html,
77
body {
8+
background: var(--sapBackgroundColor);
89
max-width: 100vw;
910
overflow-x: hidden;
1011
padding: 0;
1112
margin: 0;
1213
}
1314

1415
.appShell {
15-
height: 100vh;
16-
width: 100vw;
17-
overflow: hidden;
16+
height: 100vh;
17+
width: 100vw;
18+
overflow: hidden;
1819
}
1920

2021
.appScrollContainer {
21-
height: calc(100vh - 3.25rem);
22-
width: 100vw;
23-
overflow-y: auto;
24-
position: relative;
25-
}
22+
height: calc(100vh - 3.25rem);
23+
width: 100vw;
24+
overflow-y: auto;
25+
position: relative;
26+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.container {
2-
width: 100%;
3-
height: 100%;
4-
display: flex;
5-
align-items: center;
6-
justify-content: center;
7-
}
2+
width: 100%;
3+
height: 100%;
4+
display: flex;
5+
align-items: center;
6+
justify-content: center;
7+
}

examples/nextjs-app/app/loading.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { BusyIndicator, BusyIndicatorSize } from '@ui5/webcomponents-react';
1+
import { BusyIndicator } from '@ui5/webcomponents-react';
22
import classes from './loading.module.css';
33

4+
import BusyIndicatorSize from '@ui5/webcomponents/dist/types/BusyIndicatorSize.js';
5+
46
export default function HomeLoading() {
57
return (
68
<div className={classes.container}>
7-
<BusyIndicator active size={BusyIndicatorSize.Large} delay={0} />
9+
<BusyIndicator active size={BusyIndicatorSize.L} delay={0} />
810
</div>
911
);
1012
}

examples/nextjs-app/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default async function Home() {
1212

1313
return (
1414
<>
15-
<Page header={<Bar startContent={<Title>My Todos</Title>} />}>
15+
<Page header={<Bar startContent={<Title wrappingType="None">My Todos</Title>} />} fixedFooter>
1616
<TodoList items={todoList} />
1717
</Page>
1818
</>

examples/nextjs-app/app/todos/[id]/page.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {
66
Form,
77
FormItem,
88
Input,
9+
Label,
910
MessageStrip,
10-
MessageStripDesign,
1111
Switch,
12-
TextArea
12+
TextArea,
13+
Title
1314
} from '@ui5/webcomponents-react';
15+
import MessageStripDesign from '@ui5/webcomponents/dist/types/MessageStripDesign.js';
1416

1517
export default async function TodoDetails({ params }: { params: { id: string } }) {
1618
// this is a very simple mock which mimics data fetching
@@ -22,22 +24,22 @@ export default async function TodoDetails({ params }: { params: { id: string } }
2224

2325
return (
2426
<>
25-
<DynamicPage showHideHeaderButton={false} headerTitle={<DynamicPageTitle header={todo?.title} />}>
27+
<DynamicPage titleArea={<DynamicPageTitle heading={<Title>{todo?.title}</Title>} />}>
2628
<MessageStrip design={MessageStripDesign.Information}>
2729
{`Since this is only a demo app, adjustments made here on this page won't be reflected in the todo list.`}
2830
</MessageStrip>
2931
<Form>
30-
<FormItem label={'Title'}>
32+
<FormItem labelContent={<Label wrappingType="None">Title</Label>}>
3133
<Input value={todo?.title} />
3234
</FormItem>
33-
<FormItem label={'Details'}>
34-
<TextArea value={todo?.details} growing growingMaxLines={10} />
35+
<FormItem labelContent={<Label wrappingType="None">Details</Label>}>
36+
<TextArea value={todo?.details} growing growingMaxRows={10} />
3537
</FormItem>
3638

37-
<FormItem label={'Due Date'}>
39+
<FormItem labelContent={<Label wrappingType="None">Due Date</Label>}>
3840
<DatePicker />
3941
</FormItem>
40-
<FormItem label={'Completed'}>
42+
<FormItem labelContent={<Label wrappingType="None">Completed</Label>}>
4143
<Switch checked={todo?.completed} />
4244
</FormItem>
4345
</Form>

0 commit comments

Comments
 (0)