-
-
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
Info addon: prettify the source? #1602
Comments
@slorber I think it's a good idea! |
I can try :) |
As far as I understand, the source is rendered from an VDOM representation with a custom recursive rendering logic, so using Prettier here means we would remove a lot of the current code (and available options) because we would probably run Prettier directly against a string. Is it something to consider? Otherwise it's probably possible to create more display options based on current code. |
Yes, it looks like this! @slorber You can check out this example: https://github.com/UsulPro/storybook-styleguidist |
@usulpro I'm not sure why you want to use markdown to display the source. For me the simplest option would probably be:
This would remove the burden of maintaining a custom vdom renderer and we could also expose prettier options as addon options. |
it's a fork of Maybe you're right and some existing package will be better, but not sure that react specific solution has a future in a sense that we're going to support other frameworks soon |
Our own solution isn't ideal as well. So maybe we could switch framework specific tools depending on what Storybook is running? |
I like @slorber 's proposed solution and would love to see a PR. Regarding support for multiple frameworks, I'd propose we either just add custom code to the addon to support other frameworks, like in function wrapperKnobs(options) {
if (options) channel.emit('addon:knobs:setOptions', options);
switch (window.STORYBOOK_ENV) {
case 'vue': {
return vueHandler(channel, manager.knobStore);
}
case 'react': {
return reactHandler(channel, manager.knobStore);
}
default: {
return reactHandler(channel, manager.knobStore);
}
}
} Alternatively we could create packages for each framework, e.g. |
I've looked into this recently, and have a few notes:
|
@kohlmannj it seems possible to embed prettier for runtime formatting. However it looks like it adds 4mb to the bundle because prettier ships with a lot of built in parsers that may not be easy to tree-shake/disable. See this PR jsx-to-string should already be a nice solution imho |
@kohlmannj awesome!!! i think @ndelangen has a lot of experience with syntax highlighting and can chime in? |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. We do try to do some housekeeping every once in a while so inactive issues will get closed after 90 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
For anyone stumbling over this: You can hide the source from withInfo and use storysource instead. |
thanks didn't know about this new plugin |
I have written an addon that uses prettier to format the source code, it does it inline as opposed to seeing the whole file in a panel like in the storysource addon. There is a standalone version of prettier now that can run in the browser. As with storysource you would want to hide the source from the info addon. |
Hi,
I think it would be nice if in the info addon, the source would be run against a tool like Prettier, it will be certainly more readable than current form:
The text was updated successfully, but these errors were encountered: