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

Info addon: prettify the source? #1602

Closed
slorber opened this issue Aug 5, 2017 · 16 comments
Closed

Info addon: prettify the source? #1602

slorber opened this issue Aug 5, 2017 · 16 comments

Comments

@slorber
Copy link
Contributor

slorber commented Aug 5, 2017

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:

image

@usulpro
Copy link
Member

usulpro commented Aug 5, 2017

@slorber I think it's a good idea!
Do you want to make a PR for that?

@slorber
Copy link
Contributor Author

slorber commented Aug 5, 2017

I can try :)

@slorber
Copy link
Contributor Author

slorber commented Aug 5, 2017

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. maxPropsIntoLine: 1, helps but one prop is still on a single line which makes it hard to read for complex object props.

@usulpro
Copy link
Member

usulpro commented Aug 5, 2017

Yes, it looks like this!
But I guess having the source as a string could be a useful feature in the next stages.

@slorber You can check out this example: https://github.com/UsulPro/storybook-styleguidist
it generates markdown from the stories sources. Can't promise that it's the best solution, but maybe it could be useful as a starting point.

@slorber
Copy link
Contributor Author

slorber commented Aug 5, 2017

@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.

@usulpro
Copy link
Member

usulpro commented Aug 5, 2017

it's a fork of addon-info and just generates text string with the source of the story component.

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

@usulpro
Copy link
Member

usulpro commented Aug 9, 2017

Our own solution isn't ideal as well. So maybe we could switch framework specific tools depending on what Storybook is running?
cc: @shilman

@shilman
Copy link
Member

shilman commented Aug 9, 2017

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 addon-knobs:

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. addon-info-react.

@kohlmannj
Copy link
Contributor

kohlmannj commented Aug 23, 2017

I've looked into this recently, and have a few notes:

@slorber
Copy link
Contributor Author

slorber commented Aug 23, 2017

@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

@shilman
Copy link
Member

shilman commented Aug 23, 2017

@kohlmannj awesome!!! i think @ndelangen has a lot of experience with syntax highlighting and can chime in?

@stale
Copy link

stale bot commented Nov 2, 2017

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!

@stale stale bot added the inactive label Nov 2, 2017
@stale
Copy link

stale bot commented Nov 17, 2017

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!

@stale stale bot closed this as completed Nov 17, 2017
@eps1lon
Copy link
Contributor

eps1lon commented Feb 23, 2018

For anyone stumbling over this: You can hide the source from withInfo and use storysource instead.

@slorber
Copy link
Contributor Author

slorber commented Feb 23, 2018

thanks didn't know about this new plugin

@chinchiheather
Copy link
Member

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.
I thought someone else might find it useful - https://github.com/chinchiheather/storybook-addon-prettier-source

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

No branches or pull requests

6 participants