mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-09 09:47:28 +03:00
Added preview modal component
This commit is contained in:
parent
131099b2a6
commit
842b1a7590
4 changed files with 49 additions and 2 deletions
|
@ -13,6 +13,7 @@ import copyIcon from '@fortawesome/fontawesome-free-regular/faCopy';
|
||||||
import menuIcon from '@fortawesome/fontawesome-free-solid/faEllipsisV';
|
import menuIcon from '@fortawesome/fontawesome-free-solid/faEllipsisV';
|
||||||
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
|
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
|
||||||
import Tag from '../utils/Tag';
|
import Tag from '../utils/Tag';
|
||||||
|
import PreviewModal from './helpers/PreviewModal';
|
||||||
import QrCodeModal from './helpers/QrCodeModal';
|
import QrCodeModal from './helpers/QrCodeModal';
|
||||||
import { listShortUrls } from './reducers/shortUrlsList';
|
import { listShortUrls } from './reducers/shortUrlsList';
|
||||||
import './ShortUrlsList.scss';
|
import './ShortUrlsList.scss';
|
||||||
|
@ -175,7 +176,7 @@ class Row extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
class RowMenu extends React.Component {
|
class RowMenu extends React.Component {
|
||||||
state = { isOpen: false, isQrModalOpen: false };
|
state = { isOpen: false, isQrModalOpen: false, isPreviewOpen: false };
|
||||||
toggle = () => this.setState({ isOpen: ! this.state.isOpen });
|
toggle = () => this.setState({ isOpen: ! this.state.isOpen });
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
@ -183,6 +184,7 @@ class RowMenu extends React.Component {
|
||||||
const baseClass = 'short-urls-list__dropdown-toggle';
|
const baseClass = 'short-urls-list__dropdown-toggle';
|
||||||
const toggleClass = ! display ? `${baseClass} short-urls-list__dropdown-toggle--hidden` : baseClass;
|
const toggleClass = ! display ? `${baseClass} short-urls-list__dropdown-toggle--hidden` : baseClass;
|
||||||
const toggleQrCode = () => this.setState({ isQrModalOpen: !this.state.isQrModalOpen });
|
const toggleQrCode = () => this.setState({ isQrModalOpen: !this.state.isQrModalOpen });
|
||||||
|
const togglePreview = () => this.setState({ isPreviewOpen: !this.state.isPreviewOpen });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ButtonDropdown toggle={this.toggle} isOpen={this.state.isOpen} direction="left">
|
<ButtonDropdown toggle={this.toggle} isOpen={this.state.isOpen} direction="left">
|
||||||
|
@ -193,10 +195,18 @@ class RowMenu extends React.Component {
|
||||||
<DropdownItem>
|
<DropdownItem>
|
||||||
<FontAwesomeIcon icon={pieChartIcon} /> Visit Stats
|
<FontAwesomeIcon icon={pieChartIcon} /> Visit Stats
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
|
|
||||||
<DropdownItem divider />
|
<DropdownItem divider />
|
||||||
<DropdownItem>
|
|
||||||
|
<DropdownItem onClick={togglePreview}>
|
||||||
<FontAwesomeIcon icon={pictureIcon} /> Preview
|
<FontAwesomeIcon icon={pictureIcon} /> Preview
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
|
<PreviewModal
|
||||||
|
url={shortUrl}
|
||||||
|
isOpen={this.state.isPreviewOpen}
|
||||||
|
toggle={togglePreview}
|
||||||
|
/>
|
||||||
|
|
||||||
<DropdownItem onClick={toggleQrCode}>
|
<DropdownItem onClick={toggleQrCode}>
|
||||||
<FontAwesomeIcon icon={qrIcon} /> QR code
|
<FontAwesomeIcon icon={qrIcon} /> QR code
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
|
@ -205,7 +215,9 @@ class RowMenu extends React.Component {
|
||||||
isOpen={this.state.isQrModalOpen}
|
isOpen={this.state.isQrModalOpen}
|
||||||
toggle={toggleQrCode}
|
toggle={toggleQrCode}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DropdownItem divider />
|
<DropdownItem divider />
|
||||||
|
|
||||||
<CopyToClipboard text={shortUrl} onCopy={onCopyToClipboard}>
|
<CopyToClipboard text={shortUrl} onCopy={onCopyToClipboard}>
|
||||||
<DropdownItem>
|
<DropdownItem>
|
||||||
<FontAwesomeIcon icon={copyIcon} /> Copy to clipboard
|
<FontAwesomeIcon icon={copyIcon} /> Copy to clipboard
|
||||||
|
|
17
src/short-urls/helpers/PreviewModal.js
Normal file
17
src/short-urls/helpers/PreviewModal.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import React from 'react'
|
||||||
|
import { Modal, ModalBody, ModalHeader } from 'reactstrap';
|
||||||
|
import './PreviewModal.scss';
|
||||||
|
|
||||||
|
export default function PreviewModal ({ url, toggle, isOpen }) {
|
||||||
|
return (
|
||||||
|
<Modal isOpen={isOpen} toggle={toggle} size="lg">
|
||||||
|
<ModalHeader toggle={toggle}>Preview for <a target="_blank" href={url}>{url}</a></ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<div className="text-center">
|
||||||
|
<p className="preview-modal__loader">Loading...</p>
|
||||||
|
<img src={`${url}/preview`} className="preview-modal__img" />
|
||||||
|
</div>
|
||||||
|
</ModalBody>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
13
src/short-urls/helpers/PreviewModal.scss
Normal file
13
src/short-urls/helpers/PreviewModal.scss
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
@import "../../utils/mixins/horizontal-align";
|
||||||
|
|
||||||
|
.preview-modal__img {
|
||||||
|
max-width: 100%;
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-modal__loader {
|
||||||
|
@include horizontal-align();
|
||||||
|
z-index: 1;
|
||||||
|
top: 1rem;
|
||||||
|
}
|
5
src/utils/mixins/horizontal-align.scss
Normal file
5
src/utils/mixins/horizontal-align.scss
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
@mixin horizontal-align {
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
Loading…
Reference in a new issue