Created
December 9, 2020 19:35
-
-
Save skovy/cc82245d99de74190b2e161c9becc27c 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
const HIGHLIGHT_WIDTH = 2; | |
const HIGHLIGHT_SELECTOR = '[data-component]'; | |
function createHighlighterForElement(component: HTMLElement) { | |
const highlighter = document.createElement('div'); | |
const { x, y, width, height } = component.getBoundingClientRect(); | |
highlighter.style.cssText = ` | |
top: ${y + window.scrollY - HIGHLIGHT_WIDTH}px; | |
left: ${x - HIGHLIGHT_WIDTH}px; | |
height: ${height}px; | |
width: ${width}px; | |
border: ${HIGHLIGHT_WIDTH}px solid red; | |
position: absolute; | |
`; | |
return highlighter; | |
} | |
function highlightComponents() { | |
const components = document.querySelectorAll<HTMLElement>(HIGHLIGHT_SELECTOR); | |
components.forEach((component) => { | |
const highlighter = createHighlighterForElement(component); | |
document.body.appendChild(highlighter); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment