Skip to content

Commit 4fcaf3a

Browse files
committed
svelte: Port Placeholder component from Ember
1 parent 366aa96 commit 4fcaf3a

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script module>
2+
import { defineMeta } from '@storybook/addon-svelte-csf';
3+
4+
import Placeholder from './Placeholder.svelte';
5+
6+
const { Story } = defineMeta({
7+
title: 'Placeholder',
8+
component: Placeholder,
9+
tags: ['autodocs'],
10+
});
11+
</script>
12+
13+
<Story name="Default" args={{ width: '200px', height: '20px' }} />
14+
15+
<Story name="Multiple Lines" asChild>
16+
<div style="display: flex; flex-direction: column; gap: 8px;">
17+
<Placeholder width="100%" height="20px" />
18+
<Placeholder width="80%" height="20px" />
19+
<Placeholder width="90%" height="20px" />
20+
</div>
21+
</Story>
22+
23+
<Story name="Card" asChild>
24+
<div style="display: flex; gap: 16px; align-items: flex-start;">
25+
<Placeholder width='80px' height='80px' radius='8px' style="flex-shrink: 0;" />
26+
<div style="display: flex; flex-direction: column; gap: 8px; flex: 1;">
27+
<Placeholder width='60%' height='24px' />
28+
<Placeholder width='100%' height='16px' />
29+
<Placeholder width='40%' height='16px' />
30+
</div>
31+
</div>
32+
</Story>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script lang="ts">
2+
import type { HTMLAttributes } from 'svelte/elements';
3+
4+
interface Props extends HTMLAttributes<HTMLDivElement> {
5+
width: string;
6+
height: string;
7+
radius?: string;
8+
opacity?: number;
9+
}
10+
11+
let {
12+
width,
13+
height,
14+
radius = 'var(--space-3xs)',
15+
opacity = 0.35,
16+
class: className,
17+
...restProps
18+
}: Props = $props();
19+
</script>
20+
21+
<div
22+
class={['placeholder', className]}
23+
style:width
24+
style:height
25+
style:border-radius={radius}
26+
style:opacity
27+
{...restProps}
28+
></div>
29+
30+
<style>
31+
.placeholder {
32+
position: relative;
33+
display: block;
34+
overflow: hidden;
35+
background: linear-gradient(
36+
to right,
37+
var(--placeholder-bg) 8%,
38+
var(--placeholder-bg2) 16%,
39+
var(--placeholder-bg) 29%
40+
);
41+
background-size: 1200px 100%;
42+
animation-name: backgroundAnimation;
43+
animation-duration: 1.5s;
44+
animation-timing-function: linear;
45+
animation-iteration-count: infinite;
46+
animation-fill-mode: forwards;
47+
}
48+
49+
@keyframes backgroundAnimation {
50+
0% {
51+
background-position: -500px;
52+
}
53+
54+
100% {
55+
background-position: 500px;
56+
}
57+
}
58+
</style>

0 commit comments

Comments
 (0)