diff --git a/.eslintrc.js b/.eslintrc.js index 3a70661031b9..ad34e8fc73a4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -14,6 +14,7 @@ module.exports = { plugins: ['prettier', 'jest', 'import', 'react', 'jsx-a11y', 'json'], parser: 'babel-eslint', parserOptions: { + ecmaVersion: 8, sourceType: 'module', }, env: { diff --git a/addons/a11y/src/components/Panel.js b/addons/a11y/src/components/Panel.js index d371ebc10359..3796cc5e75d8 100644 --- a/addons/a11y/src/components/Panel.js +++ b/addons/a11y/src/components/Panel.js @@ -35,21 +35,27 @@ class Panel extends Component { }; componentDidMount() { - this.props.channel.on(CHECK_EVENT_ID, this.onUpdate); - this.props.channel.on(STORY_RENDERED, this.requestCheck); - this.props.channel.on(RERUN_EVENT_ID, this.requestCheck); + const { channel } = this.props; + + channel.on(CHECK_EVENT_ID, this.onUpdate); + channel.on(STORY_RENDERED, this.requestCheck); + channel.on(RERUN_EVENT_ID, this.requestCheck); } componentDidUpdate(prevProps) { - if (!prevProps.active && this.props.active) { + const { active } = this.props; + + if (!prevProps.active && active) { this.requestCheck(); } } componentWillUnmount() { - this.props.channel.removeListener(CHECK_EVENT_ID, this.onUpdate); - this.props.channel.removeListener(STORY_RENDERED, this.requestCheck); - this.props.channel.removeListener(RERUN_EVENT_ID, this.requestCheck); + const { channel } = this.props; + + channel.removeListener(CHECK_EVENT_ID, this.onUpdate); + channel.removeListener(STORY_RENDERED, this.requestCheck); + channel.removeListener(RERUN_EVENT_ID, this.requestCheck); } onUpdate = ({ passes, violations }) => { @@ -60,8 +66,10 @@ class Panel extends Component { }; requestCheck = () => { - if (this.props.active) { - this.props.channel.emit(REQUEST_CHECK_EVENT_ID); + const { channel, active } = this.props; + + if (active) { + channel.emit(REQUEST_CHECK_EVENT_ID); } }; diff --git a/addons/a11y/src/components/Report/Elements.js b/addons/a11y/src/components/Report/Elements.js index 4b34e24870d3..3a957b513356 100644 --- a/addons/a11y/src/components/Report/Elements.js +++ b/addons/a11y/src/components/Report/Elements.js @@ -40,7 +40,9 @@ Element.propTypes = { /* eslint-disable react/no-array-index-key */ const Elements = ({ elements, passes }) => (
- {React.Children.map(this.props.children, (root, idx) => ( + {React.Children.map(children, (root, idx) => ({ + if (propTables) { + propTables.forEach(type => { types.set(type, true); }); } // depth-first traverse and collect types - const extract = children => { - if (!children) { + const extract = innerChildren => { + if (!innerChildren) { return; } - if (Array.isArray(children)) { - children.forEach(extract); + if (Array.isArray(innerChildren)) { + innerChildren.forEach(extract); return; } - if (children.props && children.props.children) { - extract(children.props.children); + if (innerChildren.props && innerChildren.props.innerChildren) { + extract(innerChildren.props.innerChildren); } if ( - typeof children === 'string' || - typeof children.type === 'string' || - (Array.isArray(this.props.propTablesExclude) && // also ignore excluded types - ~this.props.propTablesExclude.indexOf(children.type)) // eslint-disable-line no-bitwise + typeof innerChildren === 'string' || + typeof innerChildren.type === 'string' || + (Array.isArray(propTablesExclude) && // also ignore excluded types + ~propTablesExclude.indexOf(innerChildren.type)) // eslint-disable-line no-bitwise ) { return; } - if (children.type && !types.has(children.type)) { - types.set(children.type, true); + if (innerChildren.type && !types.has(innerChildren.type)) { + types.set(innerChildren.type, true); } }; // extract components from children - extract(this.props.children); + extract(children); const array = Array.from(types.keys()); array.sort((a, b) => getName(a) > getName(b)); - const { - maxPropObjectKeys, - maxPropArrayLength, - maxPropStringLength, - excludedPropTypes, - } = this.props; - const propTables = array.map((type, i) => ( + propTables = array.map((type, i) => ( // eslint-disable-next-line react/no-array-index-key -); } render() { - //"{getName(type)}" Component
+"{getName(type)}" Component
- Prop Types
+Prop Types
{propTables}- return this.props.showInline ? this._renderInline() : this._renderOverlay(); + const { showInline } = this.props; + // + return showInline ? this._renderInline() : this._renderOverlay(); } } -Story.getDerivedStateFromProps = ({ styles }) => ({ stylesheet: styles(stylesheet) }); +Story.getDerivedStateFromProps = ({ styles }) => ({ stylesheet: styles(stylesheetBase) }); Story.displayName = 'Story'; diff --git a/addons/info/src/components/makeTableComponent.js b/addons/info/src/components/makeTableComponent.js index 173083a846df..2f2cdd979ccb 100644 --- a/addons/info/src/components/makeTableComponent.js +++ b/addons/info/src/components/makeTableComponent.js @@ -67,10 +67,12 @@ const propsFromPropTypes = type => { return; } + // eslint-disable-next-line react/destructuring-assignment if (!props[property]) { props[property] = { property }; } + // eslint-disable-next-line react/destructuring-assignment props[property].defaultValue = value; }); } @@ -84,10 +86,12 @@ export default function makeTableComponent(Component) { return null; } + /* eslint-disable react/destructuring-assignment */ const propDefinitionsMap = hasDocgen(props.type) ? propsFromDocgen(props.type) : propsFromPropTypes(props.type); const propDefinitions = Object.values(propDefinitionsMap); + /* eslint-enable react/destructuring-assignment */ return ; }; diff --git a/addons/info/src/components/markdown/code.js b/addons/info/src/components/markdown/code.js index db17696ca944..3663bbd0f1d1 100644 --- a/addons/info/src/components/markdown/code.js +++ b/addons/info/src/components/markdown/code.js @@ -18,6 +18,7 @@ export class Code extends React.Component { } render() { + const { language, code } = this.props; const codeStyle = { fontFamily: 'Menlo, Monaco, "Courier New", monospace', backgroundColor: '#fafafa', @@ -31,12 +32,12 @@ export class Code extends React.Component { overflowX: 'scroll', }; - const className = this.props.language ? `language-${this.props.language}` : ''; + const className = language ? `language-${language}` : ''; return ( ); @@ -52,14 +53,14 @@ Code.defaultProps = { code: null, }; -export function Blockquote(props) { +export function Blockquote({ children }) { const style = { fontSize: '1.88em', fontFamily: 'Menlo, Monaco, "Courier New", monospace', borderLeft: '8px solid #fafafa', padding: '1rem', }; - return- {this.props.code} + {code}
{props.children}; + return{children}; } Blockquote.propTypes = { children: PropTypes.node }; diff --git a/addons/info/src/components/markdown/htags.js b/addons/info/src/components/markdown/htags.js index b0f0df8d652a..50b542e601c4 100644 --- a/addons/info/src/components/markdown/htags.js +++ b/addons/info/src/components/markdown/htags.js @@ -11,7 +11,7 @@ const propTypes = { id: PropTypes.string, }; -export function H1(props) { +export function H1({ id, children }) { const styles = { ...baseFonts, borderBottom: '1px solid #eee', @@ -21,8 +21,8 @@ export function H1(props) { fontSize: '40px', }; return ( -- {props.children} +
+ {children}
); } @@ -30,7 +30,7 @@ export function H1(props) { H1.defaultProps = defaultProps; H1.propTypes = propTypes; -export function H2(props) { +export function H2({ id, children }) { const styles = { ...baseFonts, fontWeight: 600, @@ -39,8 +39,8 @@ export function H2(props) { fontSize: '30px', }; return ( -- {props.children} +
+ {children}
); } @@ -48,7 +48,7 @@ export function H2(props) { H2.defaultProps = defaultProps; H2.propTypes = propTypes; -export function H3(props) { +export function H3({ id, children }) { const styles = { ...baseFonts, fontWeight: 600, @@ -58,8 +58,8 @@ export function H3(props) { textTransform: 'uppercase', }; return ( -- {props.children} +
+ {children}
); } @@ -67,7 +67,7 @@ export function H3(props) { H3.defaultProps = defaultProps; H3.propTypes = propTypes; -export function H4(props) { +export function H4({ id, children }) { const styles = { ...baseFonts, fontWeight: 600, @@ -76,8 +76,8 @@ export function H4(props) { fontSize: '20px', }; return ( -- {props.children} +
+ {children}
); } @@ -85,7 +85,7 @@ export function H4(props) { H4.defaultProps = defaultProps; H4.propTypes = propTypes; -export function H5(props) { +export function H5({ id, children }) { const styles = { ...baseFonts, fontWeight: 600, @@ -94,8 +94,8 @@ export function H5(props) { fontSize: '18px', }; return ( -- {props.children} +
+ {children}
); } @@ -103,7 +103,7 @@ export function H5(props) { H5.defaultProps = defaultProps; H5.propTypes = propTypes; -export function H6(props) { +export function H6({ id, children }) { const styles = { ...baseFonts, fontWeight: 400, @@ -112,8 +112,8 @@ export function H6(props) { fontSize: '18px', }; return ( -- {props.children} +
+ {children}
); } diff --git a/addons/info/src/components/markdown/pre/copyButton.js b/addons/info/src/components/markdown/pre/copyButton.js index ff11d7a60d0f..e29632663d73 100644 --- a/addons/info/src/components/markdown/pre/copyButton.js +++ b/addons/info/src/components/markdown/pre/copyButton.js @@ -24,7 +24,7 @@ const Button = styled('button')( borderColor: '#ccc', }, }, - props => props.styles + ({ styles }) => styles ); const ContentWrapper = styled('div')( @@ -32,19 +32,19 @@ const ContentWrapper = styled('div')( transition: 'transform .2s ease', height: 16, }, - props => ({ - ...props.styles, - transform: props.toggled ? 'translateY(0px)' : 'translateY(-100%) translateY(-6px)', + ({ styles, toggled }) => ({ + ...styles, + transform: toggled ? 'translateY(0px)' : 'translateY(-100%) translateY(-6px)', }) ); -function CopyButton(props) { - const { copyButton = {}, copyButtonContent } = props.theme; +function CopyButton({ theme, onClick, toggled }) { + const { copyButton = {}, copyButtonContent } = theme; const { toggleText = 'Copied!', text = 'Copy', ...copyButtonStyles } = copyButton; return ( -