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

Commit dbe4241

Browse files
committed
feat(hyperlink modal): added message for successful copy of a link url
Signed-off-by: Nikhil <[email protected]>
1 parent 0ea33d2 commit dbe4241

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/RichTextEditor/FormattingToolbar/HyperlinkModal.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ const InlineFormButton = styled.button`
9898
}
9999
`;
100100

101+
const LinkCopiedMessage = styled.div`
102+
color: green;
103+
margin-bottom: 2%;
104+
`;
105+
101106
const popupStyles = {
102107
padding: '0.2em 0.5em 0.2em 0.5em',
103108
zIndex: '9999'
@@ -114,6 +119,7 @@ const HyperlinkModal = React.forwardRef(({ ...props }, ref) => {
114119
const editor = useEditor();
115120
const [originalSelection, setOriginalSelection] = useState(null);
116121
const [canApply, setApplyStatus] = useState(false);
122+
const [linkCopied, setLinkCopied] = useState(false);
117123

118124
const handleClick = useCallback((e) => {
119125
if (ref.current && !ref.current.contains(e.target)) {
@@ -186,8 +192,10 @@ const HyperlinkModal = React.forwardRef(({ ...props }, ref) => {
186192
const copyLink = () => {
187193
const inputLink = refHyperlinkTextInput.current.inputRef.current.value;
188194
const listener = (e) => {
189-
e.clipboardData.setData('text/plain', inputLink);
195+
e.clipboardData.setData('text/plain', validateUrl(inputLink));
190196
e.preventDefault();
197+
setLinkCopied(true);
198+
Transforms.select(editor, originalSelection);
191199
};
192200

193201
document.addEventListener('copy', listener);
@@ -231,6 +239,7 @@ const HyperlinkModal = React.forwardRef(({ ...props }, ref) => {
231239
Apply
232240
</InlineFormButton>
233241
</InlineFormField>
242+
{linkCopied && <LinkCopiedMessage>Link copied</LinkCopiedMessage>}
234243
<InlineFormField>
235244
<Popup
236245
trigger={

0 commit comments

Comments
 (0)