Skip to content

Commit 043d617

Browse files
authored
Merge pull request #83 from umbraco/feature/uui-progress-bar
2 parents b80e73f + 6196e1b commit 043d617

File tree

12 files changed

+252
-0
lines changed

12 files changed

+252
-0
lines changed

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uui-progress-bar/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# uui-progress-bar
2+
3+
![npm](https://img.shields.io/npm/v/@umbraco-ui/uui-progress-bar?logoColor=%231B264F)
4+
5+
Umbraco style progress-bar component.
6+
7+
## Installation
8+
9+
### ES imports
10+
11+
```zsh
12+
npm i @umbraco-ui/uui-progress-bar
13+
```
14+
15+
Import the registration of `<uui-progress-bar>` via:
16+
17+
```javascript
18+
import '@umbraco-ui/uui-progress-bar/lib';
19+
```
20+
21+
When looking to leverage the `UUIProgressBarElement` base class as a type and/or for extension purposes, do so via:
22+
23+
```javascript
24+
import { UUIProgressBarElement } from '@umbraco-ui/uui-progress-bar/lib/uui-progress-bar.element';
25+
```
26+
27+
### CDN
28+
29+
The component is available via CDN. This means it can be added to your application without the need of any bundler configuration. Here is how to use it with jsDelivr.
30+
31+
```html
32+
<!-- Latest Version -->
33+
<script src="https://cdn.jsdelivr.net/npm/@umbraco-ui/uui-progress-bar@latest/dist/uui-progress-bar.min.js"></script>
34+
35+
<!-- Specific version -->
36+
<script src="https://cdn.jsdelivr.net/npm/@umbraco-ui/[email protected]/dist/uui-progress-bar.min.js"></script>
37+
```
38+
39+
## Usage
40+
41+
```html
42+
<uui-progress-bar progress="25"></uui-progress-bar>
43+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { UUIProgressBarElement } from './uui-progress-bar.element';
2+
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
3+
4+
defineElement('uui-progress-bar', UUIProgressBarElement as any);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { LitElement, html, css } from 'lit';
2+
import { property } from 'lit/decorators.js';
3+
import { styleMap } from 'lit/directives/style-map.js';
4+
5+
const clamp = (num: number, min: number, max: number) =>
6+
Math.min(Math.max(num, min), max);
7+
8+
/**
9+
* @element uui-progress-bar
10+
*/
11+
export class UUIProgressBarElement extends LitElement {
12+
static styles = [
13+
css`
14+
:host {
15+
width: 100%;
16+
height: 4px;
17+
position: relative;
18+
overflow: hidden;
19+
background: var(--uui-interface-surface-alt);
20+
border-radius: 100px;
21+
display: inline-block;
22+
}
23+
24+
#bar {
25+
transition: width 250ms ease;
26+
background: var(--uui-look-positive-surface);
27+
height: 100%;
28+
width: 0%;
29+
}
30+
`,
31+
];
32+
33+
private _progress = 0;
34+
/**
35+
* Set this to a number between 0 and 100 to reflect the progress of some operation.
36+
* @type {number}
37+
* @attr
38+
* @default 0
39+
*/
40+
@property({ type: Number })
41+
get progress() {
42+
return this._progress;
43+
}
44+
45+
set progress(newVal) {
46+
const oldVal = this._progress;
47+
this._progress = clamp(newVal, 0, 100);
48+
this.requestUpdate('progress', oldVal);
49+
}
50+
51+
private _getProgressStyle() {
52+
return { width: `${this._progress}%` };
53+
}
54+
55+
render() {
56+
return html`
57+
<div id="bar" style=${styleMap(this._getProgressStyle())}></div>
58+
`;
59+
}
60+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Story } from '@storybook/web-components';
2+
import { html } from 'lit-html';
3+
import '@umbraco-ui/uui-progress-bar/lib/index';
4+
5+
export default {
6+
id: 'uui-progress-bar',
7+
title: 'Progress Bar',
8+
component: 'uui-progress-bar',
9+
args: {
10+
progress: 25,
11+
},
12+
parameters: {
13+
docs: {
14+
source: {
15+
code: `<uui-progress-bar></uui-progress-bar>`,
16+
},
17+
},
18+
},
19+
};
20+
21+
export const Overview: Story = props =>
22+
html`<uui-progress-bar progress="${props.progress}"></uui-progress-bar>`;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { html, fixture, expect, elementUpdated } from '@open-wc/testing';
2+
import { UUIProgressBarElement } from './uui-progress-bar.element';
3+
import '.';
4+
5+
describe('UUIProgressBarElement', () => {
6+
let element: UUIProgressBarElement;
7+
8+
beforeEach(async () => {
9+
element = await fixture(html` <uui-progress-bar></uui-progress-bar> `);
10+
});
11+
12+
it('passes the a11y audit', async () => {
13+
expect(element).shadowDom.to.be.accessible();
14+
});
15+
16+
it('clamps the negative values passed to progress to 0', async () => {
17+
element.progress = -44;
18+
expect(element.progress).to.equal(0);
19+
});
20+
21+
it('clamps the progress values greater then 100 to 100', async () => {
22+
element.progress = 200;
23+
expect(element.progress).to.equal(100);
24+
});
25+
26+
it('sets the bar width corresponding to the progress', async () => {
27+
element.progress = 23;
28+
await elementUpdated(element);
29+
const bar = element.shadowRoot?.getElementById('bar');
30+
expect(bar?.style.width).to.equal('23%');
31+
});
32+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "@umbraco-ui/uui-progress-bar",
3+
"version": "0.0.0",
4+
"license": "MIT",
5+
"keywords": [
6+
"Umbraco",
7+
"Custom elements",
8+
"Web components",
9+
"UI",
10+
"Lit",
11+
"Progress Bar"
12+
],
13+
"description": "Umbraco UI progress-bar component",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/umbraco/Umbraco.UI.git",
17+
"directory": "packages/uui-progress-bar"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/umbraco/Umbraco.UI/issues"
21+
},
22+
"main": "./dist/uui-progress-bar.min.js",
23+
"module": "./lib/index.js",
24+
"customElements": "custom-elements.json",
25+
"files": [
26+
"dist",
27+
"lib/**/*.d.ts",
28+
"lib/**/*.js",
29+
"custom-elements.json"
30+
],
31+
"dependencies": {
32+
"@umbraco-ui/uui-base": "0.0.13"
33+
},
34+
"scripts": {
35+
"build": "npm run analyze && tsc --build --force && rollup -c rollup.config.js",
36+
"clean": "tsc --build --clean && rimraf dist lib/*.js lib/**/*.js custom-elements.json",
37+
"analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json"
38+
},
39+
"publishConfig": {
40+
"access": "public"
41+
},
42+
"homepage": "https://uui.umbraco.com/?path=/story/uui-progress-bar"
43+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { UUIProdConfig } from '../rollup-package.config';
2+
3+
export default UUIProdConfig({
4+
entryPoints: ['index', 'uui-progress-bar.element'],
5+
bundle: 'index',
6+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Don't edit this file directly. It is generated by /scripts/generate-ts-config.js
2+
3+
{
4+
"extends": "../../tsconfig.json",
5+
"compilerOptions": {
6+
"outDir": "./lib",
7+
"rootDir": "./lib",
8+
"composite": true
9+
},
10+
"include": ["./**/*.ts"],
11+
"exclude": ["./**/*.test.ts", "./**/*.story.ts"],
12+
"references": [
13+
{
14+
"path": "../uui-base"
15+
}
16+
]
17+
}

packages/uui/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ import '@umbraco-ui/uui-toggle/lib/index';
3535
import '@umbraco-ui/uui-caret/lib/index';
3636
import '@umbraco-ui/uui-menu-item/lib/index';
3737
import '@umbraco-ui/uui-pagination/lib/index';
38+
import '@umbraco-ui/uui-progress-bar/lib/index';

0 commit comments

Comments
 (0)