From 3c8ee4341f682edb419f9193e07f214d96209384 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 13 Jan 2024 19:05:57 -0400 Subject: content, css, client: generateTextWithTooltip --- .../dependencies/generateTextWithTooltip.js | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/content/dependencies/generateTextWithTooltip.js (limited to 'src/content/dependencies/generateTextWithTooltip.js') 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); + }, +}; -- cgit 1.3.0-6-gf8a5