docbrown/app/javascript/article-form/components/ClipboardButton.jsx
ludwiczakpawel ea28093bbb
Implementing new buttons (#15843)
* buttons

* view archive link block

* revert font weight change

* save draft title

* revert

* fix

* specs

* specs

* spec

* spec

* for fcks  sake

* Change spec for unarchive/archive button from .find to .findByRole

* fix help icon

* improve a11y on close.jsx

* bring back the focus

* .

* Update cypress/integration/seededFlows/publishingFlows/uploadImage.spec.js

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>

* drop icons.jsx

Co-authored-by: Nick Taylor <nick@dev.to>
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
2022-01-14 10:28:31 +01:00

48 lines
1.3 KiB
JavaScript

import { h } from 'preact';
import PropTypes from 'prop-types';
import { ButtonNew as Button } from '@crayons';
import CopyIcon from '@images/copy.svg';
function linksToMarkdownForm(imageLinks) {
return imageLinks
.map((imageLink) => `![Image description](${imageLink})`)
.join('\n');
}
export const ClipboardButton = ({
onCopy,
imageUrls,
showCopyMessage = false,
}) => (
<clipboard-copy
onClick={onCopy}
for="image-markdown-copy-link-input"
aria-live="polite"
className="flex items-center flex-1"
aria-controls="image-markdown-copy-link-announcer"
>
<input
data-testid="markdown-copy-link"
type="text"
className="crayons-textfield mr-2"
id="image-markdown-copy-link-input"
readOnly="true"
value={linksToMarkdownForm(imageUrls)}
/>
<Button
className="spec__image-markdown-copy whitespace-nowrap fw-normal"
icon={CopyIcon}
title="Copy markdown for image"
>
{showCopyMessage ? 'Copied!' : 'Copy...'}
</Button>
</clipboard-copy>
);
ClipboardButton.displayName = 'ClipboardButton';
ClipboardButton.propTypes = {
onCopy: PropTypes.func.isRequired,
imageUrls: PropTypes.arrayOf(PropTypes.string).isRequired,
showCopyMessage: PropTypes.bool.isRequired,
};