import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; import type { ButtonSkeletonProps } from "./ButtonSkeleton.svelte"; type $RestProps = SvelteHTMLElements["button"] & SvelteHTMLElements["a"] & SvelteHTMLElements["div"]; type $Props = { /** * Specify the kind of button. * @default "primary" */ kind?: "primary" | "secondary" | "tertiary" | "ghost" | "danger" | "danger-tertiary" | "danger-ghost"; /** * Specify the size of button. * When the `badge` slot is used, size is set to `lg` per Carbon design guidelines. * Falls back to the size set by an ancestor `ActionSet` when unset, then * to the height of a parent `Form`'s size (`xs`, `small` for `sm`, * `default` for `xl`). * Use `"xs"` for icon-only buttons in dense layouts. * Also accepts Carbon v11's `"sm"` (`"small"`), `"md"` (`"field"`) and * `"2xl"` (`"xl"`). `"lg"` and `"xl"` keep this library's 64px and 80px; * Carbon v11's 48px `lg` and 64px `xl` are `"default"` and `"lg"` here. * @default "default" */ size?: "default" | "field" | "small" | "xs" | "lg" | "xl" | "sm" | "md" | "2xl" | undefined; /** * Set to `true` to use Carbon's expressive typesetting * @default false */ expressive?: boolean; /** * Set to `true` to enable the selected state for an icon-only, ghost button. * Set to `false` to render it as a toggle that is not pressed. Left unset, * the button is not a toggle and renders no `aria-pressed`. */ isSelected?: boolean | undefined; /** * Set to `true` to render an icon-only button even when default content * is passed (default content isn't rendered), as from a wrapper that * forwards optional text; `false` to always render a labelled button. * Unset, a button with an icon and no default content is icon-only. * Without an icon, the button is always labelled. */ iconOnly?: boolean | undefined; /** * Set to `true` to span the full width of the container * @default false */ fullWidth?: boolean; /** * Specify the icon to render. * Alternatively, use the named slot "icon". * @example * ```svelte * * ``` */ icon?: Icon | undefined; /** * Specify the ARIA label for the button icon. * On an icon-only button, this also drives Carbon's tooltip. If omitted, * the icon-only button renders without a tooltip; supply your own * `aria-label` or `aria-labelledby` for accessibility in that case. */ iconDescription?: string | undefined; /** * Specify a keyboard shortcut for the button, such as `"mod+s"`. `mod` is * Command on Apple platforms and Ctrl elsewhere. The button shows the * keys (in its tooltip when icon-only), sets `aria-keyshortcuts`, and is * clicked when the shortcut is pressed while it's enabled and shown, and, * while a modal is open, inside it. A shortcut the app binds with * `onShortcut` takes precedence. * @default "" */ shortcut?: string; /** * 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 alignment of the tooltip relative to the icon. * Only applies to icon-only buttons. * @deprecated use `tooltipAlign` * @default "center" */ tooltipAlignment?: "start" | "center" | "end"; /** * Set the position of the tooltip relative to the icon. * @deprecated use `tooltipAlign` * @default "bottom" */ tooltipPosition?: "top" | "right" | "bottom" | "left"; /** * Set to `true` to hide the tooltip while maintaining accessibility. * Only applies to icon-only buttons. * When `true`, the tooltip is visually hidden but the `iconDescription` remains accessible to screen readers. * @default false */ hideTooltip?: boolean; /** * Set to `true` to render a custom HTML element. * Props are destructured as `props` in the default slot. * @example * ```svelte * * ``` * @default false */ as?: boolean; /** * Set to `true` to display the skeleton state * @default false */ skeleton?: boolean; /** * Set to `true` to disable the button * @default false */ disabled?: boolean; /** * Set the `href` to use an anchor link. */ href?: string | undefined; /** * Specify the tabindex * @default "0" */ tabindex?: number | string | undefined; /** * Specify the `type` attribute for the button element * @default "button" */ type?: string; /** * Obtain a reference to the HTML element. * Stays `null` when `as` is set; use `bind:this` on your own element instead. * @default null */ ref?: null | HTMLAnchorElement | HTMLButtonElement; /** * Set to `true` to always render the icon-only tooltip in a portal, which * also flips it when the preferred direction lacks space, or `false` to * keep it in place. Left unset, the tooltip opens in a portal inside a * `Modal`, or when a box around it (`overflow` other than `visible`, such * as a `DataTable`) would cut it off. */ portalTooltip?: boolean | undefined; /** * Set to `true` to display a loading spinner in place of the icon * and prevent the button from being activated. * Unlike `disabled`, the button remains focusable; use `disabled` * as well if it should also be removed from the tab order. * @default false */ loading?: boolean; /** * Specify the accessible description for the loading spinner. */ loadingDescription?: string | undefined; /** * Wait this many milliseconds after `loading` turns `true` before showing * the spinner. Once shown, the spinner stays for at least 500 ms, so fast * work shows nothing and slow work never flashes. The button blocks clicks * and sets `aria-busy` as soon as `loading` is `true`. * Set to `0` to show the spinner at once. * @default 0 */ loadingDelay?: number; /** Compose a `BadgeIndicator` overlaid on an icon-only button. Size is set to `lg` automatically. */ badge?: (this: void) => void; children?: (this: void, ...args: [{ props: { role: "button"; type?: string; tabindex: any; disabled: boolean; href?: string; class: string; [key: string]: any; } }]) => void; [key: `data-${string}`]: unknown; }; export type ButtonProps = Omit<$RestProps, keyof ($Props & ButtonSkeletonProps)> & Omit> & $Props; export default class Button extends SvelteComponentTyped< ButtonProps, { blur: WindowEventMap["blur"]; click: WindowEventMap["click"]; focus: WindowEventMap["focus"]; mousedown: WindowEventMap["mousedown"]; mouseenter: WindowEventMap["mouseenter"]; mouseleave: WindowEventMap["mouseleave"]; mouseover: WindowEventMap["mouseover"]; /** Dispatched when `shortcut` is pressed, before the button is clicked. Call `preventDefault()` to skip the click. */ shortcut: CustomEvent; }, { default: { props: { role: "button"; type?: string; tabindex: any; disabled: boolean; href?: string; class: string; [key: string]: any; } }; /** Compose a `BadgeIndicator` overlaid on an icon-only button. Size is set to `lg` automatically. */ badge: Record; icon: { style: undefined | string }; } > {}