Skip to main content

tablo_ui/components/primitives/
skeleton.rs

1// SYNC: topcoat-ui-registry@0.12.1 sha256:dfb151741d3c08c9312967d20eb1d6c513916b764e73af034a1904ae9ce37a3d — do not hand-edit. Sync via `cargo xtask sync-topcoat-ui` (ADR-0007).
2use topcoat::{
3    Result,
4    context::Cx,
5    view::{Attributes, StaticClass, View, class, component, view},
6};
7
8/// Classes for a pulsing placeholder with a muted background.
9const SKELETON: StaticClass = class!("animate-pulse rounded-md bg-foreground/10");
10
11/// A pulsing placeholder for content that is loading.
12///
13/// Set its dimensions through classes in `attrs`. Match the expected content's shape to
14/// reduce layout movement when it arrives. Attributes are forwarded to the `<div>`,
15/// with extra classes added to its classes.
16///
17/// ```ignore
18/// view! {
19///     <div class="flex flex-col gap-2">
20///         skeleton(attrs: attributes! { class="h-4 w-32" })
21///         skeleton(attrs: attributes! { class="h-4 w-full" })
22///     </div>
23/// }
24/// ```
25#[component]
26pub async fn skeleton(cx: &Cx, #[default] mut attrs: Attributes) -> Result<impl View> {
27    Ok(view! { <div class=(class!(SKELETON, attrs.remove("class"))) (attrs)></div> })
28}