"use client"; /* * Documentation: * Copy to clipboard button — https://app.subframe.com/f023064a5ca0/library?component=Copy+to+clipboard+button_e8c76626-6462-4f2f-b595-38d530d427e8 * Tooltip — https://app.subframe.com/f023064a5ca0/library?component=Tooltip_ccebd1e9-f6ac-4737-8376-0dfacd90c9f3 */ import React from "react"; import { FeatherCopy } from "@subframe/core"; import * as SubframeCore from "@subframe/core"; import copy from "copy-to-clipboard"; import * as SubframeUtils from "../../utils"; import { Tooltip } from "../Tooltip"; export interface CopyToClipboardButtonRootProps extends Omit, "clipboardText" | "onCopy"> { clipboardText?: React.ReactNode; tooltipText?: React.ReactNode; icon?: React.ReactNode; onCopy?: (copied: boolean) => void; className?: string; } const CopyToClipboardButtonRoot = React.forwardRef(function CopyToClipboardButtonRoot( { clipboardText, tooltipText, icon = , onCopy, options, className, ...otherProps }: CopyToClipboardButtonRootProps, ref ) { const copyValue = () => { if (typeof clipboardText !== "string") return; const copied = copy(clipboardText, options); onCopy?.(copied); }; return (
{ otherProps.onClick?.(event); if (!event.defaultPrevented) copyValue(); }} onKeyDown={(event) => { otherProps.onKeyDown?.(event); if (event.defaultPrevented || (event.key !== "Enter" && event.key !== " ")) return; event.preventDefault(); copyValue(); }} ref={ref} role={otherProps.role ?? "button"} tabIndex={otherProps.tabIndex ?? 0} > {icon ? ( {icon} ) : null}
{tooltipText}
); }); export const CopyToClipboardButton = CopyToClipboardButtonRoot;