Skip to content

Commit

Permalink
fix(AvatarGroup): 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 acb5530 commit eec9caa
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/lib/components/avatar-group/Avatar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
</script>

<script lang="ts">
import { fade } from 'svelte/transition';
import { AVATAR_GROUP_CONTEXT_ID } from './AvatarGroup.svelte';
import { useContext } from '../../utils/useContext';
import { browser } from '$app/environment';
import { setContext, getContext, onMount } from 'svelte/internal';
import { twMerge } from 'tailwind-merge';
import Placeholder from './Placeholder.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());
export let src: string | undefined = undefined;
export let alt = 'avatar';
Expand Down Expand Up @@ -94,7 +97,12 @@
</script>

{#if src}
<span class={finalContainerClass} style={$$props.style}>
<span
class={finalContainerClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
{#if loaded}
<img class={finalClass} style={$$props.style} src={src || ''} {alt} />
{:else if failed}
Expand All @@ -110,7 +118,12 @@
<slot name="indicator" />
</span>
{:else if initials}
<span class={finalClass} style={$$props.style}>
<span
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
<span
class="font-bold leading-none text-current"
class:text-xs={size === 'xs'}
Expand Down
12 changes: 11 additions & 1 deletion src/lib/components/avatar-group/AvatarGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<script lang="ts">
import { setContext } from 'svelte/internal';
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());
export let shape: 'circle' | 'rounded' | 'square' = 'circle';
export let size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' = 'md';
Expand All @@ -26,6 +31,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/avatar-group/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import { getContext } from 'svelte/internal';
import { useContext } from '../../utils/useContext';
import type { MaterialIcon } from '../../types';
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 icon: MaterialIcon = 'person';
Expand Down Expand Up @@ -44,6 +49,11 @@
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<span class={finalClass} style={$$props.style}>
<span
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
{icon}
</span>
12 changes: 11 additions & 1 deletion src/lib/components/avatar-group/Indicator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import { getContext } from 'svelte/internal';
import { AVATAR_GROUP_AVATAR_CONTEXT_ID } from './Avatar.svelte';
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());
export let placement: 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left' = 'top-right';
Expand Down Expand Up @@ -58,4 +63,9 @@
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<span class={finalClass} style={$$props.style} />
<span
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
/>
13 changes: 12 additions & 1 deletion src/lib/components/avatar-group/Placeholder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import { getContext, setContext } from 'svelte/internal';
import { twMerge } from 'tailwind-merge';
import Icon from './Icon.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());
export let loading = false;
Expand Down Expand Up @@ -40,7 +45,13 @@
$: finalClass = twMerge(defaultClass, $$props.class);
</script>

<div transition:fade|local class={finalClass} style={$$props.style}>
<div
transition:fade|local
class={finalClass}
use:useActions={use}
use:forwardEvents
{...exclude($$props, ['use', 'class'])}
>
{#if $$slots.icon || $$slots.default}
<slot name="icon" />
<slot />
Expand Down

0 comments on commit eec9caa

Please sign in to comment.