update avatar
This commit is contained in:
parent
7e2b20d4a5
commit
da1dfe2aa7
4 changed files with 54 additions and 11 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
<script module lang="ts">
|
<script module lang="ts">
|
||||||
import { defineMeta } from '@storybook/addon-svelte-csf';
|
import { defineMeta } from '@storybook/addon-svelte-csf';
|
||||||
|
import { type ComponentProps } from 'svelte';
|
||||||
import Avatar from './Avatar.svelte';
|
import Avatar from './Avatar.svelte';
|
||||||
|
import AvatarGroups from './AvatarGroup.svelte';
|
||||||
|
|
||||||
const { Story } = defineMeta({
|
const { Story } = defineMeta({
|
||||||
title: 'Data display/Avatar',
|
title: 'Data display/Avatar',
|
||||||
|
|
@ -14,11 +16,11 @@
|
||||||
defaultValue: 'DP',
|
defaultValue: 'DP',
|
||||||
},
|
},
|
||||||
presence: {
|
presence: {
|
||||||
control: 'select',
|
control: 'radio',
|
||||||
options: [undefined, 'online', 'offline'],
|
options: [undefined, 'online', 'offline'],
|
||||||
},
|
},
|
||||||
ring: {
|
ring: {
|
||||||
control: 'select',
|
control: 'radio',
|
||||||
options: [
|
options: [
|
||||||
undefined,
|
undefined,
|
||||||
'neutral',
|
'neutral',
|
||||||
|
|
@ -32,20 +34,36 @@
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
shape: {
|
shape: {
|
||||||
control: 'select',
|
control: 'radio',
|
||||||
options: ['square', 'circle'],
|
options: ['square', 'circle'],
|
||||||
|
defaultValue: 'circle',
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
control: 'select',
|
control: 'radio',
|
||||||
options: ['xs', 'sm', 'md', 'lg'],
|
options: ['xs', 'sm', 'md', 'lg'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#snippet template(props: Partial<ComponentProps<typeof Avatar>>)}
|
||||||
|
<Avatar {...props} placeholder={props.placeholder || 'PC'} />
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
<Story
|
<Story
|
||||||
name="Default"
|
name="Default"
|
||||||
args={{
|
args={{
|
||||||
img: 'https://img.daisyui.com/images/stock/photo-1534528741775-53994a69daeb.webp',
|
img: 'https://img.daisyui.com/images/stock/photo-1534528741775-53994a69daeb.webp',
|
||||||
}}
|
}}
|
||||||
|
children={template}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Story name="Placeholder" args={{ placeholder: 'BP' }} children={template} />
|
||||||
|
|
||||||
|
<Story name="Avatar Group">
|
||||||
|
<AvatarGroups>
|
||||||
|
{@render template({ placeholder: 'BP' })}
|
||||||
|
{@render template({ placeholder: 'MS' })}
|
||||||
|
{@render template({ placeholder: 'DM' })}
|
||||||
|
</AvatarGroups>
|
||||||
|
</Story>
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
<script lang="ts" module>
|
||||||
|
export type AvatarShape = 'circle' | 'square';
|
||||||
|
export type AvatarPresence = 'offline' | 'online';
|
||||||
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { DaisyColor, DaisySize } from '$lib/types';
|
import type { DaisyColor, DaisySize } from '$lib/types';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
|
|
@ -7,10 +12,10 @@
|
||||||
type Props = {
|
type Props = {
|
||||||
img?: string;
|
img?: string;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
presence?: 'online' | 'offline';
|
presence?: AvatarPresence;
|
||||||
ring?: Exclude<DaisyColor, 'ghost'>;
|
ring?: DaisyColor;
|
||||||
shape?: 'square' | 'circle';
|
shape?: AvatarShape;
|
||||||
size?: DaisySize | 'md';
|
size?: DaisySize;
|
||||||
} & Omit<SvelteHTMLElements['div'], 'children'>;
|
} & Omit<SvelteHTMLElements['div'], 'children'>;
|
||||||
|
|
||||||
let {
|
let {
|
||||||
|
|
@ -25,7 +30,13 @@
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div {...props} class={twMerge('avatar', presence, clsx(className))} class:placeholder>
|
<div
|
||||||
|
{...props}
|
||||||
|
class={twMerge('avatar', clsx(className))}
|
||||||
|
class:avatar-online={presence === 'online'}
|
||||||
|
class:avatar-offline={presence === 'offline'}
|
||||||
|
class:avatar-placeholder={placeholder}
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
class={twMerge(
|
class={twMerge(
|
||||||
'rounded-xl',
|
'rounded-xl',
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import type { Snippet } from 'svelte';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
children?: Snippet;
|
||||||
|
};
|
||||||
|
|
||||||
|
let { children }: Props = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="avatar-group -space-x-6">
|
||||||
|
{@render children?.()}
|
||||||
|
</div>
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export { default as Accordion } from './Accordion.svelte';
|
export { default as Accordion } from './Accordion.svelte';
|
||||||
export { default as Avatar } from './Avatar.svelte';
|
export { default as Avatar } from './Avatar.svelte';
|
||||||
|
export { default as AvatarGroup } from './AvatarGroup.svelte';
|
||||||
Loading…
Add table
Reference in a new issue