Skip to content

Commit

Permalink
fix(Avatar): swapped out Icon
Browse files Browse the repository at this point in the history
docs(avatar): updated examples, props, and slots tables
  • Loading branch information
N00nDay committed Oct 18, 2022
1 parent e3b2467 commit a504065
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 82 deletions.
55 changes: 0 additions & 55 deletions src/lib/components/avatar/Icon.svelte

This file was deleted.

34 changes: 30 additions & 4 deletions src/lib/components/avatar/Placeholder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import { useContext } from '../../utils/useContext';
import { getContext, setContext } from 'svelte/internal';
import { twMerge } from 'tailwind-merge';
import Icon from './Icon.svelte';
import Icon from '../icon/Icon.svelte';
import { account } from '../../icons';
import { get_current_component } from 'svelte/internal';
import { forwardEventsBuilder, useActions, type ActionArray } from '../../actions';
export let use: ActionArray = [];
Expand All @@ -23,14 +24,37 @@
component: 'Avatar.Placeholder'
});
const { shape }: { shape: 'circle' | 'rounded' | 'square' } = getContext(AVATAR_CONTEXT_ID);
const {
shape,
size
}: { shape: 'circle' | 'rounded' | 'square'; size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' } =
getContext(AVATAR_CONTEXT_ID);
setContext(AVATAR_PLACEHOLDER_CONTEXT_ID, {
placeholder: true
});
let iconContainerClass = 'absolute text-light-icon dark:text-dark-icon h-full w-full';
let iconSize = '';
if (size === 'xs') {
iconContainerClass += ' bottom-[-0.25rem]';
iconSize = '24px';
} else if (size === 'sm') {
iconContainerClass += ' bottom-[-0.35rem]';
iconSize = '32px';
} else if (size === 'md') {
iconContainerClass += ' bottom-[-0.5rem]';
iconSize = '40px';
} else if (size === 'lg') {
iconContainerClass += ' text-6xl bottom-[-0.6rem]';
iconSize = '48px';
} else if (size === 'xl') {
iconContainerClass += ' bottom-[-0.75rem]';
iconSize = '64px';
}
let defaultClass =
'absolute inset-0 h-full w-full flex items-center justify-center overflow-hidden bg-light-icon-background dark:bg-dark-icon-background';
'absolute text-light-icon dark:text-dark-icon inset-0 h-full w-full flex items-center justify-center overflow-hidden bg-light-icon-background dark:bg-dark-icon-background';
if (shape === 'circle') {
defaultClass += ' rounded-full';
} else if (shape === 'rounded') {
Expand All @@ -52,7 +76,9 @@
{#if $$slots.icon}
<slot name="icon" />
{:else}
<Icon class="text-light-icon dark:text-dark-icon" />
<span class={iconContainerClass}>
<Icon data={account} size={iconSize} />
</span>
{/if}
</div>

Expand Down
13 changes: 3 additions & 10 deletions src/lib/components/avatar/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import OriginalAvatar from './Avatar.svelte';
import Indicator from './Indicator.svelte';
import OriginalPlaceholder from './Placeholder.svelte';
import Icon from './Icon.svelte';
import Placeholder from './Placeholder.svelte';

const Avatar = OriginalAvatar as AvatarStatic;
Avatar.Indicator = Indicator;
Avatar.Placeholder = OriginalPlaceholder as PlaceholderStatic;
Avatar.Placeholder.Icon = Icon;
Avatar.Placeholder = Placeholder;

export default Avatar;

export interface AvatarStatic {
new (...args: ConstructorParameters<typeof OriginalAvatar>): OriginalAvatar;
Indicator: typeof Indicator;
Placeholder: PlaceholderStatic;
}

export interface PlaceholderStatic {
new (...args: ConstructorParameters<typeof OriginalPlaceholder>): OriginalPlaceholder;
Icon: typeof Icon;
Placeholder: typeof Placeholder;
}
5 changes: 0 additions & 5 deletions src/routes/avatar/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
exampleInitials,
props,
slots,
iconSlots,
placeholderSlots,
indicatorProps
} from './examples';
Expand Down Expand Up @@ -120,10 +119,6 @@
<SlotsTable component="Avatar.Placeholder" slots={placeholderSlots} />
</Col>

<Col class="col-24">
<SlotsTable component="Avatar.Placeholder.Icon" slots={iconSlots} />
</Col>

<Col class="col-24">
<PropsTable component="Avatar.Indicator" props={indicatorProps} />
</Col>
8 changes: 0 additions & 8 deletions src/routes/avatar/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ export const placeholderSlots: Slot[] = [
{
id: '1',
slot: 'icon',
component: '<Avatar.Placeholder.Icon slot="icon" />'
}
];

export const iconSlots: Slot[] = [
{
id: '1',
slot: 'default',
component: ''
}
];
Expand Down

0 comments on commit a504065

Please sign in to comment.