-
-
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
Emit event on updating background #6561
Emit event on updating background #6561
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://monorepo-git-fork-pajter-feature-addon-bac.storybook.now.sh |
change = (args: State) => this.setState(args); | ||
change = ({ selected, name }: { selected: string; name: string }) => { | ||
this.props.api.emit(EVENTS.UPDATE, { selected, name }); | ||
this.setState({ selected, expanded: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The menu always closes when selecting a color, so I moved expanded: false
into here.
Codecov Report
@@ Coverage Diff @@
## next #6561 +/- ##
==========================================
- Coverage 40.69% 40.68% -0.01%
==========================================
Files 616 616
Lines 8534 8536 +2
Branches 600 600
==========================================
Hits 3473 3473
- Misses 4972 4974 +2
Partials 89 89
Continue to review full report at Codecov.
|
Issue: n/a
What I did
I made the backgrounds addon emit an event when a user changes the background. This allows developers to listen for this event and implement any custom logic they need in their own Storybook (plugin), eg. setting a class name for theming on the preview body element based on the background color (light/dark).
I'm not sure if there's a specific convention I should follow for event names. I looked at and copied what I found in other addons.
How to test
storybook/background/update
event message in the console