mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-10 00:12:22 +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) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.props.channel.on("background-set", backgrounds => this.setState({ backgrounds }));
|
this.props.channel.on("background-set", backgrounds => this.setState({ backgrounds }));
|
||||||
|
this.props.channel.on("background-unset", backgrounds => this.setState({ backgrounds: [] }));
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
|
||||||
const { channel } = this.props;
|
const { channel } = this.props;
|
||||||
const backgrounds: BackgroundDetail[] = this.state.backgrounds;
|
const backgrounds: BackgroundDetail[] = [...this.state.backgrounds];
|
||||||
|
|
||||||
if (!backgrounds.length) {
|
if (!backgrounds.length) {
|
||||||
return (
|
return (
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import addon from "@kadira/storybook-addons";
|
import addons from "@kadira/storybook-addons";
|
||||||
|
|
||||||
const style = {
|
const style = {
|
||||||
wrapper: {
|
wrapper: {
|
||||||
@ -25,12 +25,16 @@ export class BackgroundDecorator extends React.Component<any, any> {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.channel = addon.getChannel();
|
this.channel = addons.getChannel();
|
||||||
this.story = this.props.story();
|
this.story = this.props.story();
|
||||||
|
|
||||||
this.channel.on("background", background => this.setState({ background }));
|
this.channel.on("background", background => this.setState({ background }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.channel.emit("background-unset");
|
||||||
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.channel.emit("background-set", this.props.backgrounds);
|
this.channel.emit("background-set", this.props.backgrounds);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user