Last active
May 21, 2024 18:46
-
-
Save YonatanKra/36390ddc314ce63c37371653fc601cef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'global-jsdom/register'; | |
import '@vonage/vivid/button'; | |
function getAllNestedShadowRootsParents(element) { | |
const nestedShadowRoots = []; | |
function traverseShadowRoot(node) { | |
if (node.shadowRoot) { | |
nestedShadowRoots.push(node); | |
node.shadowRoot.querySelectorAll('*').forEach(child => { | |
traverseShadowRoot(child); | |
}); | |
} else { | |
Array.from(node.querySelectorAll('*')).forEach(child => traverseShadowRoot(child)); | |
} | |
} | |
traverseShadowRoot(element); | |
return Array.from(new Set(nestedShadowRoots)); | |
} | |
function appendOwnShadow(element) { | |
const shadowTemplate = `<template shadowrootmode="open">${element.shadowRoot.innerHTML}</template>`; | |
const tmpElement = document.createElement('div'); | |
tmpElement.innerHTML = shadowTemplate; | |
element.appendChild(tmpElement.children[0]); | |
} | |
export async function getHomePageTemplate() { | |
const template = ` | |
<style> | |
@import "https://unpkg.com/@vonage/vivid@latest/styles/tokens/theme-light.css"; | |
@import "https://unpkg.com/@vonage/vivid@latest/styles/core/all.css"; | |
@import "https://unpkg.com/@vonage/vivid@latest/styles/fonts/spezia-variable.css"; | |
#buttons-wrapper { | |
min-width: 50px; | |
min-height: 50px; | |
background-color: crimson; | |
} | |
</style> | |
<div id="buttons-wrapper" class="vvd-root"> | |
<vwc-button icon="facebook-color" label="ghost" appearance="ghost"></vwc-button> | |
<vwc-button icon="linkedin-color" label="ghost-light" appearance="ghost-light"></vwc-button> | |
<vwc-button icon="twitter-color" label="filled" appearance="filled"></vwc-button> | |
<vwc-button icon="instagram-color" label="outlined" appearance="outlined"></vwc-button> | |
</div> | |
`; | |
const div = document.createElement('div'); | |
div.innerHTML = template; | |
document.body.appendChild(div); | |
await new Promise(res => setTimeout(res)); | |
getAllNestedShadowRootsParents(div).reverse().forEach(appendOwnShadow); | |
return div.innerHTML; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment