Skip to content

Commit

Permalink
fix(Avatar): cleaned up context
Browse files Browse the repository at this point in the history
  • Loading branch information
N00nDay committed Oct 23, 2022
1 parent c800798 commit 4392f3b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 46 deletions.
15 changes: 4 additions & 11 deletions src/lib/components/avatar/Avatar.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<script lang="ts" context="module">
export const AVATAR_CONTEXT_ID = 'avatar-context-id';
</script>

<script lang="ts">
import { setContext, onMount } from 'svelte/internal';
import { twMerge } from 'tailwind-merge';
Expand All @@ -22,13 +18,10 @@
let failed = false;
let loading = true;
setContext(AVATAR_CONTEXT_ID, {
avatar: true,
src,
alt,
shape,
size
});
setContext('avatar-src', src);
setContext('avatar-alt', alt);
setContext('avatar-shape', shape);
setContext('avatar-size', size);
let defaultClass = '';
let containerDefaultClass = '';
Expand Down
15 changes: 2 additions & 13 deletions src/lib/components/avatar/Indicator.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<script lang="ts">
import { useContext } from '../../utils/useContext';
import { getContext } from 'svelte/internal';
import { 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';
Expand All @@ -11,17 +9,8 @@
export let placement: 'top-right' | 'bottom-right' | 'top-left' | 'bottom-left' = 'top-right';
useContext({
context_id: AVATAR_CONTEXT_ID,
parent: 'Avatar',
component: 'Avatar.Indicator'
});
const {
shape,
size
}: { size: 'xs' | 'sm' | 'md' | 'lg' | 'xl'; shape: 'circle' | 'rounded' | 'square' } =
getContext(AVATAR_CONTEXT_ID);
const shape: 'circle' | 'rounded' | 'square' = getContext('avatar-shape');
const size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' = getContext('avatar-size');
let defaultClass = '';
if (placement === 'top-right') {
Expand Down
25 changes: 3 additions & 22 deletions src/lib/components/avatar/Placeholder.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<script lang="ts" context="module">
export const AVATAR_PLACEHOLDER_CONTEXT_ID = 'avatar-placeholder-context-id';
</script>

<script lang="ts">
import { fade } from 'svelte/transition';
import { AVATAR_CONTEXT_ID } from './Avatar.svelte';
import { useContext } from '../../utils/useContext';
import { getContext, setContext } from 'svelte/internal';
import { getContext } from 'svelte/internal';
import { twMerge } from 'tailwind-merge';
import Icon from '../icon/Icon.svelte';
import { account } from '../../icons';
Expand All @@ -18,21 +12,8 @@
export let loading = false;
useContext({
context_id: AVATAR_CONTEXT_ID,
parent: 'Avatar',
component: 'Avatar.Placeholder'
});
const {
shape,
size
}: { shape: 'circle' | 'rounded' | 'square'; size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' } =
getContext(AVATAR_CONTEXT_ID);
setContext(AVATAR_PLACEHOLDER_CONTEXT_ID, {
placeholder: true
});
const shape: 'circle' | 'rounded' | 'square' = getContext('avatar-shape');
const size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' = getContext('avatar-size');
let iconContainerClass = 'absolute text-light-icon dark:text-dark-icon h-full w-full';
let iconSize = '';
Expand Down

0 comments on commit 4392f3b

Please sign in to comment.