2020-06-05 10:00:19 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useState } from '@wordpress/element';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { Icon, chevronUp, chevronDown } from '@woocommerce/icons';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
const Panel = ( {
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
initialOpen = false,
|
2020-06-12 12:07:02 +00:00
|
|
|
hasBorder = false,
|
2020-06-05 10:00:19 +00:00
|
|
|
title,
|
|
|
|
titleTag: TitleTag = 'div',
|
|
|
|
} ) => {
|
|
|
|
const [ isOpen, setIsOpen ] = useState( initialOpen );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2020-06-12 12:07:02 +00:00
|
|
|
className={ classNames( className, 'wc-blocks-components-panel', {
|
|
|
|
'has-border': hasBorder,
|
|
|
|
} ) }
|
2020-06-05 10:00:19 +00:00
|
|
|
>
|
|
|
|
<TitleTag>
|
|
|
|
<button
|
|
|
|
aria-expanded={ isOpen }
|
|
|
|
className="wc-blocks-components-panel__button"
|
|
|
|
onClick={ () => setIsOpen( ! isOpen ) }
|
|
|
|
>
|
|
|
|
<Icon
|
|
|
|
aria-hidden="true"
|
|
|
|
className="wc-blocks-components-panel__button-icon"
|
|
|
|
srcElement={ isOpen ? chevronUp : chevronDown }
|
|
|
|
/>
|
|
|
|
{ title }
|
|
|
|
</button>
|
|
|
|
</TitleTag>
|
|
|
|
<div
|
|
|
|
className="wc-blocks-components-panel__content"
|
|
|
|
hidden={ ! isOpen }
|
|
|
|
>
|
|
|
|
{ children }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Panel.propTypes = {
|
|
|
|
className: PropTypes.string,
|
2020-06-12 12:07:02 +00:00
|
|
|
hasBorder: PropTypes.bool,
|
2020-06-05 10:00:19 +00:00
|
|
|
initialOpen: PropTypes.bool,
|
|
|
|
title: PropTypes.element,
|
|
|
|
titleTag: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Panel;
|