-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: Add code snippet to addons panel #29253
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit f2a8af8. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
6 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings
Hey @larsrickert, I like how you used the same code snippet on the SourceDecorator. However, this could ideally be an addon, similar to the existing StorySource addon. Though StorySource serves a different purpose—it only displays the actual story code from the file. |
@chakAs3 Thanks for the feedback! Imo the code generation / snippets are responsibility of the docs addon which also already shows the snippets on the "Docs" page. So this PR/feature "just" also shows the snippets on the single story pages. |
05996b9
to
14f6a7a
Compare
@shilman Hey :) Would it be possible for you to take a look at this PR? |
@larsrickert Sorry I missed this one. Will look later today! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @larsrickert ! Thanks for your patience on the review.
This looks great: a low-cost improvement to Storybook, eliminating the need for the Storysource addon, which is broken/outdated.
My original thought was to create a standalone addon for this, @storybook/addon-source
, which would co-exist with addon-docs
the same way that @storybook/addon-controls
current does. What do you think about that direction?
I realize this is a much simpler change, and I appreciate that.
I want to discuss this with the core team on Monday and get back to you. But I like this direction and appreciate your PR!!!
@larsrickert I haven't had a formal discussion with the team but initial sentiment from talking to a few people is that we should move controls & source handling into the core, and keep docs as its own addon. I will keep you posted on whether we're serious about that change & how it might get done. In the meantime, I'm inclined to merge this PR since it's useful as is. I will try to have some resolution this week. Thanks for your patience. |
14f6a7a
to
7b4d91f
Compare
@shilman Thanks for your insights and thoughts! In general, I appreciate the separation of concerns by moving features to dedicated addons. In the case of the docs addon / source generation I am open to both options. Since the source code generation is already part of the docs addon (and its already displayed on the "Docs" page for each story), the new "Code" panel would also fit perfectly in the current docs addon in my opinion. I like your idea about merging this feature already in the docs addon and then discuss if it should be split up into a source addon in the future. But since this would be a bigger refactoring and probably also other parts of the docs addon would be moved, I'd still merge this PR already as feature for Storybook 8.x. 👍 |
Hi @larsrickert, can you please add the following flag: parameters: {
docs: {
source: {
addonPanel: false,
},
},
} This way users can opt out of the new behavior if they want. Once that's ready and CI is green, I'll update |
7b4d91f
to
ddef097
Compare
Package BenchmarksCommit: No significant changes detected, all good. 👏 |
Hey @shilman Sure, no problem :) Is there some example/docs how to implement this or someone that could guide me here? I already tried to achieve it but in |
Oof. I'm actually not too familiar with that aspect of things. @ndelangen can you please help? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, and I agree with @shilman request to be able to turn it off.
ddef097
to
413f2d4
Compare
@shilman @kasperpeulen Thanks for the feedback! I added the parameter as requested :) |
@shilman Great, thanks for testing! Do you already have a rough release plan for this? |
fb132e5
to
9f35083
Compare
@larsrickert not so comfortable with the current parameter implementation. I have a cleaner solution with a worse user API. Need to figure that out, sorry for the delays. I'll update again later today |
@larsrickert i discussed with @yannbf and @ndelangen and the current parameter approach won't cut it. i'm going to reimplement it now with a worse API and then get it merged. thanks again for the contribution and for your patience on this. |
@larsrickert I've opened a PR on top of this one for your review. Please merge if you're OK with it, or we can discuss the changes there. I've also found some issues with the PR in its current form.
I've also reached out in Discord in case it's more efficient to discuss it there. |
78ee7df
to
db146c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition!
Don't we want to document this too?
MIGRATION.md
Outdated
```js | ||
export default { | ||
parameters: { | ||
docsSourcePanel: { disable: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I think this is the right API.
We already have parameters.docs.source.X
: https://storybook.js.org/docs/api/doc-blocks/doc-block-source
Wouldn't it make sense to keep in line with that, and have it as parameters.docs.source.panel = bool
instead?
Potentially, if we want to leave room for other panel-specific configs later, it could be parameters.docs.source.panel.enable = bool
cc @shilman
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that this has already been discussed, before.
Personally, I highly disagree with the direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just think that we can change internal hacks whenever, but we can only change the API in majors, so I'd rather merge this with hacks than an API we dislike.
It looks like we can add something here if we want: https://github.com/storybookjs/storybook/blob/next/code/core/src/manager/container/Panel.tsx/#L32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JReinhold — But as you (implicitly) point out, parameters.docs.source.X
are props of the Source doc block. That wouldn't be the case here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe parameters.docs.sourcePanel: boolean
would be a nice middle ground?
Although if the panel title is Code
, maybe it should be codePanel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JReinhold @kylegach Thanks for your input!
I updated the implementation to support a new parameters.docs.codePanel
parameter so the code panel can be disabled by setting:
export default {
parameters: {
docs: {
codePanel: false,
},
},
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Will add some documentation in a followup PR 😬
Closes #26691
What I did
Add a new "Code" panel for the docs addon so the generated code snippet can also be viewed/copied in single story mode and is no longer limited to the docs page / view mode.
Open questions:
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
yarn task --task sandbox --start-from auto --template vue3-vite/default-ts
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>
Greptile Summary
This PR adds a new 'Code' panel to the Storybook UI for displaying and copying generated code snippets in single story view mode, focusing on improvements for the docs addon and Vue3 renderer.
code/addons/docs/src/manager.tsx
for viewing generated code snippetscode/renderers/vue3/src/docs/sourceDecorator.ts
, improving handling of complex props and slotscode/addons/essentials/package.json
and related files to integrate the new 'Code' panel functionalitycode/addons/essentials/src/index.ts
, potentially affecting addon initialization order