2022-09-14 07:43:30 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useState } from '@wordpress/element';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
CardBody,
|
|
|
|
CardDivider,
|
|
|
|
CardHeader,
|
|
|
|
CardFooter,
|
|
|
|
Button,
|
|
|
|
} from '@wordpress/components';
|
|
|
|
import { chevronUp, chevronDown } from '@wordpress/icons';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-12-09 11:30:24 +00:00
|
|
|
import { CardHeaderTitle } from '~/marketing/components';
|
2022-09-14 07:43:30 +00:00
|
|
|
import './CollapsibleCard.scss';
|
|
|
|
|
|
|
|
type CollapsibleCardProps = {
|
|
|
|
header: string;
|
|
|
|
children: React.ReactNode;
|
|
|
|
className?: string;
|
|
|
|
footer?: React.ReactNode;
|
|
|
|
initialCollapsed?: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
const CollapsibleCard: React.FC< CollapsibleCardProps > = ( {
|
|
|
|
header,
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
footer,
|
|
|
|
initialCollapsed = false,
|
|
|
|
} ) => {
|
|
|
|
const [ collapsed, setCollapsed ] = useState( initialCollapsed );
|
|
|
|
|
|
|
|
const handleClick = () => {
|
|
|
|
setCollapsed( ! collapsed );
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card
|
|
|
|
className={ classnames(
|
|
|
|
'woocommerce-collapsible-card',
|
|
|
|
className
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<CardHeader onClick={ handleClick }>
|
2022-12-09 11:30:24 +00:00
|
|
|
<CardHeaderTitle>{ header }</CardHeaderTitle>
|
2022-09-14 07:43:30 +00:00
|
|
|
<Button
|
|
|
|
isSmall
|
|
|
|
icon={ collapsed ? chevronDown : chevronUp }
|
|
|
|
label={
|
|
|
|
collapsed
|
|
|
|
? __( 'Expand', 'woocommerce' )
|
|
|
|
: __( 'Collapse', 'woocommerce' )
|
|
|
|
}
|
|
|
|
onClick={ handleClick }
|
|
|
|
/>
|
|
|
|
</CardHeader>
|
|
|
|
{ ! collapsed && (
|
|
|
|
<>
|
|
|
|
{ children }
|
2023-03-15 00:24:00 +00:00
|
|
|
{ !! footer && <CardFooter>{ footer }</CardFooter> }
|
2022-09-14 07:43:30 +00:00
|
|
|
</>
|
|
|
|
) }
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export { CollapsibleCard, CardBody, CardDivider };
|