mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 04:13:02 +00:00
feat(side-nav): dispatch open, close, click:overlay events
This commit is contained in:
parent
a79ef4b98f
commit
6d805e73a8
4 changed files with 27 additions and 4 deletions
|
@ -1,4 +1,10 @@
|
|||
<script>
|
||||
/**
|
||||
* @event {any} open
|
||||
* @event {any} close
|
||||
* @event {any} click:overlay
|
||||
*/
|
||||
|
||||
/** Set to `true` to use the fixed variant */
|
||||
export let fixed = false;
|
||||
|
||||
|
@ -11,9 +17,13 @@
|
|||
/** Set to `true` to toggle the expanded state */
|
||||
export let isOpen = false;
|
||||
|
||||
import { onMount } from "svelte";
|
||||
import { onMount, createEventDispatcher } from "svelte";
|
||||
import { shouldRenderHamburgerMenu } from "../navStore";
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
$: dispatch(isOpen ? "open" : "close");
|
||||
|
||||
onMount(() => {
|
||||
shouldRenderHamburgerMenu.set(true);
|
||||
return () => shouldRenderHamburgerMenu.set(false);
|
||||
|
@ -23,6 +33,7 @@
|
|||
{#if !fixed}
|
||||
<div
|
||||
on:click="{() => {
|
||||
dispatch('click:overlay');
|
||||
isOpen = false;
|
||||
}}"
|
||||
class:bx--side-nav__overlay="{true}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue