Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
feat(hyperlink modal): added message for successful copy of a link url
Browse files Browse the repository at this point in the history
Signed-off-by: Nikhil <[email protected]>
  • Loading branch information
nik72619c committed May 1, 2020
1 parent b28b89c commit 3c55902
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/RichTextEditor/FormattingToolbar/HyperlinkModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ const InlineFormButton = styled.button`
}
`;

const LinkCopiedMessage = styled.div`
color: green;
margin-bottom: 2%;
`;

const popupStyles = {
padding: '0.2em 0.5em 0.2em 0.5em',
zIndex: '9999'
Expand All @@ -114,6 +119,7 @@ const HyperlinkModal = React.forwardRef(({ ...props }, ref) => {
const editor = useEditor();
const [originalSelection, setOriginalSelection] = useState(null);
const [canApply, setApplyStatus] = useState(false);
const [linkCopied, setLinkCopied] = useState(false);

const handleClick = useCallback((e) => {
if (ref.current && !ref.current.contains(e.target)) {
Expand Down Expand Up @@ -189,8 +195,10 @@ const HyperlinkModal = React.forwardRef(({ ...props }, ref) => {
const copyLink = () => {
const inputLink = refHyperlinkTextInput.current.inputRef.current.value;
const listener = (e) => {
e.clipboardData.setData('text/plain', inputLink);
e.clipboardData.setData('text/plain', validateUrl(inputLink));
e.preventDefault();
setLinkCopied(true);
Transforms.select(editor, originalSelection);
};

document.addEventListener('copy', listener);
Expand Down Expand Up @@ -234,6 +242,7 @@ const HyperlinkModal = React.forwardRef(({ ...props }, ref) => {
Apply
</InlineFormButton>
</InlineFormField>
{linkCopied && <LinkCopiedMessage>Link copied</LinkCopiedMessage>}
<InlineFormField>
<Popup
trigger={
Expand Down

0 comments on commit 3c55902

Please sign in to comment.