Skip to content

Commit

Permalink
fix(Drawer): forward all events including child components
Browse files Browse the repository at this point in the history
fix(Drawer): class is reactive including child components
  • Loading branch information
N00nDay committed Oct 14, 2022
1 parent 7c4782b commit 564ab6a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/lib/components/drawer/Content.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import { DRAWER_CONTEXT_ID } from './Drawer.svelte';
import { useContext } from '../../utils/useContext';
import { twMerge } from 'tailwind-merge';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
useContext({
context_id: DRAWER_CONTEXT_ID,
Expand All @@ -13,6 +18,11 @@
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<div class={finalClass} style={$$props.style}>
<div
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
<slot />
</div>
14 changes: 12 additions & 2 deletions src/lib/components/drawer/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import { DRAWER_CONTEXT_ID } from './Drawer.svelte';
import { useContext } from '../../utils/useContext';
import { twMerge } from 'tailwind-merge';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
useContext({
context_id: DRAWER_CONTEXT_ID,
Expand All @@ -11,9 +16,14 @@
const defaultClass =
'px-4 sm:px-6 py-4 text-light-content dark:text-dark-content shadow-negative-md dark:shadow-black flex-shrink';
const finalClass = twMerge(defaultClass, $$props.class);
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<div class={finalClass} style={$$props.style}>
<div
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
<slot />
</div>
14 changes: 12 additions & 2 deletions src/lib/components/drawer/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import Button from '../button';
import { DRAWER_CONTEXT_ID } from './Drawer.svelte';
import { useContext } from '../../utils/useContext';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
import { exclude } from '../../utils/exclude';
const forwardEvents = forwardEventsBuilder(get_current_component());
useContext({
context_id: DRAWER_CONTEXT_ID,
Expand All @@ -14,10 +19,15 @@
const defaultClass =
'px-4 sm:px-6 py-4 shadow-md dark:shadow-black flex-shrink text-lg font-medium text-light-content dark:text-dark-content';
const finalClass = twMerge(defaultClass, $$props.class);
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<div class={finalClass}>
<div
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
<div class="flex items-start justify-between">
<h2>
<slot />
Expand Down

0 comments on commit 564ab6a

Please sign in to comment.