carbon-components-svelte
Version:
Svelte implementation of the Carbon Design System
104 lines (87 loc) • 2.46 kB
TypeScript
import { SvelteComponentTyped } from "svelte";
import type { SvelteHTMLElements } from "svelte/elements";
type $RestProps = SvelteHTMLElements["li"];
type $Props<Icon = any> = {
/**
* Specify the tab label.
* Alternatively, use the default slot.
* @example
* ```svelte
* <Tab>
* <span>Label</span>
* </Tab>
* ```
* @default ""
*/
label?: string;
/**
* Specify the href attribute
* @default "#"
*/
href?: string;
/**
* Set to `true` to disable the tab
* @default false
*/
disabled?: boolean;
/**
* Specify the tabindex
* @default "0"
*/
tabindex?: number | string | undefined;
/**
* Set an id for the top-level element
* @default `ccs-${Math.random().toString(36)}`
*/
id?: string;
/**
* Specify an optional secondary label.
* Only rendered for container type tabs.
* Alternatively, use the "secondaryChildren" slot.
* @default ""
*/
secondaryLabel?: string;
/**
* Specify the icon to render.
* Icon is rendered to the right of the label by default.
* When the parent `Tabs` is `dismissible`, the icon is rendered to the left.
* When the parent `Tabs` is `iconOnly`, only the icon is rendered and the
* `label` is used as the accessible name and the tooltip shown on hover/focus.
* @default undefined
*/
icon?: Icon;
/**
* Obtain a reference to the anchor HTML element.
* @default null
*/
ref?: null | HTMLAnchorElement;
/**
* Set the direction of the tooltip relative to the tab.
* Only used when the tab is rendered icon-only.
* @default "bottom"
*/
tooltipDirection?: "top" | "bottom";
/**
* Set the alignment of the tooltip relative to the tab.
* Only used when the tab is rendered icon-only.
* @default "center"
*/
tooltipAlignment?: "start" | "center" | "end";
secondaryChildren?: (this: void) => void;
children?: (this: void, ...args: [{ selected: boolean }]) => void;
[key: `data-${string}`]: unknown;
};
export type TabProps<Icon = any> = Omit<$RestProps, keyof $Props<Icon>> & $Props<Icon>;
export default class Tab<Icon = any> extends SvelteComponentTyped<
TabProps<Icon>,
{
click: WindowEventMap["click"];
mouseenter: WindowEventMap["mouseenter"];
mouseleave: WindowEventMap["mouseleave"];
mouseover: WindowEventMap["mouseover"];
},
{
default: { selected: boolean };
secondaryChildren: Record<string, never>;
}
> {}