Created
October 23, 2018 23:21
-
-
Save ninetails/904d216109ea3d611f9993a4350cc45c to your computer and use it in GitHub Desktop.
Remove style inside React Storybook
This file contains hidden or 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
// @todo a way to revert to be a switch plugin | |
(() => { | |
Array.from(document.getElementById('storybook-preview-iframe').contentDocument.body.querySelectorAll('.sb-wrapper')) | |
.forEach(el => { | |
el.style.display = 'none' | |
}) | |
// remove styles | |
Array.from(document.getElementById('storybook-preview-iframe').contentDocument.head.getElementsByTagName("*")) | |
.filter(el => el.sheet) | |
.forEach(el => { | |
el.sheet.disabled = true | |
}) | |
// remove inline styles | |
Array.from(document.getElementById('storybook-preview-iframe').contentDocument.getElementById('root').firstChild.firstElementChild.getElementsByTagName("*")) | |
.filter(el => el.getAttribute('style') && el) | |
.forEach(el => { | |
el.dataset.style = el.getAttribute('style') | |
el.removeAttribute('style') | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment