pub struct Skeleton { /* private fields */ }yew only.Expand description
Skeleton Component
A flexible and customizable Skeleton component for Yew applications, ideal for
rendering placeholder content during loading states. It provides support for
animations, visibility-based rendering, and responsive behavior.
§Properties
The component uses the SkeletonProps struct for its properties. Key properties include:
§Features
-
Viewport-aware Animation: When
animate_on_visibleis enabled, the component usesIntersectionObserverto trigger animation only when scrolled into view. -
Delay Support: Prevents immediate rendering using the
delay_msprop, useful for avoiding flash of skeletons for fast-loading content. -
Responsive Layout: With the
responsiveprop, skeletons scale naturally across screen sizes. -
State-controlled Rendering: You can explicitly show or hide the skeleton using the
showprop or control visibility dynamically. -
Slot Support: You can pass children to be wrapped in the skeleton effect, especially useful for text or UI blocks.
§Examples
§Basic Usage
use yew::prelude::*;
use skeleton_rs::yew::{Skeleton, SkeletonGroup};
use skeleton_rs::{Animation, Theme, Variant};
#[function_component(App)]
pub fn app() -> Html {
html! {
<Skeleton width="200px" height="1.5em" />
}
}§Text Placeholder
use yew::prelude::*;
use skeleton_rs::yew::{Skeleton, SkeletonGroup};
use skeleton_rs::{Animation, Theme, Variant};
#[function_component(App)]
pub fn app() -> Html {
html! {
<Skeleton variant={Variant::Text} width="100%" height="1.2em" />
}
}§Responsive with Inferred Size
use yew::prelude::*;
use skeleton_rs::yew::{Skeleton, SkeletonGroup};
use skeleton_rs::{Animation, Theme, Variant};
#[function_component(App)]
pub fn app() -> Html {
html! {
<Skeleton infer_size={true} responsive={true}>
<p>{ "Loading text..." }</p>
</Skeleton>
}
}§Animate When Visible
use yew::prelude::*;
use skeleton_rs::yew::{Skeleton, SkeletonGroup};
use skeleton_rs::{Animation, Theme, Variant};
#[function_component(App)]
pub fn app() -> Html {
html! {
<Skeleton
variant={Variant::Text}
animate_on_visible={true}
height="2em"
width="80%"
/>
}
}§Behavior
- When
animate_on_visibleis enabled, animation starts only once the component enters the viewport. - If
showis set tofalse, the component initializes hidden and reveals itself based on internal or external logic. - You can customize almost all styles using props.
§Accessibility
- Skeletons typically represent non-interactive placeholders and do not interfere with screen readers.
- Consider pairing them with appropriate ARIA
aria-busy,aria-hidden, or live regions on the parent container for accessibility.
§Notes
- The component uses
NodeRefinternally to observe visibility changes. - The
childrenprop allows rendering actual elements inside the skeleton, which get masked by the animation.
§See Also
Trait Implementations§
Source§impl BaseComponent for Skeletonwhere
Self: 'static,
impl BaseComponent for Skeletonwhere
Self: 'static,
Source§type Properties = SkeletonProps
type Properties = SkeletonProps
Source§fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool
fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool
Source§fn changed(
&mut self,
_ctx: &Context<Self>,
_old_props: &Self::Properties,
) -> bool
fn changed( &mut self, _ctx: &Context<Self>, _old_props: &Self::Properties, ) -> bool
Source§fn view(&self, ctx: &Context<Self>) -> HtmlResult
fn view(&self, ctx: &Context<Self>) -> HtmlResult
Source§fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool)
fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool)
Source§fn prepare_state(&self) -> Option<String>
fn prepare_state(&self) -> Option<String>
Source§impl FunctionProvider for Skeleton
impl FunctionProvider for Skeleton
Source§type Properties = SkeletonProps
type Properties = SkeletonProps
Source§fn run(ctx: &mut HookContext, props: &Self::Properties) -> HtmlResult
fn run(ctx: &mut HookContext, props: &Self::Properties) -> HtmlResult
Auto Trait Implementations§
impl !Freeze for Skeleton
impl !RefUnwindSafe for Skeleton
impl !Send for Skeleton
impl !Sync for Skeleton
impl Unpin for Skeleton
impl !UnwindSafe for Skeleton
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> InitializeFromFunction<T> for T
impl<T> InitializeFromFunction<T> for T
Source§fn initialize_from_function(f: fn() -> T) -> T
fn initialize_from_function(f: fn() -> T) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.