carbon-components-svelte/src/Notification/NotificationButton.svelte
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

47 lines
1.1 KiB
Svelte

<script>
/**
* Set the type of notification
* @type {"toast" | "inline"}
*/
export let notificationType = "toast";
/**
* Specify the icon to render
* @type {any}
*/
export let icon = Close;
/**
* Specify the title of the icon
* @type {string}
*/
export let title = undefined;
/** Specify the ARIA label for the icon */
export let iconDescription = "Close icon";
import Close from "../icons/Close.svelte";
</script>
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<button
type="button"
aria-label={iconDescription}
title={iconDescription}
class:bx--toast-notification__close-button={notificationType === "toast"}
class:bx--inline-notification__close-button={notificationType === "inline"}
{...$$restProps}
on:click
on:mouseover
on:mouseenter
on:mouseleave
>
<svelte:component
this={icon}
size={20}
{title}
class="{notificationType === 'toast' &&
'bx--toast-notification__close-icon'} {notificationType === 'inline' &&
'bx--inline-notification__close-icon'}"
/>
</button>