import { ToggleControl } from '@wordpress/components'; import clsx from 'clsx'; import { Children, Component } from 'react'; import InfoPopover from 'calypso/components/info-popover'; import './style.scss'; class PluginAction extends Component { handleAction = ( event ) => { if ( ! this.props.disabledInfo ) { this.props.action(); } else { this.infoPopover.handleClick( event ); } }; disabledInfoLabelRef = ( ref ) => { this.disabledInfoLabel = ref; }; renderLabel() { if ( ! this.props.label ) { return null; } return ( /* eslint-disable jsx-a11y/click-events-have-key-events */ /* eslint-disable jsx-a11y/no-static-element-interactions */ { this.props.label } { this.renderDisabledInfo() } /* eslint-enable jsx-a11y/click-events-have-key-events */ /* eslint-enable jsx-a11y/no-static-element-interactions */ ); } infoPopoverRef = ( ref ) => { this.infoPopover = ref; }; renderDisabledInfo() { if ( ! this.props.disabledInfo ) { return null; } return ( { this.props.disabledInfo } ); } renderToggle() { return ( <> { this.props.toggleExtraContent } ); } renderChildren() { return ( { this.props.children } { this.renderLabel() } ); } renderInner() { if ( 0 < Children.count( this.props.children ) ) { return this.renderChildren(); } return this.renderToggle(); } render() { const additionalClasses = { 'is-disabled': this.props.disabled, 'has-disabled-info': !! this.props.disabledInfo, }; return (
{ this.renderInner() }
); } } export default PluginAction;