mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
hamburger menu working
This commit is contained in:
parent
7e168adcb7
commit
2746249d98
3 changed files with 33 additions and 20 deletions
|
@ -15,11 +15,26 @@
|
||||||
import UIShellSideNavItem from './UIShellSideNav/UIShellSideNavItem.svelte';
|
import UIShellSideNavItem from './UIShellSideNav/UIShellSideNavItem.svelte';
|
||||||
import HamburgerMenu from './UIShellSideNav/HamburgerMenu.svelte';
|
import HamburgerMenu from './UIShellSideNav/HamburgerMenu.svelte';
|
||||||
|
|
||||||
|
let isSideNavOpen = undefined;
|
||||||
|
let winWidth = window.innerWidth;
|
||||||
|
|
||||||
|
window.addEventListener('resize', () => {
|
||||||
|
winWidth = window.innerWidth;
|
||||||
|
|
||||||
|
if (winWidth >= 1056) {
|
||||||
|
isSideNavOpen = true;
|
||||||
|
} else {
|
||||||
|
isSideNavOpen = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName);
|
$: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header aria-label={ariaLabel} class={cx('--header')} role="banner">
|
<header aria-label={ariaLabel} class={cx('--header')} role="banner">
|
||||||
<HamburgerMenu />
|
{#if winWidth < 1056}
|
||||||
|
<HamburgerMenu bind:isOpen={isSideNavOpen} />
|
||||||
|
{/if}
|
||||||
<a class={cx('--header__name')} {href}>
|
<a class={cx('--header__name')} {href}>
|
||||||
<span class={cx('--header__name--prefix')}>{company}</span>
|
<span class={cx('--header__name--prefix')}>{company}</span>
|
||||||
{platformName}
|
{platformName}
|
||||||
|
@ -35,7 +50,7 @@
|
||||||
<UIShellRightPanel {rightPanel} on:inputSearch />
|
<UIShellRightPanel {rightPanel} on:inputSearch />
|
||||||
{/if}
|
{/if}
|
||||||
{#if sideNavMenu}
|
{#if sideNavMenu}
|
||||||
<UIShellSideNavWrapper>
|
<UIShellSideNavWrapper bind:isOpen={isSideNavOpen} bind:winWidth={winWidth}>
|
||||||
<UIShellSideNavItem />
|
<UIShellSideNavItem />
|
||||||
</UIShellSideNavWrapper>
|
</UIShellSideNavWrapper>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<script>
|
<script>
|
||||||
export let ariaLabel = undefined;
|
export let ariaLabel = undefined;
|
||||||
|
export let isOpen = false;
|
||||||
|
|
||||||
import { cx } from '../../../lib';
|
import { cx } from '../../../lib';
|
||||||
import Menu20 from 'carbon-icons-svelte/lib/Menu20';
|
import Menu20 from 'carbon-icons-svelte/lib/Menu20';
|
||||||
import Icon from '../../Icon/Icon.svelte';
|
import Icon from '../../Icon/Icon.svelte';
|
||||||
|
import { fly } from "svelte/transition";
|
||||||
import { closeIcon } from '../constants';
|
import { closeIcon } from '../constants';
|
||||||
|
|
||||||
let isOpen = false;
|
|
||||||
|
|
||||||
$: iconProps = !isOpen ? {
|
$: iconProps = !isOpen ? {
|
||||||
class: undefined,
|
class: undefined,
|
||||||
skeleton: false,
|
skeleton: false,
|
||||||
|
@ -20,6 +20,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
transition:fly={{ x: -200, delay: 50, duration: 250 }}
|
||||||
aria-label={ariaLabel}
|
aria-label={ariaLabel}
|
||||||
class={cx('--header__action', '--header__menu-trigger', '--header__menu-toggle')}
|
class={cx('--header__action', '--header__menu-trigger', '--header__menu-toggle')}
|
||||||
title="Open menu"
|
title="Open menu"
|
||||||
|
|
|
@ -1,29 +1,26 @@
|
||||||
<script>
|
<script>
|
||||||
export let ariaLabel = undefined;
|
export let ariaLabel = undefined;
|
||||||
|
export let isOpen = undefined;
|
||||||
|
|
||||||
import { cx } from '../../../lib';
|
import { cx } from '../../../lib';
|
||||||
|
import Icon from '../../Icon/Icon.svelte';
|
||||||
|
import { closeIcon } from '../constants';
|
||||||
|
|
||||||
|
$: footerSpanText = isOpen ? 'Open' : 'Close';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<nav class={cx('--side-nav__navigation', '--side-nav', '--side-nav--ux')} aria-label={ariaLabel}>
|
<nav
|
||||||
|
class={cx('--side-nav__navigation', '--side-nav', '--side-nav--ux', isOpen && '--side-nav--expanded')}
|
||||||
|
aria-label={ariaLabel}>
|
||||||
<ul class={cx('--side-nav__items')}>
|
<ul class={cx('--side-nav__items')}>
|
||||||
<slot />
|
<slot />
|
||||||
</ul>
|
</ul>
|
||||||
<footer class="bx--side-nav__footer">
|
<footer class={cx('--side-nav__footer')}>
|
||||||
<button class="bx--side-nav__toggle" type="button" title="Open">
|
<button class={cx('--side-nav__toggle')} type="button" title="Open">
|
||||||
<div class="bx--side-nav__icon">
|
<div class={cx('--side-nav__icon')}>
|
||||||
<svg
|
<Icon {...closeIcon} />
|
||||||
focusable="false"
|
|
||||||
preserveAspectRatio="xMidYMid meet"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
width="20"
|
|
||||||
height="20"
|
|
||||||
viewBox="0 0 32 32"
|
|
||||||
aria-hidden="true"
|
|
||||||
style="will-change: transform;">
|
|
||||||
<path d="M22 16L12 26l-1.4-1.4 8.6-8.6-8.6-8.6L12 6z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
</div>
|
||||||
<span class="bx--assistive-text">Open</span>
|
<span class={cx('--assistive-text')}>{footerSpanText}</span>
|
||||||
</button>
|
</button>
|
||||||
</footer>
|
</footer>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue