Skip to content
Open
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={{ style: 'width: 200px; height: 20px; border-radius: 4px;' }} />

<Story name="Multiple Lines" asChild>
<div style="display: flex; flex-direction: column; gap: 8px;">
<Placeholder style="width: 100%; height: 20px; border-radius: 4px;" />
<Placeholder style="width: 80%; height: 20px; border-radius: 4px;" />
<Placeholder style="width: 90%; height: 20px; border-radius: 4px;" />
Comment on lines +17 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the example shown, if this scenario is common, I'd prefer providing props or CSS variables over an inline style approach.

</div>
</Story>

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

let { class: className, ...restProps }: HTMLAttributes<HTMLDivElement> = $props();
</script>

<div class="placeholder {className}" {...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>