mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 17:49:09 +00:00
feat(editor): add permalink section in editor
This commit is contained in:
parent
f86eaae5e9
commit
0d96a4f973
11 changed files with 125 additions and 2 deletions
47
packages/design-system/atoms/copy-area/CopyArea.tsx
Normal file
47
packages/design-system/atoms/copy-area/CopyArea.tsx
Normal file
|
@ -0,0 +1,47 @@
|
|||
import React from 'react';
|
||||
import ReactTooltip from 'react-tooltip';
|
||||
import { CopyAreaStyled, CopyAreaTextInput } from './CopyArea.styled';
|
||||
|
||||
type CopyAreaProps = {
|
||||
value: string;
|
||||
};
|
||||
|
||||
enum CopyState {
|
||||
NotCopied = 0,
|
||||
Copied = 1,
|
||||
}
|
||||
|
||||
export const CopyArea = (props: CopyAreaProps) => {
|
||||
const [copied, setCopied] = React.useState<CopyState>(CopyState.NotCopied);
|
||||
|
||||
const inputRef = React.useRef<HTMLInputElement>(null);
|
||||
|
||||
const handleClick = () => {
|
||||
inputRef.current?.setSelectionRange(0, 99999);
|
||||
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(props.value);
|
||||
setCopied(CopyState.Copied);
|
||||
}
|
||||
};
|
||||
|
||||
const strings = {
|
||||
[CopyState.NotCopied]: `Press ⌘/Ctrl+C to copy`,
|
||||
[CopyState.Copied]: 'Copied to clipboard!',
|
||||
};
|
||||
|
||||
return (
|
||||
<CopyAreaStyled>
|
||||
<CopyAreaTextInput
|
||||
ref={inputRef}
|
||||
value={props.value}
|
||||
onClick={handleClick}
|
||||
onBlur={() => setCopied(CopyState.NotCopied)}
|
||||
copied={copied === CopyState.Copied}
|
||||
data-tip={strings[copied]}
|
||||
data-for={'copy-area'}
|
||||
/>
|
||||
<ReactTooltip id="copy-area" />
|
||||
</CopyAreaStyled>
|
||||
);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue