2019-04-09 04:32:25 +00:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { gettext } from '../../utils/constants';
|
|
|
|
|
2020-01-14 05:40:59 +00:00
|
|
|
import Lightbox from '@seafile/react-image-lightbox';
|
|
|
|
import '@seafile/react-image-lightbox/style.css';
|
2019-04-09 04:32:25 +00:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
imageItems: PropTypes.array.isRequired,
|
|
|
|
imageIndex: PropTypes.number.isRequired,
|
|
|
|
closeImagePopup: PropTypes.func.isRequired,
|
|
|
|
moveToPrevImage: PropTypes.func.isRequired,
|
|
|
|
moveToNextImage: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
class ImageDialog extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const imageItems = this.props.imageItems;
|
|
|
|
const imageIndex = this.props.imageIndex;
|
|
|
|
const imageItemsLength = imageItems.length;
|
2022-12-31 11:38:51 +00:00
|
|
|
const name = imageItems[imageIndex].name;
|
|
|
|
const imageTitle = `${name} (${imageIndex + 1}/${imageItemsLength})`;
|
2019-04-09 04:32:25 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Lightbox
|
2022-12-31 11:38:51 +00:00
|
|
|
imageTitle={imageTitle}
|
2019-04-09 04:32:25 +00:00
|
|
|
mainSrc={imageItems[imageIndex].src}
|
|
|
|
nextSrc={imageItems[(imageIndex + 1) % imageItemsLength].src}
|
|
|
|
prevSrc={imageItems[(imageIndex + imageItemsLength - 1) % imageItemsLength].src}
|
|
|
|
onCloseRequest={this.props.closeImagePopup}
|
|
|
|
onMovePrevRequest={this.props.moveToPrevImage}
|
|
|
|
onMoveNextRequest={this.props.moveToNextImage}
|
|
|
|
imagePadding={70}
|
|
|
|
imageLoadErrorMessage={gettext('The image could not be loaded.')}
|
|
|
|
prevLabel={gettext('Previous (Left arrow key)')}
|
|
|
|
nextLabel={gettext('Next (Right arrow key)')}
|
|
|
|
closeLabel={gettext('Close (Esc)')}
|
|
|
|
zoomInLabel={gettext('Zoom in')}
|
|
|
|
zoomOutLabel={gettext('Zoom out')}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageDialog.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default ImageDialog;
|