Skip to content

Commit

Permalink
fix(Alert): forward all events including child components
Browse files Browse the repository at this point in the history
  • Loading branch information
N00nDay committed Oct 14, 2022
1 parent 060bc81 commit 7e3f73a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/lib/components/alert/Alert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import { twMerge } from 'tailwind-merge';
import { setContext } from 'svelte';
import { writable } from 'svelte/store';
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());
export let type: 'info' | 'warn' | 'success' | 'error' = 'info';
let reactiveType = writable(type);
Expand All @@ -29,7 +34,12 @@
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<div class={finalClass} style={$$props.style}>
<div
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
<div class="flex">
<slot name="icon" />
{#if $$slots.title || $$slots.description}
Expand Down
12 changes: 11 additions & 1 deletion src/lib/components/alert/Description.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import type { Writable } from 'svelte/store';
import { twMerge } from 'tailwind-merge';
import { ALERT_CONTEXT_ID } from './Alert.svelte';
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());
const { type }: { type: Writable<'info' | 'warn' | 'success' | 'error'> } =
getContext(ALERT_CONTEXT_ID);
Expand All @@ -22,6 +27,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>
12 changes: 11 additions & 1 deletion src/lib/components/alert/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import type { Writable } from 'svelte/store';
import { twMerge } from 'tailwind-merge';
import { ALERT_CONTEXT_ID } from './Alert.svelte';
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());
const { type }: { type: Writable<'info' | 'warn' | 'success' | 'error'> } =
getContext(ALERT_CONTEXT_ID);
Expand All @@ -20,6 +25,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>
12 changes: 11 additions & 1 deletion src/lib/components/alert/Title.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import type { Writable } from 'svelte/store';
import { twMerge } from 'tailwind-merge';
import { ALERT_CONTEXT_ID } from './Alert.svelte';
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());
const { type }: { type: Writable<'info' | 'warn' | 'success' | 'error'> } =
getContext(ALERT_CONTEXT_ID);
Expand All @@ -24,7 +29,12 @@
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<h3 class={finalClass} style={$$props.style}>
<h3
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
<slot />
<slot name="extra" />
</h3>

0 comments on commit 7e3f73a

Please sign in to comment.