diff options
Diffstat (limited to 'src/content/dependencies/generateDotSwitcherTemplate.js')
-rw-r--r-- | src/content/dependencies/generateDotSwitcherTemplate.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/content/dependencies/generateDotSwitcherTemplate.js b/src/content/dependencies/generateDotSwitcherTemplate.js new file mode 100644 index 00000000..22205922 --- /dev/null +++ b/src/content/dependencies/generateDotSwitcherTemplate.js @@ -0,0 +1,41 @@ +export default { + extraDependencies: ['html'], + + slots: { + attributes: { + type: 'attributes', + mutable: false, + }, + + options: { + validate: v => v.strictArrayOf(v.isHTML), + }, + + initialOptionIndex: {type: 'number'}, + }, + + generate: (slots, {html}) => + html.tag('span', {class: 'dot-switcher'}, + {[html.onlyIfContent]: true}, + {[html.noEdgeWhitespace]: true}, + {[html.joinChildren]: ''}, + + slots.attributes, + + slots.options + .map((option, index) => + html.tag('span', + {[html.onlyIfContent]: true}, + + html.resolve(option, {normalize: 'tag'}) + .onlyIfSiblings && + {[html.onlyIfSiblings]: true}, + + index === slots.initialOptionIndex && + {class: 'current'}, + + [ + html.metatag('imaginary-sibling'), + option, + ]))), +}; |