From a119a99a7579ab5db698e06a118d17ca3ca46520 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Sat, 4 Nov 2017 00:40:58 +0100 Subject: [PATCH] FIX linting --- addons/background/src/BackgroundPanel.js | 24 +++++++++++++++---- .../src/__tests__/BackgroundPanel.js | 4 +--- addons/background/src/index.js | 24 +++++++++++++++---- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/addons/background/src/BackgroundPanel.js b/addons/background/src/BackgroundPanel.js index 34daedbcbb1..2da45e36529 100644 --- a/addons/background/src/BackgroundPanel.js +++ b/addons/background/src/BackgroundPanel.js @@ -1,5 +1,7 @@ import React, { Component } from 'react'; +import PropTypes from 'prop-types'; import addons from '@storybook/addons'; +import EventEmitter from 'events'; import Swatch from './Swatch'; @@ -56,9 +58,11 @@ export default class BackgroundPanel extends Component { constructor(props) { super(props); + const { channel, api } = props; + // A channel is explicitly passed in for testing - if (this.props.channel) { - this.channel = this.props.channel; + if (channel) { + this.channel = channel; } else { this.channel = addons.getChannel(); } @@ -67,7 +71,7 @@ export default class BackgroundPanel extends Component { this.channel.on('background-set', backgrounds => { this.setState({ backgrounds }); - const currentBackground = this.props.api.getQueryParam('background'); + const currentBackground = api.getQueryParam('background'); if (currentBackground) { this.setBackgroundInPreview(currentBackground); @@ -77,9 +81,9 @@ export default class BackgroundPanel extends Component { } }); - this.channel.on('background-unset', backgrounds => { + this.channel.on('background-unset', () => { this.setState({ backgrounds: [] }); - this.props.api.setQueryParams({ background: null }); + api.setQueryParams({ background: null }); }); } @@ -109,3 +113,13 @@ export default class BackgroundPanel extends Component { ); } } +BackgroundPanel.propTypes = { + api: PropTypes.shape({ + getQueryParam: PropTypes.func, + setQueryParams: PropTypes.func, + }).isRequired, + channel: PropTypes.instanceOf(EventEmitter), +}; +BackgroundPanel.defaultProps = { + channel: undefined, +}; diff --git a/addons/background/src/__tests__/BackgroundPanel.js b/addons/background/src/__tests__/BackgroundPanel.js index 893694800bd..1b05ef8212d 100644 --- a/addons/background/src/__tests__/BackgroundPanel.js +++ b/addons/background/src/__tests__/BackgroundPanel.js @@ -1,11 +1,9 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; +import EventEmitter from 'events'; import BackgroundPanel from '../BackgroundPanel'; -const EventEmitter = require('events'); -// const TestUtils = require('react-dom/test-utils'); - const backgrounds = [ { name: 'black', value: '#000000' }, { name: 'secondary', value: 'rgb(123,123,123)' }, diff --git a/addons/background/src/index.js b/addons/background/src/index.js index 0145daec7f3..b21ec5d26c2 100644 --- a/addons/background/src/index.js +++ b/addons/background/src/index.js @@ -1,4 +1,7 @@ import React from 'react'; +import PropTypes from 'prop-types'; +import EventEmitter from 'events'; + import addons from '@storybook/addons'; const style = { @@ -17,19 +20,21 @@ const style = { }; export class BackgroundDecorator extends React.Component { - state = { background: 'transparent' }; - constructor(props) { super(props); + const { channel, story } = props; + // A channel is explicitly passed in for testing - if (this.props.channel) { - this.channel = this.props.channel; + if (channel) { + this.channel = channel; } else { this.channel = addons.getChannel(); } - this.story = this.props.story(); + this.state = { background: 'transparent' }; + + this.story = story(); } componentWillMount() { @@ -56,6 +61,15 @@ export class BackgroundDecorator extends React.Component { return
{this.story}
; } } +BackgroundDecorator.propTypes = { + backgrounds: PropTypes.arrayOf(PropTypes.object), + channel: PropTypes.instanceOf(EventEmitter), + story: PropTypes.func.isRequired, +}; +BackgroundDecorator.defaultProps = { + backgrounds: [], + channel: undefined, +}; export default backgrounds => story => (