Skip to content

Commit ab5118c

Browse files
authored
experiment: add item base styles and visual tests (#9185)
1 parent b0a02d0 commit ab5118c

18 files changed

+157
-20
lines changed

packages/item/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/*-base-styles.d.ts",
25+
"!src/*-base-styles.js",
2426
"theme",
2527
"vaadin-*.d.ts",
2628
"vaadin-*.js",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 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 itemStyles: CSSResult;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 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+
9+
export const itemStyles = css`
10+
@layer base {
11+
:host {
12+
align-items: center;
13+
border-radius: var(--vaadin-item-border-radius, var(--_vaadin-radius-m));
14+
box-sizing: border-box;
15+
cursor: pointer;
16+
display: flex;
17+
gap: var(--vaadin-item-gap, 0 var(--_vaadin-gap-container-inline));
18+
height: var(--vaadin-item-height, auto);
19+
padding: var(--vaadin-item-padding, var(--_vaadin-padding-container));
20+
}
21+
22+
:host([focused]) {
23+
outline: var(--vaadin-focus-ring-width) solid var(--vaadin-focus-ring-color);
24+
outline-offset: calc(var(--vaadin-focus-ring-width) / -1);
25+
}
26+
27+
:host([disabled]) {
28+
cursor: not-allowed;
29+
opacity: 0.5;
30+
}
31+
32+
:host([hidden]) {
33+
display: none !important;
34+
}
35+
36+
[part='checkmark'] {
37+
color: var(--vaadin-item-checkmark-color, inherit);
38+
display: var(--vaadin-item-checkmark-display, none);
39+
visibility: hidden;
40+
}
41+
42+
[part='checkmark']::before {
43+
content: '';
44+
display: block;
45+
background: currentColor;
46+
height: var(--vaadin-icon-size, 1lh);
47+
mask-image: var(--_vaadin-icon-checkmark);
48+
width: var(--vaadin-icon-size, 1lh);
49+
}
50+
51+
:host([selected]) [part='checkmark'] {
52+
visibility: visible;
53+
}
54+
55+
[part='content'] {
56+
flex: 1;
57+
}
58+
}
59+
`;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 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 itemStyles: CSSResult;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 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 itemStyles = css`
9+
:host {
10+
display: inline-block;
11+
}
12+
13+
:host([hidden]) {
14+
display: none !important;
15+
}
16+
`;

packages/item/src/vaadin-item.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
77
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
88
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
9-
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9+
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10+
import { itemStyles } from './vaadin-item-core-styles.js';
1011
import { ItemMixin } from './vaadin-item-mixin.js';
1112

13+
registerStyles('vaadin-item', itemStyles, { moduleId: 'vaadin-item-styles' });
14+
1215
/**
1316
* `<vaadin-item>` is a Web Component providing layout for items in tabs and menus.
1417
*
@@ -56,15 +59,6 @@ import { ItemMixin } from './vaadin-item-mixin.js';
5659
class Item extends ItemMixin(ThemableMixin(DirMixin(PolymerElement))) {
5760
static get template() {
5861
return html`
59-
<style>
60-
:host {
61-
display: inline-block;
62-
}
63-
64-
:host([hidden]) {
65-
display: none !important;
66-
}
67-
</style>
6862
<span part="checkmark" aria-hidden="true"></span>
6963
<div part="content">
7064
<slot></slot>

packages/item/src/vaadin-lit-item.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* Copyright (c) 2017 - 2025 Vaadin Ltd.
44
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55
*/
6-
import { css, html, LitElement } from 'lit';
6+
import { html, LitElement } from 'lit';
77
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
88
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
99
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
1010
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11+
import { itemStyles } from './vaadin-item-core-styles.js';
1112
import { ItemMixin } from './vaadin-item-mixin.js';
1213

1314
/**
@@ -25,15 +26,7 @@ class Item extends ItemMixin(ThemableMixin(DirMixin(PolylitMixin(LitElement))))
2526
}
2627

2728
static get styles() {
28-
return css`
29-
:host {
30-
display: inline-block;
31-
}
32-
33-
:host([hidden]) {
34-
display: none !important;
35-
}
36-
`;
29+
return itemStyles;
3730
}
3831

3932
/** @protected */
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { fixtureSync } from '@vaadin/testing-helpers/dist/fixture.js';
2+
import { visualDiff } from '@web/test-runner-visual-regression';
3+
import '../../../src/vaadin-item.js';
4+
5+
describe('item', () => {
6+
let div, element;
7+
8+
function setIconVisible(container) {
9+
container.style.setProperty('--vaadin-item-checkmark-display', 'block');
10+
}
11+
12+
beforeEach(() => {
13+
div = document.createElement('div');
14+
div.style.display = 'inline-block';
15+
div.style.padding = '10px';
16+
element = fixtureSync('<vaadin-item>Basic item</vaadin-item>', div);
17+
});
18+
19+
['ltr', 'rtl'].forEach((dir) => {
20+
describe(dir, () => {
21+
before(() => {
22+
document.documentElement.setAttribute('dir', dir);
23+
});
24+
25+
after(() => {
26+
document.documentElement.removeAttribute('dir');
27+
});
28+
29+
it('basic', async () => {
30+
await visualDiff(div, `${dir}-basic`);
31+
});
32+
33+
it('checkmark', async () => {
34+
setIconVisible(div);
35+
await visualDiff(div, `${dir}-checkmark`);
36+
});
37+
38+
it('selected', async () => {
39+
setIconVisible(div);
40+
element.setAttribute('selected', '');
41+
await visualDiff(div, `${dir}-selected`);
42+
});
43+
44+
it('focused', async () => {
45+
setIconVisible(div);
46+
element.setAttribute('focused', '');
47+
await visualDiff(div, `${dir}-focused`);
48+
});
49+
50+
it('disabled', async () => {
51+
setIconVisible(div);
52+
element.setAttribute('disabled', '');
53+
await visualDiff(div, `${dir}-disabled`);
54+
});
55+
});
56+
});
57+
});
610 Bytes
Loading
628 Bytes
Loading

0 commit comments

Comments
 (0)