bigbuffet-rw/app/soapbox/features/ui/components/modals/actions-modal.tsx

78 lines
2.4 KiB
TypeScript
Raw Normal View History

import clsx from 'clsx';
import React from 'react';
2022-03-21 11:09:01 -07:00
import { FormattedMessage } from 'react-intl';
import { spring } from 'react-motion';
import Icon from 'soapbox/components/icon';
import { HStack } from 'soapbox/components/ui';
import ReplyIndicator from 'soapbox/features/compose/components/reply-indicator';
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';
import type { Status as StatusEntity } from 'soapbox/types/entities';
interface IActionsModal {
status: StatusEntity
actions: Menu
onClick: () => void
onClose: () => void
}
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' />;
}
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';
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}`}>
<HStack
2022-03-21 11:09:01 -07:00
{...compProps}
space={2.5}
2020-03-27 13:59:38 -07:00
data-index={i}
className={clsx('w-full', { active, destructive })}
element={Comp}
2020-03-27 13:59:38 -07:00
>
{icon && <Icon title={text} src={icon} role='presentation' tabIndex={-1} />}
2020-03-27 13:59:38 -07:00
<div>
<div className={clsx({ 'actions-modal__item-label': !!meta })}>{text}</div>
2020-03-27 13:59:38 -07:00
<div>{meta}</div>
</div>
</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 && (
<ReplyIndicator className='actions-modal__status rounded-b-none' status={status} hideActions />
2022-03-21 11:09:01 -07: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;