Skip to content

Commit 4fe411c

Browse files
authored
experiment: add side-nav base styles and visual tests (#9407)
1 parent c342550 commit 4fe411c

33 files changed

Lines changed: 681 additions & 67 deletions

‎dev/side-nav.html‎

Lines changed: 128 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,145 @@
99
<script type="module">
1010
import '@vaadin/icon';
1111
import '@vaadin/icons';
12-
import '@vaadin/scroller';
1312
import '@vaadin/side-nav';
13+
import '@vaadin/radio-group';
14+
15+
const icons = [
16+
'vaadin:home',
17+
'vaadin:folder-open',
18+
'vaadin:chart',
19+
'vaadin:bed',
20+
'vaadin:boat',
21+
'vaadin:calendar',
22+
'vaadin:chat',
23+
'vaadin:cube',
24+
'vaadin:file-o',
25+
'vaadin:laptop',
26+
'vaadin:picture',
27+
];
28+
29+
function addIcon(item) {
30+
const icon = document.createElement('vaadin-icon');
31+
icon.icon = icons[Math.floor(Math.random() * icons.length)];
32+
icon.setAttribute('slot', 'prefix');
33+
item.prepend(icon);
34+
}
35+
36+
document.querySelector('vaadin-radio-button[value="none"]').addEventListener('click', (e) => {
37+
document.querySelectorAll('vaadin-side-nav vaadin-icon').forEach((icon) => icon.remove());
38+
});
39+
40+
document.querySelector('vaadin-radio-button[value="all"]').addEventListener('click', (e) => {
41+
document.querySelectorAll('vaadin-side-nav vaadin-icon').forEach((icon) => icon.remove());
42+
document.querySelectorAll('vaadin-side-nav-item').forEach((item) => addIcon(item));
43+
});
44+
45+
document.querySelector('vaadin-radio-button[value="top"]').addEventListener('click', (e) => {
46+
document.querySelectorAll('vaadin-side-nav vaadin-icon').forEach((icon) => icon.remove());
47+
document.querySelectorAll('vaadin-side-nav > vaadin-side-nav-item').forEach((item) => addIcon(item));
48+
});
49+
50+
document.querySelector('vaadin-radio-button[value="random"]').addEventListener('click', (e) => {
51+
document.querySelectorAll('vaadin-side-nav vaadin-icon').forEach((icon) => icon.remove());
52+
document.querySelectorAll('vaadin-side-nav-item').forEach((item) => {
53+
if (Math.random() > 0.5) {
54+
addIcon(item);
55+
}
56+
});
57+
});
58+
59+
// Fake navigation: prevent actual navigation, update 'current' item manually
60+
document.querySelector('vaadin-side-nav').addEventListener('click', (e) => {
61+
const link = e.composedPath().find((el) => el.localName === 'a');
62+
if (link) {
63+
e.preventDefault();
64+
if (link.href) {
65+
document.querySelectorAll('vaadin-side-nav-item').forEach((item) => item.removeAttribute('current'));
66+
const navItem = e.composedPath().find((el) => el.localName === 'vaadin-side-nav-item');
67+
navItem.setAttribute('current', '');
68+
}
69+
}
70+
});
71+
72+
// TODO seems like the vaadin-side-nav-item[disabled] attribute is not working, it gets overridden by DisabledMixin
73+
document.querySelector('vaadin-side-nav-item[data-disabled]').disabled = true;
1474
</script>
1575
<style>
16-
vaadin-scroller {
17-
width: 300px;
76+
vaadin-side-nav {
77+
width: fit-content;
78+
margin-top: 2rem;
79+
}
80+
81+
[theme~='badge'] {
82+
font-size: 0.8em;
83+
line-height: 1.2;
84+
display: inline-block;
85+
padding: 0.1em 0.3em;
86+
min-width: calc(1lh + 0.2em - 0.6em);
87+
background: var(--_vaadin-background-container);
88+
border-radius: 0.7em;
89+
text-align: center;
1890
}
1991
</style>
2092
</head>
2193
<body>
22-
<vaadin-scroller>
23-
<div class="content">
24-
<vaadin-side-nav collapsible>
25-
<span slot="label">Main menu</span>
26-
27-
<vaadin-side-nav-item path="/dev">
28-
<vaadin-icon icon="vaadin:chart" slot="prefix"></vaadin-icon>
29-
Dev main page
30-
<span theme="badge primary" slot="suffix" aria-label="(2 new items)">2</span>
31-
</vaadin-side-nav-item>
94+
<vaadin-radio-group
95+
label="Icons"
96+
id="icons"
97+
helper-text="Click again to randomize icons"
98+
theme="helper-above-field"
99+
>
100+
<vaadin-radio-button label="None" value="none" checked></vaadin-radio-button>
101+
<vaadin-radio-button label="All" value="all"></vaadin-radio-button>
102+
<vaadin-radio-button label="Top Level" value="top"></vaadin-radio-button>
103+
<vaadin-radio-button label="Random" value="random"></vaadin-radio-button>
104+
</vaadin-radio-group>
105+
106+
<vaadin-side-nav collapsible>
107+
<span slot="label">Main menu</span>
108+
109+
<vaadin-side-nav-item path="/dev/side-nav.html">
110+
Side Nav
111+
<span theme="badge" slot="suffix" aria-label="(2 new items)">1</span>
112+
</vaadin-side-nav-item>
113+
114+
<vaadin-side-nav-item path="/dev" expanded>
115+
Dev pages
116+
<span theme="badge" slot="suffix" aria-label="(2 new items)">99+</span>
32117

33-
<vaadin-side-nav-item>
34-
<vaadin-icon icon="vaadin:folder-open" slot="prefix"></vaadin-icon>
35-
Dev pages
118+
<vaadin-side-nav-item path="/dev/grid.html" slot="children">Grid</vaadin-side-nav-item>
119+
<vaadin-side-nav-item path="/dev/select.html" slot="children">Select</vaadin-side-nav-item>
120+
<vaadin-side-nav-item path="/dev/button.html" slot="children">Button</vaadin-side-nav-item>
36121

37-
<vaadin-side-nav-item path="/dev/grid.html" slot="children"> Grid </vaadin-side-nav-item>
122+
<vaadin-side-nav-item slot="children" expanded>
123+
Layouts
38124

39-
<vaadin-side-nav-item path="/dev/select.html" slot="children"> Select </vaadin-side-nav-item>
125+
<vaadin-side-nav-item path="/dev/app-layout.html" slot="children"> App Layout </vaadin-side-nav-item>
126+
<vaadin-side-nav-item path="/dev/form-layout.html" slot="children"> Form Layout </vaadin-side-nav-item>
127+
<vaadin-side-nav-item path="/dev/master-detail-layout.html" slot="children">
128+
Master-Detail Layout
129+
<span theme="badge" slot="suffix" aria-label="(2 new items)">2</span>
40130
</vaadin-side-nav-item>
131+
<vaadin-side-nav-item path="/dev/split-layout.html" slot="children"> Split Layout </vaadin-side-nav-item>
132+
<vaadin-side-nav-item path="/dev/horizontal-layout.html" slot="children">
133+
Horizontal Layout
134+
</vaadin-side-nav-item>
135+
<vaadin-side-nav-item path="/dev/vertical-layout.html" slot="children">
136+
Vertical Layout
137+
</vaadin-side-nav-item>
138+
</vaadin-side-nav-item>
139+
140+
<vaadin-side-nav-item slot="children" disabled data-disabled expanded>
141+
Form Fields
142+
143+
<vaadin-side-nav-item path="/dev/combo-box.html" slot="children"> Combo Box </vaadin-side-nav-item>
144+
<vaadin-side-nav-item path="/dev/date-picker.html" slot="children"> Date Picker </vaadin-side-nav-item>
145+
<vaadin-side-nav-item path="/dev/checkbox.html" slot="children"> Checkbox </vaadin-side-nav-item>
146+
<vaadin-side-nav-item path="/dev/text-field.html" slot="children"> Text Field </vaadin-side-nav-item>
147+
</vaadin-side-nav-item>
148+
</vaadin-side-nav-item>
41149

42-
<vaadin-side-nav-item> Label only (no path) </vaadin-side-nav-item>
43-
</vaadin-side-nav>
44-
</div>
45-
</vaadin-scroller>
150+
<vaadin-side-nav-item> Label only (no path) </vaadin-side-nav-item>
151+
</vaadin-side-nav>
46152
</body>
47153
</html>

‎packages/side-nav/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"type": "module",
2222
"files": [
2323
"src",
24+
"!src/styles/*-base-styles.d.ts",
25+
"!src/styles/*-base-styles.js",
2426
"theme",
2527
"vaadin-*.d.ts",
2628
"vaadin-*.js",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2023 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const sideNavStyles: CSSResult;
9+
10+
export const sideNavSlotStyles: CSSResult;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2023 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import '@vaadin/component-base/src/style-props.js';
7+
import { css } from 'lit';
8+
import { sharedStyles } from './vaadin-side-nav-shared-base-styles.js';
9+
10+
const sideNav = css`
11+
:host {
12+
white-space: nowrap;
13+
}
14+
15+
[part='label'] {
16+
align-self: start;
17+
display: flex;
18+
align-items: center;
19+
justify-content: start;
20+
gap: var(--vaadin-side-nav-item-gap, var(--_vaadin-gap-container-inline));
21+
padding: var(--vaadin-side-nav-item-padding, var(--_vaadin-padding-container));
22+
font-size: var(--vaadin-side-nav-label-font-size, 0.875em);
23+
font-weight: var(--vaadin-side-nav-label-font-weight, 500);
24+
color: var(--vaadin-side-nav-label-color, inherit);
25+
line-height: var(--vaadin-side-nav-label-line-height, inherit);
26+
border-radius: var(--vaadin-side-nav-item-border-radius, var(--_vaadin-radius-m));
27+
}
28+
`;
29+
30+
export const sideNavStyles = [sharedStyles, sideNav];
31+
32+
export const sideNavSlotStyles = css`
33+
vaadin-side-nav:has(vaadin-icon[slot='prefix']) {
34+
--_has-prefix-icon: '';
35+
}
36+
37+
vaadin-side-nav-item:has(> vaadin-icon[slot='prefix'])::part(link) {
38+
--_has-prefix-icon:;
39+
}
40+
`;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2023 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const sideNavStyles: CSSResult;
9+
10+
export const sideNavSlotStyles: CSSResult;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2023 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import { css } from 'lit';
7+
8+
export const sideNavStyles = css`
9+
:host {
10+
display: block;
11+
}
12+
13+
:host([hidden]) {
14+
display: none !important;
15+
}
16+
17+
button {
18+
display: flex;
19+
align-items: center;
20+
justify-content: inherit;
21+
width: 100%;
22+
margin: 0;
23+
padding: 0;
24+
background-color: initial;
25+
color: inherit;
26+
border: initial;
27+
outline: none;
28+
font: inherit;
29+
text-align: inherit;
30+
}
31+
32+
[part='children'] {
33+
padding: 0;
34+
margin: 0;
35+
list-style-type: none;
36+
}
37+
`;
38+
39+
export const sideNavSlotStyles = css``;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2023 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const sideNavItemStyles: CSSResult;

0 commit comments

Comments
 (0)