« get me outta code hell

content: generateChronologyLinksScopeSwitcher - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies/generateChronologyLinksScopeSwitcher.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-04-23 16:33:45 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-30 20:48:17 -0300
commit53483407a9f1f7fe20db6574fd4127d0c875e2ce (patch)
tree2b564866c638e5f45906a9c92c1ee8e7c15ce5e4 /src/content/dependencies/generateChronologyLinksScopeSwitcher.js
parent7fe20d1365068c5da45b7d3123b6cea82300e6e9 (diff)
content: generateChronologyLinksScopeSwitcher
Diffstat (limited to 'src/content/dependencies/generateChronologyLinksScopeSwitcher.js')
-rw-r--r--src/content/dependencies/generateChronologyLinksScopeSwitcher.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/content/dependencies/generateChronologyLinksScopeSwitcher.js b/src/content/dependencies/generateChronologyLinksScopeSwitcher.js
new file mode 100644
index 00000000..53ec87a6
--- /dev/null
+++ b/src/content/dependencies/generateChronologyLinksScopeSwitcher.js
@@ -0,0 +1,52 @@
+import {stitchArrays} from '#sugar';
+
+export default {
+  extraDependencies: ['html', 'language'],
+
+  slots: {
+    scopes: {
+      validate: v => v.strictArrayOf(v.isStringNonEmpty),
+    },
+
+    contents: {
+      validate: v => v.strictArrayOf(v.isHTML),
+    },
+
+    open: {
+      type: 'boolean',
+      default: true,
+    },
+  },
+
+  generate: (slots, {html, language}) =>
+    html.tag('details', {class: 'scoped-chronology-switcher'},
+      slots.open &&
+        {open: true},
+
+      [
+        html.tag('summary',
+          language.$('trackPage.nav.chronology.scope.title', {
+            scope:
+              slots.scopes.map((scope, index) =>
+                html.tag('a', {class: 'switcher-link'},
+                  {href: '#'},
+
+                  (index === 0
+                    ? {style: 'display: inline'}
+                    : {style: 'display: none'}),
+
+                  language.$('trackPage.nav.chronology.scope', scope))),
+          })),
+
+        stitchArrays({
+          scope: slots.scopes,
+          content: slots.contents,
+        }).map(({scope, content}, index) =>
+            html.tag('div', {class: 'scope-' + scope},
+              (index === 0
+                ? {style: 'display: block'}
+                : {style: 'display: none'}),
+
+              content)),
+      ]),
+};