aboutsummaryrefslogtreecommitdiff
path: root/static/widgets/month-select/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/widgets/month-select/index.js')
-rw-r--r--static/widgets/month-select/index.js75
1 files changed, 75 insertions, 0 deletions
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;
+ }
+ }
+}