-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Vue: Improve generated code snippets #27194
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 22938b9. 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. |
Relates to #1078, #414 - simplified some Stories - refactor oynx icon import code transformer to work globally so we don't need to add it to every component that uses icons - temporarily copy over improved source code generation until it is released in Storybook itself (see storybookjs/storybook#27194)
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 job, @larsrickert! I had some old TODOs regarding slots because the generated code wasn't handling edge cases properly.
@larsrickert Should be Let me now when you are finished with this! |
…typing Next.js: Add typing for NextImage to main framework options type (cherry picked from commit 46646d2)
…ypes-for-framework-builder-fields Types: Fix typing for main.framework/builder fields (cherry picked from commit 1ae28db)
Next.js: Avoid conflicts with the raw loader (cherry picked from commit f5fc402)
25eda56
to
4428320
Compare
…urce-code Vue: Improve generated code snippets (cherry picked from commit 6356195)
is there any plans to add @ events the autogenerated code snippets? @ben-hamel I am not sure about this since I'd say thats the purpose of the actions addon. The issue I see is how we can extract the source code of the functions that you pass as event handler. I don't see a reliable way to achieve this without the risk of potentially huge function contents due to some imported library functions. Also we need to know which events each story is actually using since not all events are relevant for all stories. |
In our Storybook components, we generally include more involved examples, and we’ve found that the autodocs feature leaves out too many details in the code snippets. We were hoping there might be a way to bridge that gap a bit better. Currently, we’re using template strings for our code snippets as a workaround, but it feels like storybook should be able to handle since everything is already set up in the render functions and templates. |
Could you please share one example story source? The generated code snippets have become quiet advanced with the release if this PR in Storybook Version 8.3 |
This is a very simple example. but looking at the code vs what is generated in the docs, your missing a piece of the puzzle. If you copy in the code example in the picture into your app, you wont have the same outcome as the story. There's nothing really to bridge the gap for devs other then digging into the source code of the story. I know an alert can probably be figured out pretty quickly, but you can imagine code that's reaching out to API's or doing more complex things. export const Primary: Story = {
render: (args) => ({
components: { Button },
setup() {
onMounted(() => {
alert("hello");
});
return { args };
},
template: '<Button v-bind="args" />',
}),
args: {
primary: true,
label: "Button",
},
}; Not sure if this reasonable to expect or not from the Auto docs, but hoping there's a better way then having to write out our code examples |
relates to #26691
What I did
I created a new improved Vue source code generator that has several improvements compared to the current one:
my-prop
instead of:my-prop="true"
my-prop='"I am double quoted"'
, useful if e.g. passing SVG icon content as props:my-props="['a', 'b']"
), currently they are generated as object (:my-prop="{0:'a',1: 'b'}"
) which is incorrect<template #default>
for default slot without bindings<script lang="ts" setup>
(automatically move arrays and objects there)Here is an example which compares the most important features of this PR:
Old:
New:
As reference, here is the Story source for the above example:
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>