-
Notifications
You must be signed in to change notification settings - Fork 22
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
Knobs for slotted content #1
Comments
Hmmm, could you describe your use case with a little more detail so I can visualize it better. The short answer is probably "yes" - but I need to see what you're trying to do so I'm not guessing. Thanks! |
Sure. Let's say I redefined the default render() {
- return <div>Hello, World! I'm {this.getText()}</div>;
+ return (
+ <div>
+ Hello, World! I'm <slot />, nice to meet you!
+ </div>
+ );
}
} In the <my-component>
<span>a component</span>
</my-component> However, the more I look at knobs, the more it seems like it would be cumbersome to have a knob for slot content. Instead, maybe it would be easier to allow the story to export slotted content as part of the |
Ah, I see what you mean. I will ponder this as I can see how that would be useful. Though one of my goals is to keep a minimal API. There's another feature for this thing which I haven't documented yet, but your individual story files can export a function instead of the object I used in the example. If we detect a function, it will be called with the story context and reference to KNOBS so that it can render itself (see code here). It would look something like this: /* my-component.story.js */
export default function(stories, knobs) {
const mainEl = document.createElement('div'); // do this OUTSIDE the render function below
stories.add('my-component', () => {
mainEl.innerHTML = '';
/**
* Append things to the mainEl here. You can insert knob values
* anywhere you want.
*/
return mainEl;
});
} My plan with this is to eventually provide the function with all the utilities it needs to efficiently render a custom story without having to rewrite all the code I wrote to render a story. This would be similar to the idea of render props. |
This starting config is fantastic!
So far my only question is if it would be possible to have a knob or some kind of way of passing in HTML/JSX to a
<slot />
in a component. Do you know if storybook would allow this?The text was updated successfully, but these errors were encountered: