2022-11-10 07:49:35 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2022-11-10 07:49:35 +00:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2024-01-16 10:27:26 +00:00
|
|
|
import CloseIcon from '@/material-icons/400-24px/close.svg?react';
|
2023-05-09 01:11:56 +00:00
|
|
|
import { IconButton } from 'mastodon/components/icon_button';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
2022-11-10 07:49:35 +00:00
|
|
|
import ImageLoader from './image_loader';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
close: { id: 'lightbox.close', defaultMessage: 'Close' },
|
|
|
|
});
|
|
|
|
|
2023-05-23 08:52:27 +00:00
|
|
|
class ImageModal extends PureComponent {
|
2022-11-10 07:49:35 +00:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
src: PropTypes.string.isRequired,
|
|
|
|
alt: PropTypes.string.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
navigationHidden: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
toggleNavigation = () => {
|
|
|
|
this.setState(prevState => ({
|
|
|
|
navigationHidden: !prevState.navigationHidden,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { intl, src, alt, onClose } = this.props;
|
|
|
|
const { navigationHidden } = this.state;
|
|
|
|
|
|
|
|
const navigationClassName = classNames('media-modal__navigation', {
|
|
|
|
'media-modal__navigation--hidden': navigationHidden,
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='modal-root__modal media-modal'>
|
|
|
|
<div className='media-modal__closer' role='presentation' onClick={onClose} >
|
|
|
|
<ImageLoader
|
|
|
|
src={src}
|
|
|
|
width={400}
|
|
|
|
height={400}
|
|
|
|
alt={alt}
|
|
|
|
onClick={this.toggleNavigation}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={navigationClassName}>
|
2023-10-24 17:45:08 +00:00
|
|
|
<IconButton className='media-modal__close' title={intl.formatMessage(messages.close)} icon='times' iconComponent={CloseIcon} onClick={onClose} size={40} />
|
2022-11-10 07:49:35 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 02:17:53 +00:00
|
|
|
|
|
|
|
export default injectIntl(ImageModal);
|