2023-02-06 11:28:18 -08:00
|
|
|
import clsx from 'clsx';
|
2022-01-10 14:17:52 -08:00
|
|
|
import React from 'react';
|
2022-03-21 11:09:01 -07:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2022-06-07 09:25:53 -07:00
|
|
|
import { spring } from 'react-motion';
|
|
|
|
|
|
|
|
import Icon from 'soapbox/components/icon';
|
2023-02-06 09:18:49 -08:00
|
|
|
import { HStack } from 'soapbox/components/ui';
|
|
|
|
import ReplyIndicator from 'soapbox/features/compose/components/reply-indicator';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-11-16 06:04:40 -08:00
|
|
|
import Motion from '../../util/optional-motion';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-11-15 06:10:14 -08:00
|
|
|
import type { Menu, MenuItem } from 'soapbox/components/dropdown-menu';
|
2022-06-07 09:25:53 -07:00
|
|
|
import type { Status as StatusEntity } from 'soapbox/types/entities';
|
|
|
|
|
|
|
|
interface IActionsModal {
|
2023-02-15 13:26:27 -08:00
|
|
|
status: StatusEntity
|
|
|
|
actions: Menu
|
|
|
|
onClick: () => void
|
|
|
|
onClose: () => void
|
2022-06-07 09:25:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const ActionsModal: React.FC<IActionsModal> = ({ status, actions, onClick, onClose }) => {
|
|
|
|
const renderAction = (action: MenuItem | null, i: number) => {
|
2020-03-27 13:59:38 -07:00
|
|
|
if (action === null) {
|
|
|
|
return <li key={`sep-${i}`} className='dropdown-menu__separator' />;
|
|
|
|
}
|
|
|
|
|
2023-02-09 09:42:46 -08:00
|
|
|
const { icon = null, text, meta = null, active = false, href = '#', destructive } = action;
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
const Comp = href === '#' ? 'button' : 'a';
|
2022-11-25 09:04:11 -08:00
|
|
|
const compProps = href === '#' ? { onClick: onClick } : { href: href, rel: 'noopener' };
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2020-03-27 13:59:38 -07:00
|
|
|
return (
|
|
|
|
<li key={`${text}-${i}`}>
|
2022-11-25 09:04:11 -08:00
|
|
|
<HStack
|
2022-03-21 11:09:01 -07:00
|
|
|
{...compProps}
|
2022-11-25 10:28:43 -08:00
|
|
|
space={2.5}
|
2020-03-27 13:59:38 -07:00
|
|
|
data-index={i}
|
2023-02-06 11:28:18 -08:00
|
|
|
className={clsx('w-full', { active, destructive })}
|
2022-11-25 09:04:11 -08:00
|
|
|
element={Comp}
|
2020-03-27 13:59:38 -07:00
|
|
|
>
|
2022-11-10 08:01:41 -08:00
|
|
|
{icon && <Icon title={text} src={icon} role='presentation' tabIndex={-1} />}
|
2020-03-27 13:59:38 -07:00
|
|
|
<div>
|
2023-02-06 11:28:18 -08:00
|
|
|
<div className={clsx({ 'actions-modal__item-label': !!meta })}>{text}</div>
|
2020-03-27 13:59:38 -07:00
|
|
|
<div>{meta}</div>
|
|
|
|
</div>
|
2022-11-25 09:04:11 -08:00
|
|
|
</HStack>
|
2020-03-27 13:59:38 -07:00
|
|
|
</li>
|
|
|
|
);
|
2022-03-21 11:09:01 -07:00
|
|
|
};
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
return (
|
|
|
|
<Motion defaultStyle={{ top: 100 }} style={{ top: spring(0) }}>
|
|
|
|
{({ top }) => (
|
|
|
|
<div className='modal-root__modal actions-modal' style={{ top: `${top}%` }}>
|
|
|
|
{status && (
|
2023-02-06 09:18:49 -08:00
|
|
|
<ReplyIndicator className='actions-modal__status rounded-b-none' status={status} hideActions />
|
2022-03-21 11:09:01 -07:00
|
|
|
)}
|
2021-11-04 08:37:16 -07:00
|
|
|
|
2023-02-06 11:28:18 -08:00
|
|
|
<ul className={clsx({ 'with-status': !!status })}>
|
2022-03-21 11:09:01 -07:00
|
|
|
{actions && actions.map(renderAction)}
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
<li className='dropdown-menu__separator' />
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
<li>
|
|
|
|
<button type='button' onClick={onClose}>
|
|
|
|
<FormattedMessage id='lightbox.close' defaultMessage='Cancel' />
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2020-03-27 13:59:38 -07:00
|
|
|
</div>
|
2022-03-21 11:09:01 -07:00
|
|
|
)}
|
|
|
|
</Motion>
|
|
|
|
);
|
|
|
|
};
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
export default ActionsModal;
|