-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Show Code Open by default #10430
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. |
@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)
}
} |
I'm looking for a review, please👆🏻 |
Gadzooks!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.3.0-alpha.17 containing PR #14729 that references this issue. Upgrade today to the
Closing this issue. Please re-open if you think there's still more to do. |
Leaving this here to hopefully help someone in the future... If you are just looking to have the code block open for a single story, you just need to add <Canvas withSource="open">
<Story name="Cool story bro">
<>
</Story>
</Canvas> Hope this helps someone like myself, since this isn't documented anywhere that I could find. Cheers! |
It has been added, took me a bit to find. |
Based on shilman comment above, for those that are looking on how to implement it: // .storybook/preview.ts
export const parameters = {
docs: {
source: {
state: 'open',
},
}
} |
now with storybook 7, it seems to be changed to following and it works for me: // .storybook/preview.js
export const parameters = {
// ...
docs: {
canvas: {
sourceState: 'shown'
}
}
}; Couldn't find a corresponding documentation on this though. |
As I read the source code, your example is on story level, not global in preview.js. For example, the enum for SourceState is still close or open.
But then again the function filtering the states is on story level with the "old" docs.source.state: Anyways neither solution works for me on storybook 7.4.0. Anyone else still having issues? |
I found the docs for it. https://storybook.js.org/docs/react/api/doc-block-canvas#sourcestate |
For storybook 7 or higher, the code below does not work. ```js export const parameters = { docs: { source: { state: 'open', }, }, }; ``` It should be fixed like below: ```js export const parameters = { docs: { canvas: { sourceState: 'shown' } } }; ``` However, this document seems not changed so far. So I updated it. ## References: - https://storybook.js.org/docs/api/doc-block-canvas#sourcestate - storybookjs#10430
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?
The text was updated successfully, but these errors were encountered: