-
-
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
Adding WithState and withState helpers to allow pure components actually change their state in stories #78
Conversation
Could you give us more information about this PR, may be a complete use case? And I really like to have a single API to do a thing. So, I think just having |
It looks like the It looks like it the idea is similar to If you go down the path of providing a way to update the props of a component within a story, then you also be able to open up a way of allowing those props to be a bit more dynamically updated. For example, potentially updated via a text box in the UI. I wonder if the API could be a bit more generic by accepting functions rather than just strings? <WithState handlers={onButtonSelected: props => activeId => ({ ...props, { activeId }})}>
// Which looks a little crazy, but is basically:
function onButtonSelected(props) { // WithState passes in the props
return function (activeId) { // Your component passes in arbitrary args
return Object.assign(
{},
props,
{ activeId: activeId }
);
}
}
// So, given a props object, return a new one with the expected state. Which might make more sense with some name changes (lots of code emitted): <PropsContainer updaters={onButtonSelected: /* as above */}>
{props => (
<ButtonGroup
activeId={props.activeId}
onButtonSelected={props.onButtonSelected} />
)}
</PropsContainer> Sorry for the ramble, just spitballing here |
@ilyabo any update on this ? Needed it for a project. that's why I'm asking. |
@ilyabo I think this is great and this doesn't need any support from core storybook APIs. So, I think it's better to create this as a independent NPM module. We can have a link in the README to addons and list this project there. |
I'm going to close this in-favour of separate NPM as mentioned in the above comment. |
…fragment-15.3.2 [email protected] untested⚠️
UI: Fix z-index in modal elements
☁️ Nx Cloud ReportCI is running/has finished running commands for commit f37f279. 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 1 targetSent with 💌 from NxCloud. |
WithState
orwithState
can be used to wrap a component and inject into it prop values coming from change handlers: