Skeleton RS

Edit Component

Y Skeleton RS Yew Usage

Adding Skeleton RS to your project is simple:

  1. Make sure your project is set up with Yew. Follow their Getting Started Guide for setup instructions.

  2. Add the Skeleton RS component to your dependencies by including it in your Cargo.toml file:

    cargo add skeleton-rs --features=yew
    
  3. Import the Skeleton component into your Yew component and start using it in your app.

🛠️ Usage

Incorporating Skeleton RS into your Yew application is easy. Follow these steps:

  1. Import the Skeleton component into your Yew project:

    use yew::prelude::*;
    use skeleton_rs::yew::Skeleton;
    use skeleton_rs::Variant;
  2. Use the Skeleton component within your Yew application:

    use yew::prelude::*;
    use skeleton_rs::yew::Skeleton;
    use skeleton_rs::Variant;
    
    
    #[function_component(App)]
    pub fn app() -> Html {
        html! {
            <Skeleton
                variant={Variant::Text}
                width="100%"
                height="1.2em"
                animate_on_visible={true}
            />
        }
    }

🔧 Props

PropertyTypeDescriptionDefault
variantVariantVisual variant: Text, Circle, Rect, etc.Text
animationAnimationAnimation style: Pulse, Wave, None.Pulse
directionDirectionAnimation direction: LeftToRight, RightToLeft, TopToBottom, etc.LeftToRight
themeThemeTheme for light/dark variants.Light
showboolManually control visibility of the skeleton.false
delay_msu32Delay before showing the skeleton in milliseconds.0
infer_sizeboolInfers width/height from child content if true.false
responsiveboolEnables scaling for responsive layouts.false
childrenHtmlContent to wrap in skeleton loading.None

🎨 Styling Props

PropertyTypeDescriptionDefault
width&'static strWidth of the skeleton block."100%"
height&'static strHeight of the skeleton block."1em"
font_sizeOption<&str>Font size used for text variant.None
border_radius&'static strBorder radius for rounded shapes."4px"
line_height&'static strLine height of the skeleton block."1"
margin&'static strExternal margin styling.""
custom_style&'static strInline custom styles.""

⚙️ Visibility Behavior

PropertyTypeDescriptionDefault
animate_on_hoverboolStarts animation on hover.false
animate_on_focusboolStarts animation on focus.false
animate_on_activeboolStarts animation on active interaction (e.g., click).false
animate_on_visibleboolUses IntersectionObserver to trigger animation when in view.false

📏 Layout Constraints

PropertyTypeDescriptionDefault
max_widthOption<&str>Max width of the skeleton.None
min_widthOption<&str>Min width of the skeleton.None
max_heightOption<&str>Max height of the skeleton.None
min_heightOption<&str>Min height of the skeleton.None

🧠 DOM Utility

PropertyTypeDescriptionDefault
node_refNodeRefDOM reference used internally (e.g., for visibility tracking).Default

💡 Notes

  • The Skeleton component is primarily designed for loading states and placeholder UI.
  • IntersectionObserver is used when animate_on_visible is enabled to improve performance.
  • You can control the component via the show prop or allow it to handle visibility with internal state.
  • Use infer_size with children when you want the skeleton to match their dimensions.
  • For better performance, delay the appearance of skeletons using delay_ms to avoid flicker.
  • You can use custom_style and class to style it further as needed.

Usage

CLI Usage

You can import Skeleton RS directly into your project to customize and modify it using the opensass cli:

os add skeleton-rs yew