Skip to content

Commit 72ac67c

Browse files
Add skeleton component (#161)
Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
1 parent 3d9ad64 commit 72ac67c

File tree

8 files changed

+99
-0
lines changed

8 files changed

+99
-0
lines changed

component.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"preview/src/components/aspect_ratio",
3535
"preview/src/components/scroll_area",
3636
"preview/src/components/date_picker",
37+
"preview/src/components/skeleton",
3738
"preview/src/components/card"
3839
]
3940
}

preview/src/components/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ examples!(
8181
scroll_area,
8282
select,
8383
separator,
84+
skeleton,
8485
slider,
8586
switch,
8687
tabs,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "skeleton",
3+
"description": "A placeholder component for all loading elements.",
4+
"authors": [
5+
"zhiyanzhaijie"
6+
],
7+
"exclude": [
8+
"variants",
9+
"docs.md",
10+
"component.json"
11+
],
12+
"cargoDependencies": [
13+
{
14+
"name": "dioxus-primitives",
15+
"git": "https://github.com/DioxusLabs/components"
16+
}
17+
],
18+
"globalAssets": [
19+
"../../../assets/dx-components-theme.css"
20+
]
21+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use dioxus::prelude::*;
2+
3+
#[component]
4+
pub fn Skeleton(#[props(extends=GlobalAttributes)] attributes: Vec<Attribute>) -> Element {
5+
rsx! {
6+
document::Link { rel: "stylesheet", href: asset!("./style.css") }
7+
div { class: "skeleton", ..attributes }
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
The Skeleton component is used to display a placeholder preview of content before the data gets loaded. This helps improve perceived performance and provides users with a visual indication that content is being loaded.
2+
3+
## Component Structure
4+
5+
```rust
6+
Skeleton {
7+
// Accepts all GlobalAttributes, commonly used with style for sizing
8+
style: "width: 15rem; height: 1rem;",
9+
}
10+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod component;
2+
pub use component::*;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.skeleton {
2+
background-color: var(--primary-color-5);
3+
border-radius: 0.375rem;
4+
animation: skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
5+
}
6+
7+
@keyframes skeleton-pulse {
8+
9+
0%,
10+
100% {
11+
opacity: 1;
12+
}
13+
14+
61.8% {
15+
opacity: 0.5;
16+
}
17+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use super::super::component::*;
2+
use dioxus::prelude::*;
3+
4+
#[component]
5+
pub fn Demo() -> Element {
6+
rsx! {
7+
div { style: "display: flex; flex-direction: column; align-items: center; gap: 2rem;",
8+
SkeletonInfoDemo {}
9+
SkeletonCardDemo {}
10+
}
11+
}
12+
}
13+
14+
#[component]
15+
fn SkeletonInfoDemo() -> Element {
16+
rsx! {
17+
div { style: "display: flex; align-items: center; gap: 1rem;",
18+
Skeleton { style: "width: 3rem; height: 3rem; border-radius: 50%;" }
19+
div { style: "display: flex; flex-direction: column; gap: 0.5rem;",
20+
Skeleton { style: "width: 11.625rem; height: 1rem;" }
21+
Skeleton { style: "width: 8.5rem; height: 1rem;" }
22+
}
23+
}
24+
}
25+
}
26+
27+
#[component]
28+
fn SkeletonCardDemo() -> Element {
29+
rsx! {
30+
div { style: "display: flex; flex-direction: column; gap: 0.75rem;",
31+
Skeleton { style: "width: 15rem; height: 8rem; border-radius: 0.75rem;" }
32+
div { style: "display: flex; flex-direction: column; gap: 0.5rem;",
33+
Skeleton { style: "width: 15.625rem; height: 1rem;" }
34+
Skeleton { style: "width: 12.5rem; height: 1rem;" }
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)