Skeleton

Rust UI component that show a placeholder while content is loading.

  • Rust UI Icons - CopyCopy Demo
use leptos::prelude::*;

use crate::components::ui::skeleton::Skeleton;

#[component]
pub fn DemoSkeleton() -> impl IntoView {
    view! {
        <div class="flex flex-col space-y-3">
            <Skeleton class="rounded-xl h-[125px] w-[250px]" />
            <div class="space-y-2">
                <Skeleton class="h-4 w-[250px]" />
                <Skeleton class="h-4 w-[200px]" />
            </div>
        </div>
    }
}

Installation

You can run either of the following commands:

# cargo install ui-cli --force
ui add demo_skeleton
ui add skeleton

Update the imports to match your project setup.

Copy and paste the following code into your project:

components/ui/skeleton.rs

use leptos::prelude::*;
use leptos_ui::div;

const PULSE_ANIMATION: &str = "animate-pulse";

// TODO UI. Skeleton should be able to receive children (or not).

mod components {
    use super::*;
    div! {Skeleton, PULSE_ANIMATION, "rounded-md bg-muted"}
}

pub use components::*;

Update the imports to match your project setup.

Usage

use crate::components::ui::skeleton::Skeleton;
<Skeleton class="w-[100px] h-[20px]" />

Examples

1. Skeleton Image

  • Rust UI Icons - CopyCopy Demo
Rust UI Icons - Image
Loading...
use icons::Image;
use leptos::prelude::*;

use crate::components::ui::skeleton::Skeleton;

// TODO UI.

#[component]
pub fn DemoSkeletonImage() -> impl IntoView {
    view! {
        <div class="m-4 space-y-8 w-full md:flex md:items-center md:space-y-0 md:space-x-8 rtl:space-x-reverse">

            // TODO UI. Skeleton should be able to receive children (or not).
            <div class="flex justify-center items-center w-full h-48 rounded-lg animate-pulse sm:w-96 bg-muted">
                <Image class="text-muted-foreground size-10" />
            </div>

            <div class="space-y-2 w-full">
                <Skeleton class="h-4" />
                <Skeleton class="h-4 w-[80%]" />
                <Skeleton class="h-4 w-[80%]" />
                <Skeleton class="h-4 w-[80%]" />
            </div>
            <span class="sr-only">Loading...</span>
        </div>
    }
}