2018-06-29 00:34:17 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Button } from '@wordpress/components';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* A button useful for a launcher of a dropdown component. The button is 100% width of its container and displays
|
|
|
|
* single or multiple lines rendered as `<span/>` elments.
|
|
|
|
*
|
|
|
|
* @param { object } props Props passed to component.
|
|
|
|
* @return { object } -
|
|
|
|
*/
|
2018-06-29 00:34:17 +00:00
|
|
|
const DropdownButton = props => {
|
|
|
|
const { labels, isOpen, ...otherProps } = props;
|
|
|
|
const buttonClasses = classnames( 'woocommerce-dropdown-button', {
|
|
|
|
'is-open': isOpen,
|
|
|
|
'is-multi-line': labels.length > 1,
|
|
|
|
} );
|
|
|
|
return (
|
|
|
|
<Button className={ buttonClasses } aria-expanded={ isOpen } { ...otherProps }>
|
|
|
|
<div className="woocommerce-dropdown-button__labels">
|
2018-07-09 20:36:12 +00:00
|
|
|
{ labels.map( ( label, i ) => <span key={ i }>{ label }</span> ) }
|
2018-06-29 00:34:17 +00:00
|
|
|
</div>
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
DropdownButton.propTypes = {
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* An array of elements to be rendered as the content of the button.
|
|
|
|
*/
|
2018-06-29 00:34:17 +00:00
|
|
|
labels: PropTypes.array,
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* Boolean describing if the dropdown in open or not.
|
|
|
|
*/
|
2018-06-29 00:34:17 +00:00
|
|
|
isOpen: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DropdownButton;
|