Skip to content

Commit 2697cdd

Browse files
manoloCopilot
andauthored
Migrate theme and styles to Vaadin 25.0 approach (#11)
* removed deprecated @theme annotation, moved css to resources folder * Fix logo and lumo utility styles * simplify styles and fix footer position * use tabs for menu items, aligning with starters and simplifying css * better styles for navbar * Apply suggestion from @Copilot * fix css for footer and contain * simpler css * show correctly the full stacktrace exception in the view --------- Co-authored-by: Copilot <[email protected]>
1 parent 21abd51 commit 2697cdd

File tree

17 files changed

+170
-217
lines changed

17 files changed

+170
-217
lines changed

src/main/frontend/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<meta charset="UTF-8" />
99
<meta name="viewport" content="width=device-width, initial-scale=1" />
1010
<style>
11-
body, #outlet {
11+
html, body, #outlet {
1212
height: 100vh;
1313
width: 100%;
1414
margin: 0;

src/main/frontend/themes/petclinic/main-content-layout.css

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/main/frontend/themes/petclinic/main-layout.css

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/main/frontend/themes/petclinic/navigation.css

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/main/frontend/themes/petclinic/theme-editor.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/main/frontend/themes/petclinic/theme.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/main/frontend/views/@index.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ViewConfig } from '@vaadin/hilla-file-router/types.js';
2-
import { useSignal } from '@vaadin/hilla-react-signals';
32
import {VerticalLayout} from "@vaadin/react-components";
43
import {key, translate} from "@vaadin/hilla-react-i18n";
54

@@ -9,15 +8,11 @@ export const config: ViewConfig = {
98
};
109

1110
export default function HomeView() {
12-
const name = useSignal('');
13-
1411
return (
15-
<>
16-
<VerticalLayout theme="padding spacing"
17-
className="w-full items-center justify-center">
18-
<h2>{translate(key`welcome`)}</h2>
19-
<img src="./images/pets.png" alt="Pets" />
20-
</VerticalLayout>
21-
</>
12+
<VerticalLayout theme="padding spacing"
13+
className="w-full items-center justify-center home">
14+
<h2>{translate(key`welcome`)}</h2>
15+
<img src="./images/pets.png" alt="Pets" />
16+
</VerticalLayout>
2217
);
2318
}

src/main/frontend/views/@layout.tsx

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,83 @@ import { Button } from '@vaadin/react-components/Button';
22
import { createMenuItems, useViewConfig } from '@vaadin/hilla-file-router/runtime.js';
33
import {
44
AppLayout,
5-
DrawerToggle,
65
Icon,
7-
SideNav,
8-
SideNavItem,
9-
VerticalLayout
6+
Tabs,
7+
Tab
108
} from '@vaadin/react-components';
11-
import { Suspense, useEffect } from 'react';
12-
import { Outlet, useLocation, useNavigate } from 'react-router';
9+
import { Suspense, useEffect, useRef } from 'react';
10+
import { Outlet, useLocation, NavLink } from 'react-router';
1311
import {HorizontalLayout} from "@vaadin/react-components/HorizontalLayout.js";
1412
import '@vaadin/icons';
1513
import {key, translate, i18n} from "@vaadin/hilla-react-i18n";
1614

15+
1716
import { ErrorBoundary } from "react-error-boundary";
1817

1918
const defaultTitle = document.title;
2019

2120
// @ts-ignore
2221
function Fallback({ error, resetErrorBoundary }) {
2322
return (
24-
<VerticalLayout role="alert" className="w-full items-center justify-between my-l">
23+
<div role="alert" className="error-fallback">
2524
<h1>Something went wrong</h1>
2625
<p style={{ color: "red" }}>{error.message}</p>
27-
<Button theme="primary" onClick={(e) => {
28-
resetErrorBoundary();
29-
}}>Retry</Button>
30-
</VerticalLayout>
26+
{error.type && <p><strong>Type:</strong> {error.type}</p>}
27+
{error.detail && (
28+
<pre>
29+
{typeof error.detail === 'string' ? error.detail : JSON.stringify(error.detail, null, 2)}
30+
</pre>
31+
)}
32+
<Button theme="primary" onClick={() => resetErrorBoundary()}>Retry</Button>
33+
</div>
3134
);
3235
}
3336

