Skeleton
Rust UI component that show a placeholder while content is loading.
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> } }
Demos
1. Skeleton Image
Loading...
use icons::ImageIcon; 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"> <ImageIcon 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> } }
Installation
You can run either of the following commands:
# cargo install ui-cli --forceui add demo_skeletonui 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; use crate::components::ui::_animations::ANIMATIONS; // TODO UI. Skeleton should be able to receive children (or not). mod components { use super::*; div! {Skeleton, ANIMATIONS::PULSE, "rounded-md bg-muted"} } pub use components::*;
Update the imports to match your project setup.
Usage
// Coming soon 🦀