MCPcopy Create free account
hub / github.com/adearriba/ShopifyCheckoutJS / constructor

Method constructor

src/Components/Tooltip.js:2–42  ·  view source on GitHub ↗
(text, fieldId, icon = '#question')

Source from the content-addressed store, hash-verified

1export class Tooltip extends HTMLDivElement{
2 constructor(text, fieldId, icon = '#question'){
3 let classes = {
4 wrapper: ['field__icon'],
5 container: ['tooltip-container'],
6 tooltip: ['tooltip'],
7 button: ['tooltip-control'],
8 svgIcon: ['icon-svg', 'icon-svg--color-adaptive-lighter','icon-svg--size-16', 'icon-svg--block', 'icon-svg--center'],
9 };
10
11 let tooltipDiv = document.createElement('div');
12 tooltipDiv.classList.add(...classes.wrapper);
13
14 let tooltipContainer = document.createElement('div');
15 tooltipContainer.classList.add(...classes.container);
16
17 let tooltipSpan = document.createElement('span');
18 tooltipSpan.id = `tooltip-for-${fieldId}`;
19 tooltipSpan.classList.add(...classes.tooltip);
20 tooltipSpan.innerText = text;
21
22 let button = document.createElement('button');
23 button.classList.add(...classes.button);
24 button.type = 'button';
25
26 let iconSVG = document.createElementNS('http://www.w3.org/2000/svg','svg');
27 iconSVG.classList.add(...classes.svgIcon);
28 iconSVG.setAttribute('role', 'presentation');
29 iconSVG.focusable = 'false';
30
31 let use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
32 use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', icon);
33 use.setAttributeNS('http://www.w3.org/1999/xlink', 'href', icon);
34
35 iconSVG.appendChild(use);
36 button.appendChild(iconSVG);
37 tooltipContainer.appendChild(button);
38 tooltipContainer.appendChild(tooltipSpan);
39 tooltipDiv.appendChild(tooltipContainer);
40
41 return tooltipDiv;
42 }
43}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected