d4rekanguok / talenote

Storybook-esque component directory for Sveltekit
talenote.vercel.app
MIT License
65 stars 2 forks source link

[feature request] show sample code #10

Open swyxio opened 2 years ago

swyxio commented 2 years ago

one of my favorite parts of storybook is i can copy the code for using the component itself

<FeatureCard foo="bar" />

which is like a story basically. what do you think?

d4rekanguok commented 2 years ago

oh that's handy! I think we can construct that from a snapshot of prop + component name.. how is it done in Storybook? Is it something people have to define themselves?

swyxio commented 2 years ago

yes people have to define it themselves. thats what a "Story" is, basically. https://storybook.js.org/docs/react/writing-stories/introduction#how-to-write-stories

also turns out to be a nicer way of offering preset props for people to switch between

d4rekanguok commented 2 years ago

I think a model like Storybook where the 'story' is separated from the component itself is a good idea — the way I'm doing it (passing default props in a context module script) is not always practical (some components dont want defaultProps) and it feels 'dirty' to pass irrelevant stuff to prod build

Something like component.tale.svelte would be good, ppl can import their component & write their story there. 2.0!

Thanks so much for the suggestion!

swyxio commented 2 years ago

yeah!

ideally i'd want something like the Playground method from Docz: https://www.docz.site/docs/built-in-components#playground-component

gives you the ability to write arbitrary text to give the reader more context, and you just wrap the <Playground> component to give all the storybookey goodness. when i tried implementing it however i ran into a hurdle of not being able to access the source code of the svelte component child i am wrapping... have a look and see if you get what i mean