gpui-component/crates/ui/src/skeleton.rs
Jason Lee ed0887420f
chore: Impl Styled for more elements. (#1007)
This PR for continuing #1005 was missed commits.
2025-06-24 19:36:42 +08:00

57 lines
1.4 KiB
Rust

use crate::{ActiveTheme, StyledExt};
use gpui::{
bounce, div, ease_in_out, Animation, AnimationExt, IntoElement, RenderOnce, StyleRefinement,
Styled,
};
use std::time::Duration;
#[derive(IntoElement)]
pub struct Skeleton {
style: StyleRefinement,
secondary: bool,
}
impl Skeleton {
pub fn new() -> Self {
Self {
style: StyleRefinement::default(),
secondary: false,
}
}
/// Set use secondary color.
pub fn secondary(mut self, secondary: bool) -> Self {
self.secondary = secondary;
self
}
}
impl Styled for Skeleton {
fn style(&mut self) -> &mut gpui::StyleRefinement {
&mut self.style
}
}
impl RenderOnce for Skeleton {
fn render(self, _: &mut gpui::Window, cx: &mut gpui::App) -> impl IntoElement {
div()
.w_full()
.h_4()
.bg(if self.secondary {
cx.theme().skeleton.opacity(0.5)
} else {
cx.theme().skeleton
})
.refine_style(&self.style)
.with_animation(
"skeleton",
Animation::new(Duration::from_secs(2))
.repeat()
.with_easing(bounce(ease_in_out)),
move |this, delta| {
let v = 1.0 - delta * 0.5;
this.opacity(v)
},
)
}
}