/** * External dependencies */ import { isFunction } from 'lodash'; import classnames from 'classnames'; import { BaseControl, ButtonGroup, Button } from '@wordpress/components'; /** * WordPress dependencies */ import { Component } from '@wordpress/element'; import { withInstanceId } from '@wordpress/compose'; /** * Internal dependencies */ import './style.scss'; class ToggleButtonControl extends Component { constructor() { super( ...arguments ); this.onClick = this.onClick.bind( this ); } onClick( event ) { if ( this.props.onChange ) { this.props.onChange( event.target.value ); } } render() { const { label, checked, instanceId, className, help, options, value, } = this.props; const id = `inspector-toggle-button-control-${ instanceId }`; let helpLabel; if ( help ) { helpLabel = isFunction( help ) ? help( checked ) : help; } return ( { options.map( ( option, index ) => { const buttonArgs = {}; // Change button depending on pressed state. if ( value === option.value ) { buttonArgs.isPrimary = true; buttonArgs[ 'aria-pressed' ] = true; } else { buttonArgs.isDefault = true; buttonArgs[ 'aria-pressed' ] = false; } return ( ); } ) } ); } } export default withInstanceId( ToggleButtonControl );