mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
OPS-2135 Setting a blank background state on unmount
This commit is contained in:
parent
f84c9c6df6
commit
673837d628
@ -23,11 +23,13 @@ export default class BackgroundPanel extends React.Component<BackgroundPanelProp
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.props.channel.on("background-set", backgrounds => this.setState({ backgrounds }));
|
||||
this.props.channel.on("background-unset", backgrounds => this.setState({ backgrounds: [] }));
|
||||
}
|
||||
|
||||
render () {
|
||||
|
||||
const { channel } = this.props;
|
||||
const backgrounds: BackgroundDetail[] = this.state.backgrounds;
|
||||
const backgrounds: BackgroundDetail[] = [...this.state.backgrounds];
|
||||
|
||||
if (!backgrounds.length) {
|
||||
return (
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as React from "react";
|
||||
import addon from "@kadira/storybook-addons";
|
||||
import addons from "@kadira/storybook-addons";
|
||||
|
||||
const style = {
|
||||
wrapper: {
|
||||
@ -25,12 +25,16 @@ export class BackgroundDecorator extends React.Component<any, any> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.channel = addon.getChannel();
|
||||
this.channel = addons.getChannel();
|
||||
this.story = this.props.story();
|
||||
|
||||
this.channel.on("background", background => this.setState({ background }));
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.channel.emit("background-unset");
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
this.channel.emit("background-set", this.props.backgrounds);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user