carbon-components-svelte/types/Tooltip/Tooltip.svelte.d.ts
Eric Liu 6bf72d4602
fix(types): loosen icon prop type to any (#2095)
Fixes https://github.com/carbon-design-system/carbon-icons-svelte/issues/207

`carbon-icons-svelte@13` and `carbon-pictograms-svelte@13` now  
only support TypeScript for Svelte 4/5.

The new `Component` type is incompatible with the `icon` prop in  
`carbon-components-svelte`, causing a type error with Svelte 5, as  
`typeof SvelteComponent` doesn't match the new `Component` type.

Since `Component` isn't available in Svelte 3/4, this PR changes  
the `icon` prop type to `any` for compatibility across Svelte 3, 4, and 5.
2025-02-02 19:49:53 -08:00

106 lines
2.1 KiB
TypeScript

import type { SvelteComponentTyped } from "svelte";
import type { SvelteHTMLElements } from "svelte/elements";
type $RestProps = SvelteHTMLElements["div"];
type $Props = {
/**
* Set the alignment of the tooltip relative to the icon
* @default "center"
*/
align?: "start" | "center" | "end";
/**
* Set the direction of the tooltip relative to the button
* @default "bottom"
*/
direction?: "top" | "right" | "bottom" | "left";
/**
* Set to `true` to open the tooltip
* @default false
*/
open?: boolean;
/**
* Set to `true` to hide the tooltip icon
* @default false
*/
hideIcon?: boolean;
/**
* Specify the icon to render for the tooltip button.
* Default to `<Information />`
* @default undefined
*/
icon?: any;
/**
* Specify the ARIA label for the tooltip button
* @default ""
*/
iconDescription?: string;
/**
* Specify the icon name attribute
* @default ""
*/
iconName?: string;
/**
* Set the button tabindex
* @default "0"
*/
tabindex?: string;
/**
* Set an id for the tooltip
* @default "ccs-" + Math.random().toString(36)
*/
tooltipId?: string;
/**
* Set an id for the tooltip button
* @default "ccs-" + Math.random().toString(36)
*/
triggerId?: string;
/**
* Set the tooltip button text
* @default ""
*/
triggerText?: string;
/**
* Obtain a reference to the trigger text HTML element
* @default null
*/
ref?: null | HTMLDivElement;
/**
* Obtain a reference to the tooltip HTML element
* @default null
*/
refTooltip?: null | HTMLDivElement;
/**
* Obtain a reference to the icon HTML element
* @default null
*/
refIcon?: null | HTMLDivElement;
[key: `data-${string}`]: any;
};
export type TooltipProps = Omit<$RestProps, keyof $Props> & $Props;
export default class Tooltip extends SvelteComponentTyped<
TooltipProps,
{
open: CustomEvent<null>;
close: CustomEvent<null>;
click: WindowEventMap["click"];
mousedown: WindowEventMap["mousedown"];
},
{ default: {}; icon: {}; triggerText: {} }
> {}