UNPKG

carbon-components-svelte

Version:
79 lines (66 loc) 1.87 kB
import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; type $RestProps = SvelteHTMLElements["button"]; type $Props<Icon = any> = { /** * Specify the switch text. * Alternatively, use the default slot. * @example * ```svelte * <Switch> * <span>Custom Text</span> * </Switch> * ``` * @default "Provide text" */ text?: string; /** * Render an icon-only switch. * The parent `ContentSwitcher` becomes icon-only when every `Switch` sets `icon`. * `text` is used as the accessible label and the tooltip shown on hover and focus. * @default undefined */ icon?: Icon; /** * Set to `true` for the switch to be selected. * @default false */ selected?: boolean; /** * Set to `true` to disable the switch * @default false */ disabled?: boolean; /** * Align the portalled tooltip to the switch. * @default "center" */ tooltipAlignment?: "start" | "center" | "end"; /** * Set an id for the button element * @default `ccs-${Math.random().toString(36)}` */ id?: string; /** * Obtain a reference to the button HTML element. * @default null */ ref?: null | HTMLButtonElement; children?: (this: void) => void; [key: `data-${string}`]: unknown; }; export type SwitchProps<Icon = any> = Omit<$RestProps, keyof $Props<Icon>> & $Props<Icon>; export default class Switch<Icon = any> extends SvelteComponentTyped< SwitchProps<Icon>, { blur: WindowEventMap["blur"]; click: WindowEventMap["click"]; focus: WindowEventMap["focus"]; keydown: WindowEventMap["keydown"]; keyup: WindowEventMap["keyup"]; mouseenter: WindowEventMap["mouseenter"]; mouseleave: WindowEventMap["mouseleave"]; mouseover: WindowEventMap["mouseover"]; }, { default: Record<string, never> } > {}