Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract permalink panel to own component #806

Merged
merged 1 commit into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
border-radius: 2px;
padding: 0 5px;
}

.permalink input:focus {
outline: none !important;
border: 1px solid var(--headerColor);
}
58 changes: 58 additions & 0 deletions src/component/Permalink/Permalink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';

import Button from 'antd/lib/button';
import { message } from 'antd';

import copy from 'copy-to-clipboard';

import './Permalink.css';

interface PermalinkProps {
t: (arg: string) => string;
getLink: () => string;
}

/**
* Function component for permalink panel.
*/
export const Permalink: React.FC<PermalinkProps> = ({
t,
getLink
}): JSX.Element => {

/**
* Copy the permalink to clipboard
*/
const copyToClipBoard = () => {
const linkInput: HTMLInputElement = document.querySelector('.permalink input');
if (linkInput) {
const success = copy(linkInput.value);
if (success) {
message.info(t('Permalink.copiedToClipboard'));
} else {
message.info(t('Permalink.copyToClipboardFailed'));
}
}
};

return (
<div className="permalink">
<label htmlFor="permalink">
{t('Permalink.label')}:
</label>
<input
readOnly
id="permalink"
type="text"
value={getLink()}
/>
<Button
onClick={copyToClipBoard}
>
{t('Permalink.copy')}
</Button>
</div>
);
};

export default Permalink;
47 changes: 6 additions & 41 deletions src/component/button/PermalinkButton/PermalinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import React, { useState } from 'react';
import SimpleButton, { SimpleButtonProps } from '@terrestris/react-geo/dist/Button/SimpleButton/SimpleButton';
import Window from '@terrestris/react-geo/dist/Window/Window';

import Button, { ButtonProps } from 'antd/lib/button';
import { message } from 'antd';
import { ButtonProps } from 'antd/lib/button';

import PermalinkUtil from '@terrestris/ol-util/dist/PermalinkUtil/PermalinkUtil';

import copy from 'copy-to-clipboard';

import './PermalinkButton.css';
import Permalink from '../../Permalink/Permalink';

interface DefaultPermalinkButtonProps extends SimpleButtonProps {
shape: 'circle' | 'round';
Expand Down Expand Up @@ -44,22 +41,6 @@ export const PermalinkButton: React.FC<PermalinkButtonProps> = ({

const [winVisible, setWinVisible] = useState(false);

/**
* Copy the permalink to clipboard
*/
const copyToClipBoard = () => {
const linkInput: HTMLInputElement = document.querySelector(
'.permalink input');
if (linkInput) {
const success = copy(linkInput.value);
if (success) {
message.info(t('Permalink.copiedToClipboard'));
} else {
message.info(t('Permalink.copyToClipboardFailed'));
}
}
};

return (
<>
<SimpleButton
Expand Down Expand Up @@ -91,26 +72,10 @@ export const PermalinkButton: React.FC<PermalinkButtonProps> = ({
/>
]}
>
<div
className="permalink"
>
<label
htmlFor="permalink"
>
{t('Permalink.label')}:
</label>
<input
readOnly
id="permalink"
type="text"
value={getLink ? getLink() : PermalinkUtil.getLink(map)}
/>
<Button
onClick={copyToClipBoard}
>
{t('Permalink.copy')}
</Button>
</div>
<Permalink
getLink={getLink ? getLink : PermalinkUtil.getLink(map)}
t={t}
/>
</Window>
}
</>
Expand Down