Skip to content

Commit

Permalink
feat: supporter badge (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 authored Nov 18, 2024
1 parent 9ce9104 commit 378559c
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/docs/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ export const routes: Route[] = [
{ name: 'Link', link: '/examples/link' },
{ name: 'Logo', link: '/examples/logo' },
{ name: 'Stack', link: '/examples/stack' },
{ name: 'SupporterBadge', link: '/examples/supporter-badge' },
{ name: 'Text', link: '/examples/text' },
];
15 changes: 8 additions & 7 deletions src/lib/components/Heading/Heading.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
size: HeadingSize;
color?: Color;
class?: string;
children: Snippet;
};
Expand All @@ -23,7 +24,7 @@
};
const styles = tv({
base: 'leading-none tracking-tight',
base: 'font-bold leading-none tracking-tight',
variants: {
color: {
primary: 'text-primary',
Expand All @@ -34,12 +35,12 @@
info: 'text-info',
},
size: {
tiny: 'text-lg font-bold',
small: 'text-xl font-bold',
medium: 'text-2xl font-bold',
large: 'text-3xl font-bold',
giant: 'text-4xl font-bold',
title: 'text-5xl font-bold',
tiny: 'text-lg',
small: 'text-xl',
medium: 'text-2xl',
large: 'text-3xl',
giant: 'text-4xl',
title: 'text-5xl',
},
},
});
Expand Down
94 changes: 94 additions & 0 deletions src/lib/components/SupporterBadge/SupporterBadge.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<script lang="ts">
import Logo from '$lib/components/Logo/Logo.svelte';
import Text from '$lib/components/Text/Text.svelte';
import type { Size } from '$lib/types.js';
import { cleanClass } from '$lib/utils.js';
import type { Snippet } from 'svelte';
import { tv } from 'tailwind-variants';
type Props = {
effect?: 'hover' | 'always';
text?: string;
size?: Size;
children?: Snippet;
};
const { effect = 'hover', text = 'Supporter', size = 'medium', children }: Props = $props();
const iconSize: Record<Size, Size> = {
tiny: 'tiny',
small: 'tiny',
medium: 'small',
large: 'medium',
giant: 'medium',
};
const containerStyles = tv({
base: 'bg-secondary flex place-items-center gap-2 overflow-hidden rounded-lg transition-all',
variants: {
size: {
tiny: 'px-2 py-1',
small: 'px-2 py-1',
medium: 'px-3 py-2',
large: 'px-3 py-2',
giant: 'px-3 py-2',
},
effect: {
hover: 'border border-dark/25 supporter-effect-hover',
always: 'shadow supporter-effect',
},
},
});
</script>

<div class={cleanClass(containerStyles({ effect, size }))}>
{#if children}
{@render children()}
{:else}
<Logo size={iconSize[size]} variant="icon" />
<Text fontWeight="normal" color="secondary" {size}>{text}</Text>
{/if}
</div>

<style>
.supporter-effect,
.supporter-effect-hover:hover {
position: relative;
background-clip: padding-box;
animation: gradient 10s ease infinite;
z-index: 1;
}
.supporter-effect:after,
.supporter-effect-hover:hover:after {
position: absolute;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
background: linear-gradient(
to right,
rgba(16, 132, 254, 0.15),
rgba(229, 125, 175, 0.15),
rgba(254, 36, 29, 0.15),
rgba(255, 183, 0, 0.15),
rgba(22, 193, 68, 0.15)
);
content: '';
animation: gradient 10s ease infinite;
background-size: 400% 400%;
z-index: -1;
}
@keyframes gradient {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
</style>
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as Heading } from '$lib/components/Heading/Heading.svelte';
export { default as Icon } from '$lib/components/Icon/Icon.svelte';
export { default as IconButton } from '$lib/components/IconButton/IconButton.svelte';
export { default as Link } from '$lib/components/Link/Link.svelte';
export { default as SupporterBadge } from '$lib/components/SupporterBadge/SupporterBadge.svelte';
export { default as Logo } from '$lib/components/Logo/Logo.svelte';
export { default as HStack } from '$lib/components/Stack/HStack.svelte';
export { default as Stack } from '$lib/components/Stack/Stack.svelte';
Expand Down
60 changes: 60 additions & 0 deletions src/routes/examples/supporter-badge/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script lang="ts">
import DualThemeLayout from '$docs/components/DualThemeLayout.svelte';
import { sizes } from '$docs/constants.js';
import Heading from '$lib/components/Heading/Heading.svelte';
import { Card, CardBody, CardHeader, CardTitle, Logo, SupporterBadge, VStack } from '@immich/ui';
</script>

<DualThemeLayout name="Link">
{#snippet component()}
<Card>
<CardHeader>
<CardTitle>Effect</CardTitle>
</CardHeader>
<CardBody>
<VStack class="w-[200px]">
<Heading size="tiny">On Hover</Heading>
<SupporterBadge />
<Heading size="tiny">Always</Heading>
<SupporterBadge effect="always" />
</VStack>
</CardBody>
</Card>
<Card>
<CardHeader>
<CardTitle>Sizes</CardTitle>
</CardHeader>
<CardBody>
<VStack>
{#each sizes as size}
<VStack class="w-[250px]">
<Heading size="tiny" class="capitalize">{size}</Heading>
<SupporterBadge {size} effect="always" />
</VStack>
{/each}
</VStack>
</CardBody>
</Card>

<Card>
<CardHeader>
<CardTitle>Custom</CardTitle>
</CardHeader>
<CardBody>
<VStack>
<VStack class="w-[250px]">
<SupporterBadge effect="always" text="Buy Immich" />
</VStack>

<VStack>
<Heading size="tiny">Title</Heading>
<SupporterBadge effect="always">
<Logo size="large" variant="icon" />
<Heading size="large" color="primary">Purchase Immich</Heading>
</SupporterBadge>
</VStack>
</VStack>
</CardBody>
</Card>
{/snippet}
</DualThemeLayout>

0 comments on commit 378559c

Please sign in to comment.