From c7b02f02ad0a7e2888f2d7d3599719e59bbd1ee2 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 13 Nov 2025 14:56:02 +0100 Subject: frontend: design prototype --- static/widgets/month-select/index.js | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 static/widgets/month-select/index.js (limited to 'static/widgets/month-select/index.js') diff --git a/static/widgets/month-select/index.js b/static/widgets/month-select/index.js new file mode 100644 index 0000000..d23469d --- /dev/null +++ b/static/widgets/month-select/index.js @@ -0,0 +1,75 @@ +import * as sfw from 'sfw'; +const { Div } = sfw.element.native; + +import icons from '../../icons/index.js'; + +const css = await sfw.css(import.meta.url, './index.css'); + +export default class MonthSelect extends sfw.element.Container { + #container + #month_container + + constructor() { + super({ css }); + + this.onscroll = (e) => e.stopPropagate(); + this.onmonth = () => {}; + + this.body.append( + this.#container = Div.new({ + id: 'container', + children: [ + Div.new({ id: 'title', innerText: 'Select Month' }), + Div.new({ + id: 'close-button', + children: [ icons.close ], + onclick: () => this.hide(), + }), + this.#month_container = Div.new({ + id: 'month-container', + }), + ], + }), + ); + } + + show() { + this.#container.classList.add('visible'); + } + + hide() { + this.#container.classList.remove('visible'); + } + + set months(months) { + months.sort((a, b) => a.is_before(b)); + + this.#month_container.innerHTML = ''; + + let last = null; + + for (const month of months) { + if (last != null && !last.is_same_year(month)) { + this.#month_container.append( + Div.new({ + className: 'year-item', + innerText: last.year, + }) + ); + } + + this.#month_container.append( + Div.new({ + className: 'month-item', + innerText: month.name, + onclick: () => { + this.hide(); + this.onmonth(month); + } + }) + ); + + last = month; + } + } +} -- cgit v1.2.3-70-g09d2