Skip to content

Commit dda79bf

Browse files
jouniweb-padawan
andauthored
experiment: add progress-bar base styles and visual tests (#9615)
* init base styles * base styles * add visual tests * fix: wrap styles with base layer * chore: align copyright years with core styles * test: import src version of the component in base visual test * chore: do not publish base styles to npm * chore: fix Stylelint errors * test: update visual test screenshots * fix border radius on value part * test: update screenshots * fix: support reduced motion preference * chore: move stylelint-disable comment --------- Co-authored-by: web-padawan <iamkulykov@gmail.com>
1 parent 850f036 commit dda79bf

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed

packages/progress-bar/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: 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 progressBarStyles: CSSResult;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 progressBarStyles = css`
10+
@layer base {
11+
:host {
12+
display: block;
13+
width: 100%; /* prevent collapsing inside non-stretching column flex */
14+
height: 0.5lh;
15+
contain: layout size;
16+
}
17+
18+
:host([hidden]) {
19+
display: none !important;
20+
}
21+
22+
[part='bar'] {
23+
box-sizing: border-box;
24+
height: 100%;
25+
--_padding: var(--vaadin-progress-bar-padding, 0px);
26+
padding: var(--_padding); /* stylelint-disable-line length-zero-no-unit */
27+
background: var(--vaadin-progress-bar-background, var(--vaadin-background-container));
28+
border-radius: var(--vaadin-progress-bar-border-radius, var(--vaadin-radius-m));
29+
border: var(--vaadin-progress-bar-border-width, 1px) solid
30+
var(--vaadin-progress-bar-border-color, var(--vaadin-border-color));
31+
}
32+
33+
[part='value'] {
34+
box-sizing: border-box;
35+
height: 100%;
36+
width: calc(var(--vaadin-progress-value) * 100%);
37+
background: var(--vaadin-progress-bar-value-background, var(--vaadin-border-color-strong));
38+
border-radius: calc(
39+
var(--vaadin-progress-bar-border-radius, var(--vaadin-radius-m)) - var(
40+
--vaadin-progress-bar-border-width,
41+
1px
42+
) - var(--_padding)
43+
);
44+
transition: width 150ms;
45+
}
46+
47+
/* Indeterminate progress */
48+
:host([indeterminate]) [part='value'] {
49+
--_w-min: clamp(0.5em, 5%, 1em);
50+
--_w-max: clamp(1em, 20%, 8em);
51+
animation: indeterminate var(--vaadin-progress-bar-animation-duration, 1s) linear infinite alternate;
52+
width: var(--_w-min);
53+
}
54+
55+
:host([indeterminate][aria-valuenow]) [part='value'] {
56+
animation-delay: 150ms;
57+
}
58+
59+
@keyframes indeterminate {
60+
0% {
61+
animation-timing-function: ease-in;
62+
}
63+
64+
20% {
65+
margin-inline-start: 0%;
66+
width: var(--_w-max);
67+
}
68+
69+
50% {
70+
margin-inline-start: calc(50% - var(--_w-max) / 2);
71+
}
72+
73+
80% {
74+
width: var(--_w-max);
75+
margin-inline-start: calc(100% - var(--_w-max));
76+
animation-timing-function: ease-out;
77+
}
78+
79+
100% {
80+
width: var(--_w-min);
81+
margin-inline-start: calc(100% - var(--_w-min));
82+
}
83+
}
84+
85+
@keyframes indeterminate-reduced {
86+
100% {
87+
opacity: 0.2;
88+
}
89+
}
90+
91+
@media (prefers-reduced-motion: reduce) {
92+
[part='value'] {
93+
transition: none;
94+
}
95+
96+
:host([indeterminate]) [part='value'] {
97+
width: 25%;
98+
animation: indeterminate-reduced 2s linear infinite alternate;
99+
}
100+
}
101+
}
102+
`;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { fixtureSync } from '@vaadin/testing-helpers/dist/fixture.js';
2+
import { visualDiff } from '@web/test-runner-visual-regression';
3+
import '../../../src/vaadin-progress-bar.js';
4+
5+
describe('progress-bar', () => {
6+
let div, element;
7+
8+
beforeEach(() => {
9+
div = document.createElement('div');
10+
div.style.display = 'inline-block';
11+
div.style.width = '200px';
12+
element = fixtureSync('<vaadin-progress-bar value="0.1"></vaadin-progress-bar>', div);
13+
});
14+
15+
it('basic', async () => {
16+
await visualDiff(div, 'basic');
17+
});
18+
19+
it('RTL', async () => {
20+
element.setAttribute('dir', 'rtl');
21+
await visualDiff(div, 'rtl-basic');
22+
});
23+
});
338 Bytes
Loading
335 Bytes
Loading

0 commit comments

Comments
 (0)