From e95cf5c7b6a08eb560763d5167fbddc1c2117bcc Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 17 Nov 2025 09:57:09 +0100 Subject: add file uploading and multi-threading --- static/widgets/upload-bar/index.css | 41 ++++++++++++++++++++++++++++++++++++ static/widgets/upload-bar/index.js | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 static/widgets/upload-bar/index.css create mode 100644 static/widgets/upload-bar/index.js (limited to 'static/widgets/upload-bar') diff --git a/static/widgets/upload-bar/index.css b/static/widgets/upload-bar/index.css new file mode 100644 index 0000000..8ec1697 --- /dev/null +++ b/static/widgets/upload-bar/index.css @@ -0,0 +1,41 @@ + +#container { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: calc(100% - 10px); + height: 100px; + background: #efefef99; + backdrop-filter: blur(10px); + border-radius: var(--border-radius); + max-width: 500px; + padding: 10px 20px; + display: grid; +} + +#files { + background: #efefef; + padding: 10px; + border-radius: 20px; + margin: auto; + width: min-content; + white-space: nowrap; +} + +#inner-progress { + width: 100%; + height: 5px; + border-radius: 5px; + background: #efefef; + overflow: hidden; + margin: auto; +} + + +#progress { + background: var(--primary); + height: 100%; + border-radius: 5px; + transition: width 0.2s ease; +} diff --git a/static/widgets/upload-bar/index.js b/static/widgets/upload-bar/index.js new file mode 100644 index 0000000..a9e0220 --- /dev/null +++ b/static/widgets/upload-bar/index.js @@ -0,0 +1,42 @@ +import * as sfw from 'sfw'; +const { Div } = sfw.element.native; + +const css = await sfw.css(import.meta.url, './index.css') + +export default class UploadBar extends sfw.element.Container { + #files_progress + #inner_progress + #container + + constructor() { + super({ css }); + + this.body.append( + this.#container = Div.new({ + id: 'container', + style: { display: 'none' }, + children: [ + this.#files_progress = Div.new({ id: 'files', innerText: 'Uploading...' }), + Div.new({ + id: 'inner-progress', + children: [ + this.#inner_progress = Div.new({ id: 'progress' }), + ] + }) + ] + }) + ); + } + + set progress(progress) { + this.#inner_progress.style.width = `${progress * 100}%` + } + + hide() { + this.#container.style.display = 'none'; + } + + show() { + this.#container.style.display = ''; + } +} -- cgit v1.2.3-70-g09d2