From 7a2b699cd1da33a4d91ac0b0b21cb0aa48bfc77f Mon Sep 17 00:00:00 2001 From: pk Date: Tue, 11 Mar 2025 22:16:01 +0100 Subject: [PATCH] First implementation --- README.md | 22 +++++++++++++- package.json | 8 +++--- tp-element.js | 35 ---------------------- tp-progress-bar.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 40 deletions(-) delete mode 100644 tp-element.js create mode 100644 tp-progress-bar.js diff --git a/README.md b/README.md index 1ab27b7..0504440 100644 --- a/README.md +++ b/README.md @@ -1 +1,21 @@ -# tp-element +# tp-progress-bar + +A progress bar element. + +## Installation + +```bash +npm i @tp/tp-progress-bar +``` + +## Usage + +```html + +``` + +## Properties + +| Property | Type | Description | +| -------- | ---- | ----------- | +| `value` | `Number` | The current value of the progress bar. diff --git a/package.json b/package.json index 24f0225..7548e15 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "@tp/tp-element", - "version": "0.0.1", + "name": "@tp/tp-progress-bar", + "version": "1.0.0", "description": "", - "main": "tp-element.js", + "main": "tp-progress-bar.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", - "url": "https://gitea.codeblob.work/tp-elements/tp-element.git" + "url": "https://gitea.codeblob.work/tp-elements/tp-progress-bar.git" }, "author": "trading_peter", "license": "Apache-2.0", diff --git a/tp-element.js b/tp-element.js deleted file mode 100644 index 6195006..0000000 --- a/tp-element.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -@license -Copyright (c) 2024 trading_peter -This program is available under Apache License Version 2.0 -*/ - -import { LitElement, html, css } from 'lit'; - -class TpElement extends LitElement { - static get styles() { - return [ - css` - :host { - display: block; - } - ` - ]; - } - - render() { - const { } = this; - - return html` - - `; - } - - static get properties() { - return { }; - } - - -} - -window.customElements.define('tp-element', TpElement); diff --git a/tp-progress-bar.js b/tp-progress-bar.js new file mode 100644 index 0000000..36c9664 --- /dev/null +++ b/tp-progress-bar.js @@ -0,0 +1,72 @@ +/** +@license +Copyright (c) 2025 trading_peter +This program is available under Apache License Version 2.0 +*/ + +import { LitElement, html, css } from 'lit'; + +export class TpProgressBar extends LitElement { + static get styles() { + return css` + :host { + display: block; + } + + .bar { + background: #EEEEEE; + border-radius: 8px; + height: var(--tp-progress-bar-height, 16px); + border-radius: var(--tp-progress-bar-border-radius, 8px); + position: relative; + overflow: hidden; + transform: translate3d(0, 0, 0); + } + + #progress { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + border-radius: 8px; + transform: translateX(-100%); + background: var(--tp-progress-bar-color, #039BE5); + transition: transform 200ms linear; + } + `; + } + + render() { + return html` +
+
+
+ `; + } + + static get properties() { + return { + progress: { type: Number }, + }; + } + + constructor() { + super(); + this.progress = 0; + } + + updated(changedProperties) { + if (changedProperties.has('progress')) { + this._progressChanged(this.progress); + } + } + + _progressChanged(value) { + value = Math.max(0, Math.min(100, value)); + const progress = this.shadowRoot.querySelector('#progress'); + progress.style.transform = `translateX(-${100 - value}%)`; + } +} + +window.customElements.define('tp-progress-bar', TpProgressBar);