Skip to content

Instantly share code, notes, and snippets.

@ninetails
Created October 23, 2018 23:21
Show Gist options
  • Save ninetails/904d216109ea3d611f9993a4350cc45c to your computer and use it in GitHub Desktop.
Save ninetails/904d216109ea3d611f9993a4350cc45c to your computer and use it in GitHub Desktop.
Remove style inside React Storybook
// @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