refactor: support copied text different from presented text
This commit is contained in:
parent
f8a82bb84b
commit
951cd9cfa1
1 changed files with 8 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ const CopyToClipboard = ({
|
||||||
className,
|
className,
|
||||||
buttonClassname,
|
buttonClassname,
|
||||||
children,
|
children,
|
||||||
|
value,
|
||||||
wrapperClassname,
|
wrapperClassname,
|
||||||
removeSpace = true,
|
removeSpace = true,
|
||||||
}) => {
|
}) => {
|
||||||
|
|
@ -33,6 +34,12 @@ const CopyToClipboard = ({
|
||||||
const open = Boolean(anchorEl)
|
const open = Boolean(anchorEl)
|
||||||
const id = open ? 'simple-popper' : undefined
|
const id = open ? 'simple-popper' : undefined
|
||||||
|
|
||||||
|
const text = value
|
||||||
|
? value
|
||||||
|
: removeSpace
|
||||||
|
? R.replace(/\s/g, '')(children)
|
||||||
|
: children
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classnames('flex items-center', wrapperClassname)}>
|
<div className={classnames('flex items-center', wrapperClassname)}>
|
||||||
{children && (
|
{children && (
|
||||||
|
|
@ -43,8 +50,7 @@ const CopyToClipboard = ({
|
||||||
{children}
|
{children}
|
||||||
</Mono>
|
</Mono>
|
||||||
<div className={buttonClassname}>
|
<div className={buttonClassname}>
|
||||||
<ReactCopyToClipboard
|
<ReactCopyToClipboard text={text}>
|
||||||
text={removeSpace ? R.replace(/\s/g, '')(children) : children}>
|
|
||||||
<button
|
<button
|
||||||
className="border-0 bg-transparent cursor-pointer"
|
className="border-0 bg-transparent cursor-pointer"
|
||||||
aria-describedby={id}
|
aria-describedby={id}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue