mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
feat(ui-shell): allow custom hamburger menu icons
This commit is contained in:
parent
d9fcaf3038
commit
3620f94f97
5 changed files with 78 additions and 12 deletions
|
@ -1505,16 +1505,18 @@ None.
|
||||||
|
|
||||||
### Props
|
### Props
|
||||||
|
|
||||||
| Prop name | Kind | Reactive | Type | Default value | Description |
|
| Prop name | Kind | Reactive | Type | Default value | Description |
|
||||||
| :---------------------- | :--------------- | :------- | :----------------------------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
|
| :---------------------- | :--------------- | :------- | :----------------------------------------------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| ref | <code>let</code> | Yes | <code>null | HTMLAnchorElement</code> | <code>null</code> | Obtain a reference to the HTML anchor element |
|
| ref | <code>let</code> | Yes | <code>null | HTMLAnchorElement</code> | <code>null</code> | Obtain a reference to the HTML anchor element |
|
||||||
| isSideNavOpen | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to open the side nav |
|
| isSideNavOpen | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to open the side nav |
|
||||||
| expandedByDefault | <code>let</code> | No | <code>boolean</code> | <code>true</code> | Set to `false` to hide the side nav by default |
|
| expandedByDefault | <code>let</code> | No | <code>boolean</code> | <code>true</code> | Set to `false` to hide the side nav by default |
|
||||||
| uiShellAriaLabel | <code>let</code> | No | <code>string</code> | -- | Specify the ARIA label for the header |
|
| uiShellAriaLabel | <code>let</code> | No | <code>string</code> | -- | Specify the ARIA label for the header |
|
||||||
| href | <code>let</code> | No | <code>string</code> | -- | Specify the `href` attribute |
|
| href | <code>let</code> | No | <code>string</code> | -- | Specify the `href` attribute |
|
||||||
| company | <code>let</code> | No | <code>string</code> | -- | Specify the company name |
|
| company | <code>let</code> | No | <code>string</code> | -- | Specify the company name |
|
||||||
| platformName | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the platform name<br />Alternatively, use the named slot "platform" (e.g., <span slot="platform">...</span>) |
|
| platformName | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the platform name<br />Alternatively, use the named slot "platform" (e.g., <span slot="platform">...</span>) |
|
||||||
| persistentHamburgerMenu | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to persist the hamburger menu |
|
| persistentHamburgerMenu | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to persist the hamburger menu |
|
||||||
|
| iconMenu | <code>let</code> | No | <code>typeof import("carbon-icons-svelte").CarbonIcon</code> | -- | Specify the icon from `carbon-icons-svelte` to render for the closed state<br />Defaults to `Menu20` |
|
||||||
|
| iconClose | <code>let</code> | No | <code>typeof import("carbon-icons-svelte").CarbonIcon</code> | -- | Specify the icon from `carbon-icons-svelte` to render for the opened state<br />Defaults to `Close20` |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
||||||
|
|
|
@ -3787,6 +3787,24 @@
|
||||||
"isFunction": false,
|
"isFunction": false,
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"reactive": true
|
"reactive": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "iconMenu",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Specify the icon from `carbon-icons-svelte` to render for the closed state\nDefaults to `Menu20`",
|
||||||
|
"type": "typeof import(\"carbon-icons-svelte\").CarbonIcon",
|
||||||
|
"isFunction": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "iconClose",
|
||||||
|
"kind": "let",
|
||||||
|
"description": "Specify the icon from `carbon-icons-svelte` to render for the opened state\nDefaults to `Close20`",
|
||||||
|
"type": "typeof import(\"carbon-icons-svelte\").CarbonIcon",
|
||||||
|
"isFunction": false,
|
||||||
|
"constant": false,
|
||||||
|
"reactive": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"slots": [
|
"slots": [
|
||||||
|
|
|
@ -35,6 +35,22 @@
|
||||||
/** Obtain a reference to the HTML anchor element */
|
/** Obtain a reference to the HTML anchor element */
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the icon from `carbon-icons-svelte` to render for the closed state
|
||||||
|
* Defaults to `Menu20`
|
||||||
|
* @type {typeof import("carbon-icons-svelte").CarbonIcon}
|
||||||
|
*/
|
||||||
|
export let iconMenu = Menu20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the icon from `carbon-icons-svelte` to render for the opened state
|
||||||
|
* Defaults to `Close20`
|
||||||
|
* @type {typeof import("carbon-icons-svelte").CarbonIcon}
|
||||||
|
*/
|
||||||
|
export let iconClose = Close20;
|
||||||
|
|
||||||
|
import Close20 from "carbon-icons-svelte/lib/Close20/Close20.svelte";
|
||||||
|
import Menu20 from "carbon-icons-svelte/lib/Menu20/Menu20.svelte";
|
||||||
import { shouldRenderHamburgerMenu } from "../navStore";
|
import { shouldRenderHamburgerMenu } from "../navStore";
|
||||||
import HamburgerMenu from "../SideNav/HamburgerMenu.svelte";
|
import HamburgerMenu from "../SideNav/HamburgerMenu.svelte";
|
||||||
|
|
||||||
|
@ -52,7 +68,11 @@
|
||||||
<header role="banner" aria-label="{ariaLabel}" class:bx--header="{true}">
|
<header role="banner" aria-label="{ariaLabel}" class:bx--header="{true}">
|
||||||
<slot name="skip-to-content" />
|
<slot name="skip-to-content" />
|
||||||
{#if ($shouldRenderHamburgerMenu && winWidth < 1056) || persistentHamburgerMenu}
|
{#if ($shouldRenderHamburgerMenu && winWidth < 1056) || persistentHamburgerMenu}
|
||||||
<HamburgerMenu bind:isOpen="{isSideNavOpen}" />
|
<HamburgerMenu
|
||||||
|
bind:isOpen="{isSideNavOpen}"
|
||||||
|
iconClose="{iconClose}"
|
||||||
|
iconMenu="{iconMenu}"
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<a
|
<a
|
||||||
href="{href}"
|
href="{href}"
|
||||||
|
|
|
@ -8,6 +8,20 @@
|
||||||
/** Set to `true` to toggle the open state */
|
/** Set to `true` to toggle the open state */
|
||||||
export let isOpen = false;
|
export let isOpen = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the icon from `carbon-icons-svelte` to render for the closed state
|
||||||
|
* Defaults to `Menu20`
|
||||||
|
* @type {typeof import("carbon-icons-svelte").CarbonIcon}
|
||||||
|
*/
|
||||||
|
export let iconMenu = Menu20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the icon from `carbon-icons-svelte` to render for the opened state
|
||||||
|
* Defaults to `Close20`
|
||||||
|
* @type {typeof import("carbon-icons-svelte").CarbonIcon}
|
||||||
|
*/
|
||||||
|
export let iconClose = Close20;
|
||||||
|
|
||||||
/** Obtain a reference to the HTML button element */
|
/** Obtain a reference to the HTML button element */
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
|
@ -27,5 +41,5 @@
|
||||||
on:click
|
on:click
|
||||||
on:click="{() => (isOpen = !isOpen)}"
|
on:click="{() => (isOpen = !isOpen)}"
|
||||||
>
|
>
|
||||||
<svelte:component this="{isOpen ? Close20 : Menu20}" />
|
<svelte:component this="{isOpen ? iconClose : iconMenu}" />
|
||||||
</button>
|
</button>
|
||||||
|
|
12
types/UIShell/GlobalHeader/Header.d.ts
vendored
12
types/UIShell/GlobalHeader/Header.d.ts
vendored
|
@ -48,6 +48,18 @@ export interface HeaderProps
|
||||||
* @default null
|
* @default null
|
||||||
*/
|
*/
|
||||||
ref?: null | HTMLAnchorElement;
|
ref?: null | HTMLAnchorElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the icon from `carbon-icons-svelte` to render for the closed state
|
||||||
|
* Defaults to `Menu20`
|
||||||
|
*/
|
||||||
|
iconMenu?: typeof import("carbon-icons-svelte").CarbonIcon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the icon from `carbon-icons-svelte` to render for the opened state
|
||||||
|
* Defaults to `Close20`
|
||||||
|
*/
|
||||||
|
iconClose?: typeof import("carbon-icons-svelte").CarbonIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Header extends SvelteComponentTyped<
|
export default class Header extends SvelteComponentTyped<
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue