refactor: support copied text different from presented text

This commit is contained in:
siiky 2025-05-14 17:31:32 +01:00
parent f8a82bb84b
commit 951cd9cfa1

View file

@ -13,6 +13,7 @@ const CopyToClipboard = ({
className,
buttonClassname,
children,
value,
wrapperClassname,
removeSpace = true,
}) => {
@ -33,6 +34,12 @@ const CopyToClipboard = ({
const open = Boolean(anchorEl)
const id = open ? 'simple-popper' : undefined
const text = value
? value
: removeSpace
? R.replace(/\s/g, '')(children)
: children
return (
<div className={classnames('flex items-center', wrapperClassname)}>
{children && (
@ -43,8 +50,7 @@ const CopyToClipboard = ({
{children}
</Mono>
<div className={buttonClassname}>
<ReactCopyToClipboard
text={removeSpace ? R.replace(/\s/g, '')(children) : children}>
<ReactCopyToClipboard text={text}>
<button
className="border-0 bg-transparent cursor-pointer"
aria-describedby={id}