mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 10:14:22 +01:00
docs: share tweak copy button
This commit is contained in:
@@ -11,7 +11,8 @@ export function CopyButton(props: CopyButtonProps) {
|
||||
|
||||
function handleCopyClick() {
|
||||
if (props.text) {
|
||||
navigator.clipboard.writeText(props.text).catch((err) => console.error("Copy failed", err))
|
||||
navigator.clipboard.writeText(props.text)
|
||||
.catch((err) => console.error("Copy failed", err))
|
||||
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 2000)
|
||||
@@ -19,17 +20,17 @@ export function CopyButton(props: CopyButtonProps) {
|
||||
}
|
||||
|
||||
return (
|
||||
<div class={styles.copyButtonWrapper}>
|
||||
<div data-component="copy-button" class={styles.root}>
|
||||
<button
|
||||
type="button"
|
||||
class={styles.copyButton}
|
||||
onClick={handleCopyClick}
|
||||
data-copied={copied() ? true : undefined}
|
||||
title="Copy content"
|
||||
>
|
||||
{copied() ? <IconCheckCircle width={16} height={16} /> : <IconClipboard width={16} height={16} />}
|
||||
{copied()
|
||||
? <IconCheckCircle width={16} height={16} />
|
||||
: <IconClipboard width={16} height={16} />
|
||||
}
|
||||
</button>
|
||||
{copied() && <span class={styles.copyTooltip}>Copied!</span>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user