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
[Storybook] Add story code snippets #7716
Draft
mgadewoll
wants to merge
13
commits into
elastic:main
Choose a base branch
from
mgadewoll:spacetime/storybook-code-snippets
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[Storybook] Add story code snippets #7716
mgadewoll
wants to merge
13
commits into
elastic:main
from
mgadewoll:spacetime/storybook-code-snippets
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mgadewoll
added
documentation
Issues or PRs that only affect documentation - will not need changelog entries
skip-changelog
labels
Apr 26, 2024
7 tasks
+ adds addon panel for outputting code snippet with Storybooks SyntaxHighlighter + registers code-snippet addon panel in Storybook manager
- ensure naming convention for stateful wrapper to start with Stateful... for filters to work - ensure args are passed along when using decorators - ensure no anonymous render functions are used as they would otherwise be skipped
- ensures resolving wrapper by using specific parameter - updates FLyoutExample to ensure conditional code is initially available for the code generation by using a storybook only prop
β¦unction children
ensures the prop is added as expected and that tokens are not resolved
mgadewoll
force-pushed
the
spacetime/storybook-code-snippets
branch
from
May 10, 2024 15:11
6c1c416
to
01bfb67
Compare
Preview staging links for this PR:
|
π Build Succeeded
History
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
documentation
Issues or PRs that only affect documentation - will not need changelog entries
skip-changelog
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
π§ This PR is still being updated and annotated π§
π’ This PR adds code snippets to our stories. π¦ π©βπ»
The goal of this is to improve devX by providing dynamically updated code snippets for the stories. The code snippet is generated on story load as well as when any
args
change (e.g. when controls in the controls table are being updated)This new functionality for code snippets is provided in an additional story panel next to the available panels for "Controls", "Actions" and "Interactions".
The basis for the code snippet generation is heavily inspired (copied and enhanced) on Storybooks Source block. The internal
jsxDecorator
file was copied and then adjusted to our specific needs. The main functionality to generate a string from react elements comes from thereact-element-to-jsx-string
package that is used.The overall setup
We run our custom
jsxDecorator
on every story as a decorator viapreview.tsx
. This decorator generates the code snippet asstring
and sends it via Storybooks Channel events to our newly added custom addon panel which outputs the code string using StorybooksSyntaxHighlighter
copmponent.The main updates to the
jsxDecorator
on our side are to ensure the code outputs clean and relevant code snippets.What was considered:
css
on a component in a story it will be an Emotion component)Stateful
(requires us to follow an agreed convention)_
underscore,<_Component>
is changed to<Component>
)css
object tostyle
attributefalse
values wherefalse
has meaning)The updates happen in different stages in
jsxDecorator
:react-element-to-jsx-string
and with which optionsreact-element-to-jsx-string
prettier
Options
Currently there are two addon specific parameter options added with this PR that can be used under the key
codeSnippet
in theparameters
config key.Screenshots
skipped code snippet generation
Disclaimer
jsxDecorator
functionality yet.QA