2022-04-04 10:12:20 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Button } from '@wordpress/components';
|
|
|
|
import ChevronUpIcon from 'gridicons/dist/chevron-up';
|
|
|
|
import ChevronDownIcon from 'gridicons/dist/chevron-down';
|
|
|
|
import { useState } from '@wordpress/element';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './Toggle.scss';
|
|
|
|
|
2022-04-04 10:38:07 +00:00
|
|
|
export const Toggle = ( { children, heading, onToggle } ) => {
|
|
|
|
const [ isShow, setIsShow ] = useState( false );
|
|
|
|
const onClick = () => {
|
|
|
|
onToggle( isShow );
|
|
|
|
setIsShow( ! isShow );
|
2022-04-04 10:12:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="toggle">
|
|
|
|
<Button
|
|
|
|
isTertiary
|
2022-04-04 10:38:07 +00:00
|
|
|
onClick={ onClick }
|
|
|
|
aria-expanded={ isShow }
|
2022-04-04 10:12:20 +00:00
|
|
|
frameBorder={ 0 }
|
|
|
|
className="toggle-button"
|
|
|
|
>
|
|
|
|
{ heading }
|
2022-04-04 10:38:07 +00:00
|
|
|
{ isShow ? (
|
2022-04-04 10:12:20 +00:00
|
|
|
<ChevronUpIcon size={ 18 } />
|
|
|
|
) : (
|
|
|
|
<ChevronDownIcon size={ 18 } />
|
|
|
|
) }
|
|
|
|
</Button>
|
2022-04-04 10:38:07 +00:00
|
|
|
{ isShow ? children : null }
|
2022-04-04 10:12:20 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|