diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-13 19:05:57 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-13 20:55:51 -0400 |
commit | 3c8ee4341f682edb419f9193e07f214d96209384 (patch) | |
tree | 5a3d18728d8fda6b124db25d811fecaec5055125 /src/content/dependencies/generateTextWithTooltip.js | |
parent | 35720bd44ef2d6d2a2de4ca4946bfc9ee108d4a8 (diff) |
content, css, client: generateTextWithTooltip
Diffstat (limited to 'src/content/dependencies/generateTextWithTooltip.js')
-rw-r--r-- | src/content/dependencies/generateTextWithTooltip.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/content/dependencies/generateTextWithTooltip.js b/src/content/dependencies/generateTextWithTooltip.js new file mode 100644 index 00000000..518e8782 --- /dev/null +++ b/src/content/dependencies/generateTextWithTooltip.js @@ -0,0 +1,47 @@ +export default { + extraDependencies: ['html'], + + slots: { + attributes: { + type: 'attributes', + mutable: false, + }, + + text: { + type: 'html', + mutable: false, + }, + + tooltip: { + type: 'html', + mutable: false, + }, + }, + + generate(slots, {html}) { + const hasTooltip = + !html.isBlank(slots.tooltip); + + if (slots.attributes.blank && !hasTooltip) { + return slots.text; + } + + let {attributes} = slots; + + if (hasTooltip) { + attributes = attributes.clone(); + attributes.add({ + [html.joinChildren]: '', + [html.noEdgeWhitespace]: true, + class: 'text-with-tooltip', + }); + } + + const content = + (hasTooltip + ? [slots.text, slots.tooltip] + : slots.text); + + return html.tag('span', attributes, content); + }, +}; |