2022-08-31 02:35:06 -07:00
|
|
|
import classNames from 'clsx';
|
2022-04-10 03:46:25 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
|
2022-04-24 16:54:46 -07:00
|
|
|
import { Text } from 'soapbox/components/ui';
|
2022-04-10 03:46:25 -07:00
|
|
|
import DropdownMenu from 'soapbox/containers/dropdown_menu_container';
|
|
|
|
|
2022-11-15 06:10:14 -08:00
|
|
|
import type { Menu } from 'soapbox/components/dropdown-menu';
|
2022-04-10 03:46:25 -07:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
collapse: { id: 'accordion.collapse', defaultMessage: 'Collapse' },
|
|
|
|
expand: { id: 'accordion.expand', defaultMessage: 'Expand' },
|
|
|
|
});
|
|
|
|
|
|
|
|
interface IAccordion {
|
|
|
|
headline: React.ReactNode,
|
2022-05-24 08:16:07 -07:00
|
|
|
children?: React.ReactNode,
|
2022-04-10 03:46:25 -07:00
|
|
|
menu?: Menu,
|
|
|
|
expanded?: boolean,
|
|
|
|
onToggle?: (value: boolean) => void,
|
|
|
|
}
|
|
|
|
|
|
|
|
const Accordion: React.FC<IAccordion> = ({ headline, children, menu, expanded = false, onToggle = () => {} }) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
const handleToggle = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
onToggle(!expanded);
|
|
|
|
e.preventDefault();
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classNames('accordion', { 'accordion--expanded': expanded })}>
|
|
|
|
{menu && (
|
|
|
|
<div className='accordion__menu'>
|
2022-07-09 09:20:02 -07:00
|
|
|
<DropdownMenu items={menu} src={require('@tabler/icons/dots-vertical.svg')} />
|
2022-04-10 03:46:25 -07:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<button
|
|
|
|
type='button'
|
|
|
|
className='accordion__title'
|
|
|
|
onClick={handleToggle}
|
|
|
|
title={intl.formatMessage(expanded ? messages.collapse : messages.expand)}
|
|
|
|
>
|
2022-04-24 16:54:46 -07:00
|
|
|
<Text weight='bold'>{headline}</Text>
|
2022-04-10 03:46:25 -07:00
|
|
|
</button>
|
|
|
|
<div className='accordion__content'>
|
2022-04-24 16:54:46 -07:00
|
|
|
<Text>{children}</Text>
|
2022-04-10 03:46:25 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Accordion;
|