carbon-components-svelte/src/UIShell/HamburgerMenu.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

45 lines
1 KiB
Svelte

<script>
/**
* Specify the ARIA label for the button
* @type {string}
*/
export let ariaLabel = undefined;
/** Set to `true` to toggle the open state */
export let isOpen = false;
/**
* Specify the icon to render for the closed state.
* Defaults to `<Menu size={20} />`
* @type {any}
*/
export let iconMenu = Menu;
/**
* Specify the icon to render for the opened state.
* Defaults to `<Close size={20} />`
* @type {any}
*/
export let iconClose = Close;
/** Obtain a reference to the HTML button element */
export let ref = null;
import Close from "../icons/Close.svelte";
import Menu from "../icons/Menu.svelte";
</script>
<button
bind:this={ref}
type="button"
title={ariaLabel}
aria-label={ariaLabel}
class:bx--header__action={true}
class:bx--header__menu-trigger={true}
class:bx--header__menu-toggle={true}
{...$$restProps}
on:click
on:click={() => (isOpen = !isOpen)}
>
<svelte:component this={isOpen ? iconClose : iconMenu} size={20} />
</button>