3437
export default function MainLayout() {
3538
const currentTitle = (useViewConfig()?.title) ? (i18n.translateDynamic(useViewConfig()?.title) + " — Spring PetClinic"): defaultTitle;
36-
const navigate = useNavigate();
3739
const location = useLocation();
3840

41+
const menuItems = createMenuItems();
42+
const tabsRef = useRef<any>(null);
43+
44+
useEffect(() => {
45+
// On page load/reload, sync selected tab with the active NavLink
46+
tabsRef.current.selected = [...tabsRef.current?.querySelectorAll('vaadin-tab')]
47+
.findIndex((tab: Element) => tab.querySelector('a.active'));
48+
}, []);
49+
3950
useEffect(() => {
4051
document.title = currentTitle;
4152
}, [currentTitle]);
4253

4354
return (
4455
<AppLayout>
45-
<header>
46-
<HorizontalLayout slot="navbar" theme="dark padding" id="header" className="w-full items-center justify-between">
47-
<a href="/" className="navbar-brand"><span>{translate(key`home`)}</span></a>
48-
<SideNav className="side-nav-top" onNavigate={({path}) => navigate(path!)}
49-
location={location}>
50-
{createMenuItems().map(({to, title, icon}) => (
51-
<SideNavItem path={to} key={to}>
52-
{icon ?
53-
<Icon icon={icon} slot="prefix"></Icon> : <></>}
56+
<HorizontalLayout slot="navbar" theme="dark padding" id="header" className="w-full items-center justify-between">
57+
<a href="/" className="navbar-brand"><span>{translate(key`home`)}</span></a>
58+
<Tabs ref={tabsRef}>
59+
{menuItems.map(({to, title, icon}) => (
60+
<Tab key={to}>
61+
<NavLink to={to}>
62+
{icon ? <Icon icon={icon} slot="prefix"></Icon> : <></>}
5463
{i18n.translateDynamic(title)}
55-
</SideNavItem>
56-
))}
57-
</SideNav>
58-
</HorizontalLayout>
59-
</header>
60-
<main>
61-
<ErrorBoundary FallbackComponent={Fallback} key={location.pathname}>
62-
<Suspense>
63-
<div style={{display: 'contents'}}><Outlet/></div>
64-
</Suspense>
65-
</ErrorBoundary>
66-
</main>
67-
<footer className="footer">
68-
<img src="./images/vaadin.png" alt="Vaadin"/>
69-
<img src="./images/spring-logo.svg" alt="Spring"/>
70-
</footer>
64+
</NavLink>
65+
</Tab>
66+
))}
67+
</Tabs>
68+
</HorizontalLayout>
69+
<div className="content-wrapper">
70+
<main>
71+
<ErrorBoundary FallbackComponent={Fallback} key={location.pathname}>
72+
<Suspense>
73+
<Outlet />
74+
</Suspense>
75+
</ErrorBoundary>
76+
</main>
77+
<footer className="footer">
78+
<img src="./images/vaadin.png" alt="Vaadin" />
79+
<img src="./images/spring-logo.svg" alt="Spring" />
80+
</footer>
81+
</div>
7182
</AppLayout>
7283
);
7384
}

src/main/frontend/views/owners/{ownerId}/@index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function ViewOwnerView() {
4040
return (
4141
<>
4242
<VerticalLayout theme="padding spacing"
43-
className="w-full justify-center">
43+
className="w-full">
4444
<FormLayout
4545
responsiveSteps={[{minWidth: '0', columns: 1},
4646
{minWidth: '600px', columns: 1}]
@@ -81,7 +81,7 @@ export default function ViewOwnerView() {
8181
}}>{translate(key`addNewPet`)}</Button>
8282
</HorizontalLayout>
8383
</FormItem>
84-
<VerticalLayout theme="spacing" className="pet-container">
84+
<VerticalLayout theme="spacing">
8585
<h2>{translate(key`petsAndVisits`)}</h2>
8686

8787
{

src/main/frontend/views/owners/{ownerId}/edit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default function EditOwnerView() {
8080
<TextField {...field(model.telephone)}></TextField>
8181
</FormItem>
8282
<FormItem>
83-
<Button onClick={submitWithErrors} className="edit-button">{translate(key`updateOwner`)}</Button>
83+
<Button onClick={submitWithErrors}>{translate(key`updateOwner`)}</Button>
8484
</FormItem>
8585
</FormLayout>
8686
</VerticalLayout>

0 commit comments

Comments
 (0)