/** * * InputCheckboxPlugin * */ import React from 'react'; import PropTypes from 'prop-types'; import cn from 'classnames'; import styles from './styles.scss'; class InputCheckboxPlugin extends React.Component { // eslint-disable-line react/prefer-stateless-function state = { showBackground: false, showCog: false }; componentWillReceiveProps(nextProps) { // Remove background if another input is selected if (nextProps.inputSelected !== this.props.inputSelected && nextProps.inputSelected !== this.props.name) { this.setState({ showBackground: false }); } if (!nextProps.isOpen) { this.setState({ showBackground: false, showCog: false }); } } handleChange = () => { const target = { type: 'checkbox', name: this.props.name, value: !this.props.value, }; // Don't show the label background if the user unselects the input if (!this.props.value) { this.setState({ showBackground: true }); // Tell the Parent component that another input has been selected this.props.setNewInputSelected(this.props.name); // Tell the policies component to show the associated routes this.context.setShouldDisplayPolicieshint(); this.context.setInputPoliciesPath(this.props.name); } else { this.setState({ showBackground: false, showCog: false }); this.props.setNewInputSelected(''); } this.context.onChange({ target }); } handleClick = () => { this.setState({ showBackground: !this.state.showBackground }); this.props.setNewInputSelected(this.props.name); this.context.setInputPoliciesPath(this.props.name); if (this.state.showBackground) { this.context.resetShouldDisplayPoliciesHint(); } else { this.context.setShouldDisplayPolicieshint(); } } render() { return (