bigbuffet-rw/app/soapbox/features/ui/components/actions_modal.js

84 lines
2.7 KiB
JavaScript
Raw Normal View History

import classNames from 'classnames';
2020-03-27 13:59:38 -07:00
import PropTypes from 'prop-types';
import React from 'react';
2020-03-27 13:59:38 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes';
2022-03-21 11:09:01 -07:00
import { FormattedMessage } from 'react-intl';
import spring from 'react-motion/lib/spring';
import Icon from '../../../components/icon';
import StatusContent from '../../../components/status_content';
2022-03-21 11:09:01 -07:00
import { Stack } from '../../../components/ui';
import AccountContainer from '../../../containers/account_container';
import Motion from '../util/optional_motion';
2020-03-27 13:59:38 -07:00
2022-03-21 11:09:01 -07:00
const ActionsModal = ({ status, actions, onClick, onClose }) => {
const renderAction = (action, i) => {
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 = '#', isLogout, 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 };
2020-03-27 13:59:38 -07:00
return (
<li key={`${text}-${i}`}>
2022-03-21 11:09:01 -07:00
<Comp
{...compProps}
2020-03-27 13:59:38 -07:00
rel='noopener'
data-index={i}
className={classNames({ active, destructive })}
2020-03-27 13:59:38 -07:00
data-method={isLogout ? 'delete' : null}
>
{icon && <Icon title={text} src={icon} role='presentation' tabIndex='-1' inverted />}
2020-03-27 13:59:38 -07:00
<div>
<div className={classNames({ 'actions-modal__item-label': !!meta })}>{text}</div>
<div>{meta}</div>
</div>
2022-03-21 11:09:01 -07:00
</Comp>
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 && (
<Stack space={2} className='p-4 bg-gray-50 dark:bg-slate-800 border-b border-solid border-gray-200 dark:border-gray-700'>
2022-03-21 11:09:01 -07:00
<AccountContainer
account={status.get('account')}
showProfileHoverCard={false}
timestamp={status.get('created_at')}
/>
<StatusContent status={status} />
</Stack>
)}
2022-03-21 11:09:01 -07:00
<ul className={classNames({ 'with-status': !!status })}>
{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
ActionsModal.propTypes = {
2022-03-23 10:14:42 -07:00
status: ImmutablePropTypes.record,
2022-03-21 11:09:01 -07:00
actions: PropTypes.array,
onClick: PropTypes.func,
onClose: PropTypes.func.isRequired,
};
2020-03-27 13:59:38 -07:00
2022-03-21 11:09:01 -07:00
export default ActionsModal;