-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Media): class is reactive including all child components
fix(Media.Avatar): include Avatar and its props
- Loading branch information
Craig Howell
authored and
Craig Howell
committed
Oct 11, 2022
1 parent
7ed8d81
commit 5157958
Showing
5 changed files
with
31 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
<script lang="ts"> | ||
import { MEDIA_CONTEXT_ID } from './Media.svelte'; | ||
import { useContext } from '../../utils/useContext'; | ||
import Avatar from '../avatar'; | ||
import { current_component } from 'svelte/internal'; | ||
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions'; | ||
import { exclude } from '../../utils/exclude'; | ||
import { twMerge } from 'tailwind-merge'; | ||
export let use: ActionArray = []; | ||
const forwardEvents = forwardEventsBuilder(current_component); | ||
export let align: 'top' | 'center' | 'bottom' = 'top'; | ||
export let src: string; | ||
export let alt = 'avatar'; | ||
export let size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' = 'md'; | ||
useContext({ | ||
context_id: MEDIA_CONTEXT_ID, | ||
parent: 'Media', | ||
component: 'Media.Avatar' | ||
}); | ||
let defaultClass = 'first:mr-4 last:ml-4 flex-shrink-0'; | ||
$: if (align === 'center') { | ||
defaultClass = defaultClass + ' self-center'; | ||
} else if (align === 'bottom') { | ||
defaultClass = defaultClass + ' self-end'; | ||
} | ||
$: finalClass = twMerge(defaultClass, $$props.class); | ||
</script> | ||
|
||
<div | ||
class="first:mr-4 last:ml-4 flex-shrink-0{$$props.class ? ` ${$$props.class}` : ''}" | ||
class:self-center={align === 'center'} | ||
class:self-end={align === 'bottom'} | ||
class={finalClass} | ||
style={$$props.style} | ||
use:useActions={use} | ||
use:forwardEvents | ||
{...exclude($$props, ['use', 'class'])} | ||
> | ||
<slot /> | ||
<Avatar {src} {alt} {size} /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters