diff options
Diffstat (limited to 'static/widgets/image/index.js')
| -rw-r--r-- | static/widgets/image/index.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/static/widgets/image/index.js b/static/widgets/image/index.js new file mode 100644 index 0000000..ad77c4e --- /dev/null +++ b/static/widgets/image/index.js @@ -0,0 +1,30 @@ +import * as sfw from 'sfw'; +const { Div, Img } = sfw.element.native; + +const css = await sfw.css(import.meta.url, './index.css') + +export default class Image extends sfw.element.Container { + #container + #image + + constructor() { + super ({ css }) + + this.body.append( + this.#container = Div.new({ + id: 'container', + children: [ + this.#image = Img.new({ + onload: () => this.#container.classList.add('loaded'), + }), + Div.new({ id: 'loading' }) + ], + }) + ); + } + + set id(id) { + this.#container.classList.remove('loaded'); + this.#image.src = `/api/image/load/${id}`; + } +} |