Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: avatar component #52

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/docs/components/ComponentCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
const { component }: Props = $props();
</script>

<Button href={asComponentHref(component.name)} variant="outline" color="primary" class="h-24 w-40">
<VStack gap={2} class="p-6">
<Icon icon={component.icon} size="2em" />
<Button
href={asComponentHref(component.name)}
variant="outline"
color="secondary"
class="h-24 w-40"
size="large"
>
<VStack gap={2}>
<Icon icon={component.icon} size="3rem" />
<Heading size="tiny">{component.name}</Heading>
</VStack>
</Button>
4 changes: 3 additions & 1 deletion src/docs/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
mdiAccountCircle,
mdiAlertCircleOutline,
mdiApplicationOutline,
mdiButtonCursor,
Expand Down Expand Up @@ -79,8 +80,9 @@ export const componentGroups = [
],
},
{
title: 'Immich',
title: 'Miscellaneous',
components: [
{ name: 'Avatar', icon: mdiAccountCircle },
{ name: 'Logo', icon: mdiImage },
{ name: 'SupporterBadge', icon: mdiPartyPopper },
],
Expand Down
66 changes: 66 additions & 0 deletions src/lib/components/Avatar/Avatar.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script lang="ts">
import type { Size } from '$lib/types.js';
import { tv } from 'tailwind-variants';

type Props = {
size?: Size;
color?:
| 'primary'
| 'pink'
| 'red'
| 'yellow'
| 'blue'
| 'green'
| 'purple'
| 'orange'
| 'gray'
| 'amber';
name: string;
};

const { color = 'primary', size = 'medium', name }: Props = $props();

const styles = tv({
base: 'flex h-full w-full select-none items-center justify-center font-medium',
variants: {
size: {
tiny: 'w-5 h-5 text-xs',
small: 'w-7 h-7 text-sm',
medium: 'w-10 h-10 text-md',
large: 'w-12 h-12 text-lg',
giant: 'w-16 h-16 text-xl',
},
color: {
primary: 'bg-primary text-light',
pink: 'bg-pink-400 text-light',
red: 'bg-red-500 text-light',
yellow: 'bg-yellow-500 text-light',
purple: 'bg-purple-600 text-dark',
orange: 'bg-orange-600 text-light',
gray: 'bg-gray-600 text-dark',
amber: 'bg-amber-600 text-light',
blue: 'bg-blue-500 text-dark',
green: 'bg-green-600 text-dark',
},
},
});

const wrapper = tv({
base: 'overflow-hidden shadow-md rounded rounded-full',
});

const getInitials = (name: string) => {
return name
.split(' ')
.map((part) => part.at(0))
.join('')
.substr(0, 2)
.toUpperCase();
};

const initials = $derived(getInitials(name));
</script>

<figure class={wrapper()}>
<span class={styles({ size, color })}>{initials}</span>
</figure>
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { default as Alert } from '$lib/components/Alert/Alert.svelte';
export { default as AppShell } from '$lib/components/AppShell/AppShell.svelte';
export { default as AppShellHeader } from '$lib/components/AppShell/AppShellHeader.svelte';
export { default as AppShellSidebar } from '$lib/components/AppShell/AppShellSidebar.svelte';
export { default as Avatar } from '$lib/components/Avatar/Avatar.svelte';
export { default as Button } from '$lib/components/Button/Button.svelte';
export { default as Card } from '$lib/components/Card/Card.svelte';
export { default as CardBody } from '$lib/components/Card/CardBody.svelte';
Expand Down
7 changes: 2 additions & 5 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ComponentCard from '$docs/components/ComponentCard.svelte';
import Grid from '$docs/components/Grid.svelte';
import { componentGroups } from '$docs/constants.js';
import { Heading, Link, Stack, Text } from '@immich/ui';
import { Code, Heading, Link, Stack, Text } from '@immich/ui';
</script>

<div class="max-w-screen-lg p-2">
Expand All @@ -16,10 +16,7 @@

<Heading size="large">Install</Heading>
<Text>@immich/ui is published as an npm package. You can install it using npm.</Text>

<div class="py-4">
<code class="rounded-lg border border-dark p-4">npm i --save-dev @immich/ui</code>
</div>
<Code color="secondary">npm i --save-dev @immich/ui</Code>

<Heading size="large">Components</Heading>
<Stack gap={8}>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/components/alert/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

const examples = [
{ title: 'Basic', code: basicExample, component: BasicExample },
{ title: 'Colors', code: colorExample, component: ColorExample },
{ title: 'Color', code: colorExample, component: ColorExample },
{ title: 'Custom Icon', code: customIconExample, component: CustomIconExample },
];
</script>
Expand Down
17 changes: 17 additions & 0 deletions src/routes/components/avatar/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script lang="ts">
import ExampleLayout from '$docs/components/ExampleLayout.svelte';
import BasicExample from './BasicExample.svelte';
import basicExample from './BasicExample.svelte?raw';
import ColorExample from './ColorExample.svelte';
import colorExample from './ColorExample.svelte?raw';
import SizeExample from './SizeExample.svelte';
import sizeExample from './SizeExample.svelte?raw';

const examples = [
{ title: 'Basic', code: basicExample, component: BasicExample },
{ title: 'Color', code: colorExample, component: ColorExample },
{ title: 'Size', code: sizeExample, component: SizeExample },
];
</script>

<ExampleLayout name="Avatar" {examples} />
7 changes: 7 additions & 0 deletions src/routes/components/avatar/BasicExample.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script lang="ts">
import { Avatar, HStack } from '@immich/ui';
</script>

<HStack>
<Avatar name="Immich User" />
</HStack>
16 changes: 16 additions & 0 deletions src/routes/components/avatar/ColorExample.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script lang="ts">
import { Avatar, HStack } from '@immich/ui';
</script>

<HStack>
<Avatar color="primary" name="Immich User" />
<Avatar color="gray" name="Immich User" />
<Avatar color="purple" name="Immich User" />
<Avatar color="blue" name="Immich User" />
<Avatar color="green" name="Immich User" />
<Avatar color="yellow" name="Immich User" />
<Avatar color="amber" name="Immich User" />
<Avatar color="orange" name="Immich User" />
<Avatar color="red" name="Immich User" />
<Avatar color="pink" name="Immich User" />
</HStack>
11 changes: 11 additions & 0 deletions src/routes/components/avatar/SizeExample.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script lang="ts">
import { Avatar, HStack } from '@immich/ui';
</script>

<HStack>
<Avatar size="tiny" name="Immich User" />
<Avatar size="small" name="Immich User" />
<Avatar size="medium" name="Immich User" />
<Avatar size="large" name="Immich User" />
<Avatar size="giant" name="Immich User" />
</HStack>
2 changes: 1 addition & 1 deletion src/routes/components/loading-spinner/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const examples = [
{ title: 'Sizes', code: sizeExample, component: SizeExample },
{ title: 'Colors', code: colorExample, component: ColorExample },
{ title: 'Color', code: colorExample, component: ColorExample },
];
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/routes/components/switch/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

const examples = [
{ title: 'Basic', code: basicExample, component: BasicExample },
{ title: 'Colors', code: colorExample, component: ColorExample },
{ title: 'Color', code: colorExample, component: ColorExample },
{ title: 'Form', code: formExample, component: FormExample },
];
</script>
Expand Down
Loading