From 023b626151f48cd87f93f35bd902c6d7d34cf66a Mon Sep 17 00:00:00 2001 From: A McIlwraith Date: Mon, 25 May 2026 09:12:31 -0400 Subject: [PATCH] [tooltip] Update tooltip pug to mixin --- src/pg/patterns/core/tooltip/_tooltip.pp | 46 ++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/pg/patterns/core/tooltip/_tooltip.pp b/src/pg/patterns/core/tooltip/_tooltip.pp index 57368dd..04be084 100644 --- a/src/pg/patterns/core/tooltip/_tooltip.pp +++ b/src/pg/patterns/core/tooltip/_tooltip.pp @@ -1,2 +1,44 @@ -a(href="#") Link with a tool tip - span(role="tooltip" inert tip-position="right") Tool tip content \ No newline at end of file +mixin tooltip(a) + - + const required = ['text'] + const optional = ['tip-position', 'tip-align', 'inert', 'role' ].concat(required) + + // function to strip unallowed options. + const allowed = (obj, whitelist) => { + const set = new Set(whitelist); + const result = {}; + for (const [k, v] of Object.entries(obj)) { + if (set.has(k)) result[k] = v; + } + return result; + } + + // default values + const defaults = { + "tip-position": "right", + inert: "inert", + role: "tooltip", + } + + // unhyphenated to hypenated + const map = { + position: 'tip-position', + align: 'tip-align' + } + for (const [from, to] of Object.entries(map)) { + if (a[from] !== undefined) { + a[to] = a[from] + delete a[from] + } + } + + // recheck for required and output if everything required is there. + if (a && required.some(key => !(key in a))) + p Missing keys: #{required.filter(key => !(key in a))} + else + - + text = a.text + a.text = undefined + a = allowed({...defaults, ...a}, optional) + + tool-tip&attributes(a)!= text \ No newline at end of file