import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; type $RestProps = SvelteHTMLElements["button"]; type $Props = { /** * Set the feedback text shown after clicking the button * @default "Copied!" */ feedback?: string; /** * Set the feedback text shown when copying fails * @default "Failed to copy" */ errorFeedback?: string; /** * Set the timeout duration (ms) to display feedback text * @default 2000 */ feedbackTimeout?: number; /** * Specify an icon to render during the feedback window (for example, after copying). * When unset, the copy icon is always shown. */ feedbackIcon?: Icon | undefined; /** * Set the title and ARIA label for the copy button * @default "Copy to clipboard" */ iconDescription?: string; /** * Specify the kind of copy button. * Use `"ghost"` to match a `Button` with `kind="ghost"`. * @default "primary" */ kind?: "primary" | "ghost"; /** * Specify the size of the copy button. * `"md"` keeps Carbon's native 2.5rem square; the other sizes match `Button`. * @default "md" */ size?: "sm" | "md" | "lg" | "xl"; /** * Specify the text to copy. */ text?: string | undefined; /** * Override the default copy behavior (`navigator.clipboard.writeText` with * a `document.execCommand("copy")` fallback). Failures reject so the button * can show `errorFeedback` and dispatch `copy:error`. * @default copyText */ copy?: (text: string) => void | Promise; /** * Set how the "Copied!" feedback tooltip is rendered. * By default, it is rendered in a portal so it shares the same surface as the * hover tooltip (the text swaps in place) and is never clipped by an * `overflow: hidden` container. Set to `false` to use Carbon's inline feedback * caret instead; a non-default `tooltipPosition`/`tooltipAlignment` still * portals because the inline caret only supports the default placement. */ portalTooltip?: boolean | undefined; /** * Set the tooltip placement in floating-ui form: the side, then `start` * or `end` along it, as Popover's `align` takes. Above and below, * `start` and `end` name inline sides, so they swap under `dir="rtl"`. * When set, takes precedence over `tooltipPosition` and `tooltipAlignment`. */ tooltipAlign?: "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "left-start" | "left-end" | "right" | "right-start" | "right-end" | undefined; /** * Set the position of the tooltip relative to the button. * @deprecated use `tooltipAlign` * @default "bottom" */ tooltipPosition?: "top" | "right" | "bottom" | "left"; /** * Set the alignment of the tooltip relative to the button. * @deprecated use `tooltipAlign` * @default "center" */ tooltipAlignment?: "start" | "center" | "end"; /** * Obtain a reference to the underlying button element. * @default null */ ref?: null | HTMLButtonElement; [key: `data-${string}`]: unknown; }; export type CopyButtonProps = Omit<$RestProps, keyof $Props> & $Props; export default class CopyButton extends SvelteComponentTyped< CopyButtonProps, { animationend: WindowEventMap["animationend"]; blur: WindowEventMap["blur"]; click: WindowEventMap["click"]; copy: CustomEvent; "copy:error": CustomEvent<{ error: unknown }>; focus: WindowEventMap["focus"]; mouseenter: WindowEventMap["mouseenter"]; mouseleave: WindowEventMap["mouseleave"]; }, Record > {}