Skip to content
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
32 changes: 32 additions & 0 deletions svelte/src/lib/components/Placeholder.stories.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script module>
import { defineMeta } from '@storybook/addon-svelte-csf';

import Placeholder from './Placeholder.svelte';

const { Story } = defineMeta({
title: 'Placeholder',
component: Placeholder,
tags: ['autodocs'],
});
</script>

<Story name="Default" args={{ width: '200px', height: '20px' }} />

<Story name="Multiple Lines" asChild>
<div style="display: flex; flex-direction: column; gap: 8px;">
<Placeholder width="100%" height="20px" />
<Placeholder width="80%" height="20px" />
<Placeholder width="90%" height="20px" />
</div>
</Story>

<Story name="Card" asChild>
<div style="display: flex; gap: 16px; align-items: flex-start;">
<Placeholder width="80px" height="80px" radius="8px" style="flex-shrink: 0;" />
<div style="display: flex; flex-direction: column; gap: 8px; flex: 1;">
<Placeholder width="60%" height="24px" />
<Placeholder width="100%" height="16px" />
<Placeholder width="40%" height="16px" />
</div>
</div>
</Story>
51 changes: 51 additions & 0 deletions svelte/src/lib/components/Placeholder.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script lang="ts">
import type { HTMLAttributes } from 'svelte/elements';

interface Props extends HTMLAttributes<HTMLDivElement> {
width: string;
height: string;
radius?: string;
opacity?: number;
}

let { width, height, radius = 'var(--space-3xs)', opacity = 0.35, class: className, ...restProps }: Props = $props();
</script>

<div
class={['placeholder', className]}
style:width
style:height
style:border-radius={radius}
style:opacity
{...restProps}
></div>

<style>
.placeholder {
position: relative;
display: block;
overflow: hidden;
background: linear-gradient(
to right,
var(--placeholder-bg) 8%,
var(--placeholder-bg2) 16%,
var(--placeholder-bg) 29%
);
background-size: 1200px 100%;
animation-name: backgroundAnimation;
animation-duration: 1.5s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-fill-mode: forwards;
}

@keyframes backgroundAnimation {
0% {
background-position: -500px;
}

100% {
background-position: 500px;
}
}
</style>