Storybook: docs: Show Code Open by default

Created on 15 Apr 2020  Â·  6Comments  Â·  Source: storybookjs/storybook

Hey team, I noticed the issue #8356 closed.
I'd only like to have an option to customize the story view (especially source code view), too.
Have you got any plan to resolve this issue?

addParameters({ docs: { previewSource: 'open' } })
P1 docs source feature request in progress

Most helpful comment

This would be lovely, I was just searching the docs on how to do this!

All 6 comments

@shilman has new progress?

This would be lovely, I was just searching the docs on how to do this!

🤞 my current workaround is to poll the page for show code buttons and click them. It's crazy janky.

🤞 my current workaround is to poll the page for show code buttons and click them. It's crazy janky.

@signal-intrusion How can you solve the problem by this hacking tricks.Could you pls show the code?Thank you

Any progress on this?

@ron0115 In preview.js I added this:

// this little bit of hacky code opens code samples
window.addEventListener('load', () => {
  let loc = window.location.href
  showCodeSamples()

  window.setInterval(() => {
    let newLoc = window.location.href

    if (newLoc !== loc) {
      loc = newLoc
      showCodeSamples()
    }
  }, 300)
})

function showCodeSamples() {
  try {
    const docs = document.querySelectorAll('.sbdocs')

    ;[].forEach.call(docs, (el) => {
      const buttons = el.querySelectorAll('button')
      const codeButton = [].find.call(buttons, (el) => el.textContent === 'Show code')
      if (codeButton) {
        codeButton.click()
      }
    })
  } catch (e) {
    console.warn(e)
  }
}
Was this page helpful?
0 / 5 - 0 ratings