Added QrCode modal window to short URLs

This commit is contained in:
Alejandro Celaya 2018-07-27 18:05:09 +02:00
parent a78d0b9b20
commit 131099b2a6
4 changed files with 31 additions and 2 deletions

View file

@ -8,6 +8,9 @@
white-space: nowrap; white-space: nowrap;
} }
.dropdown-item {
cursor: pointer;
}
.dropdown-item.active { .dropdown-item.active {
background-color: $mainColor !important; background-color: $mainColor !important;
} }

View file

@ -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 QrCodeModal from './helpers/QrCodeModal';
import { listShortUrls } from './reducers/shortUrlsList'; import { listShortUrls } from './reducers/shortUrlsList';
import './ShortUrlsList.scss'; import './ShortUrlsList.scss';
@ -174,13 +175,14 @@ class Row extends React.Component {
} }
class RowMenu extends React.Component { class RowMenu extends React.Component {
state = { isOpen: false }; state = { isOpen: false, isQrModalOpen: false };
toggle = () => this.setState({ isOpen: ! this.state.isOpen }); toggle = () => this.setState({ isOpen: ! this.state.isOpen });
render () { render () {
const { display, shortUrl, onCopyToClipboard } = this.props; const { display, shortUrl, onCopyToClipboard } = this.props;
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 });
return ( return (
<ButtonDropdown toggle={this.toggle} isOpen={this.state.isOpen} direction="left"> <ButtonDropdown toggle={this.toggle} isOpen={this.state.isOpen} direction="left">
@ -195,9 +197,14 @@ class RowMenu extends React.Component {
<DropdownItem> <DropdownItem>
<FontAwesomeIcon icon={pictureIcon} /> &nbsp;Preview <FontAwesomeIcon icon={pictureIcon} /> &nbsp;Preview
</DropdownItem> </DropdownItem>
<DropdownItem> <DropdownItem onClick={toggleQrCode}>
<FontAwesomeIcon icon={qrIcon} /> &nbsp;QR code <FontAwesomeIcon icon={qrIcon} /> &nbsp;QR code
</DropdownItem> </DropdownItem>
<QrCodeModal
url={shortUrl}
isOpen={this.state.isQrModalOpen}
toggle={toggleQrCode}
/>
<DropdownItem divider /> <DropdownItem divider />
<CopyToClipboard text={shortUrl} onCopy={onCopyToClipboard}> <CopyToClipboard text={shortUrl} onCopy={onCopyToClipboard}>
<DropdownItem> <DropdownItem>

View file

@ -0,0 +1,16 @@
import React from 'react'
import { Modal, ModalBody, ModalHeader } from 'reactstrap';
import './QrCodeModal.scss';
export default function QrCodeModal ({ url, toggle, isOpen }) {
return (
<Modal isOpen={isOpen} toggle={toggle} centered={true}>
<ModalHeader toggle={toggle}>QR code for <a target="_blank" href={url}>{url}</a></ModalHeader>
<ModalBody>
<div className="text-center">
<img src={`${url}/qr-code`} className="qr-code-modal__img" />
</div>
</ModalBody>
</Modal>
);
}

View file

@ -0,0 +1,3 @@
.qr-code-modal__img {
max-width: 100%;
}