Skip to content
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

Addon-docs: Add parameter to show code by default #14729

Merged
merged 7 commits into from
Apr 29, 2021

Conversation

frassinier
Copy link
Contributor

@frassinier frassinier commented Apr 27, 2021

Issue: #10430

What I did

The property isExpanded was already available on <Canvas> block

Now you can set docs.source.state on your Addon Docs configuration!

export const parameters = {
  docs: {
    source: {
      state: 'open',
     },
  },
};

How to test

Visit https://5a375b97f4b14f0020b0cda3-wplcskzipa.chromatic.com/?path=/docs/addons-controls--basic
Where Code bocks are shown by default now.

  • Is this testable with Jest or Chromatic screenshots? ✅
  • Does this need a new example in the kitchen sink apps? ❎
  • Does this need an update to the documentation? ✅

If your answer is yes to any of these, please make sure to include it in your PR.

@frassinier frassinier requested a review from shilman April 28, 2021 13:33
@shilman shilman changed the title Addon-docs: Show code by default Addon-docs: Add parameter to show code by default Apr 29, 2021
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great @frassinier, thank you! Made a couple small changes before merging 😉

@shilman shilman merged commit f6f4c8f into next Apr 29, 2021
@shilman shilman deleted the feat/addon-docs/show_code branch April 29, 2021 15:30
@shilman shilman restored the feat/addon-docs/show_code branch April 29, 2021 15:44
@frassinier frassinier deleted the feat/addon-docs/show_code branch April 29, 2021 15:45
@thien-do
Copy link

thien-do commented May 6, 2021

Hi :D I've just tested this in the new alpha release, and it seems it works when set:

  • globally in preview.js
  • page-level, like in an export default { parameters ... }

but it does not work when set:

  • story-level, like Foo.parameters.docs.source.state = 'open'

@frassinier
Copy link
Contributor Author

This PR was for Canvas, not the Story actually,
That's why we talk about global default behavior!

In MDX, at the story level, we still need to use isExpanded on Canvas which was already there!

The property isExpanded was already available on block

@thien-do
Copy link

thien-do commented May 6, 2021

@frassinier thank you! It seems I can also use "isExpanded" on a named exported Story in CSF?

@@ -13,6 +13,7 @@ When you install [Storybook Docs](../README.md), `DocsPage` is the zero-config d
- [Remixing DocsPage using doc blocks](#remixing-docspage-using-doc-blocks)

This comment was marked as off-topic.

source: {
state: 'open',
},
},

This comment was marked as off-topic.

@@ -57,7 +53,7 @@ const getPreviewProps = (
return {
...props, // pass through columns etc.
withSource: sourceProps,
isExpanded: withSource === SourceState.OPEN,

This comment was marked as off-topic.

This comment was marked as off-topic.

@andrew09
Copy link

@frassinier do you mind updating the PR description for this to the updated code which shows that state: "open", is the correct key/value as opposed to state: true which the description suggests?

@dutscher
Copy link

why this isnt documented in here https://storybook.js.org/docs/react/writing-docs/docs-page ?
@shilman
cheers and thanks for the implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants