Skip to content

Commit e99d83c

Browse files
authored
svelte: Port Placeholder component from Ember (#12562)
1 parent 366aa96 commit e99d83c

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 { width, height, radius = 'var(--space-3xs)', opacity = 0.35, class: className, ...restProps }: Props = $props();
12+
</script>
13+
14+
<div
15+
class={['placeholder', className]}
16+
style:width
17+
style:height
18+
style:border-radius={radius}
19+
style:opacity
20+
{...restProps}
21+
></div>
22+
23+
<style>
24+
.placeholder {
25+
position: relative;
26+
display: block;
27+
overflow: hidden;
28+
background: linear-gradient(
29+
to right,
30+
var(--placeholder-bg) 8%,
31+
var(--placeholder-bg2) 16%,
32+
var(--placeholder-bg) 29%
33+
);
34+
background-size: 1200px 100%;
35+
animation-name: backgroundAnimation;
36+
animation-duration: 1.5s;
37+
animation-timing-function: linear;
38+
animation-iteration-count: infinite;
39+
animation-fill-mode: forwards;
40+
}
41+
42+
@keyframes backgroundAnimation {
43+
0% {
44+
background-position: -500px;
45+
}
46+
47+
100% {
48+
background-position: 500px;
49+
}
50+
}
51+
</style>

0 commit comments

Comments
 (0)