use aura_ui::prelude::*;
use std::time::Duration;
struct Vitrina {
abierto: bool,
}
fn tarjeta(titulo: &str, sombra: impl Into<Shadows>) -> Div {
div()
.w(px(120.0))
.h(px(80.0))
.center()
.rounded_xl()
.bg(Token::ElevatedSurface)
.shadow(sombra)
.child(titulo.to_owned())
}
impl View for Vitrina {
fn view(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let muelle = Animation::new(Duration::from_millis(600)).easing(Easing::SPRING);
let desplazamiento = cx.transition("panel", if self.abierto { 180.0 } else { 0.0 }, muelle);
let pulso =
cx.animate("pulso", Animation::new(Duration::from_millis(900)).easing(Easing::EaseInOut).ping_pong());
let entrada = Animation::new(Duration::from_millis(500)).easing(Easing::STANDARD);
let fondo = cx.animate_between(
"fondo",
entrada,
Rgba { r: 0.2, g: 0.4, b: 1.0, a: 0.0 },
Rgba { r: 0.2, g: 0.4, b: 1.0, a: 1.0 },
);
div()
.page()
.items_start()
.gap_6()
.p_6()
.child(
div()
.flex_row()
.flex_wrap()
.gap_6()
.child(tarjeta("xs", ShadowPreset::Xs))
.child(tarjeta("md", ShadowPreset::Md))
.child(tarjeta("2xl", ShadowPreset::Xxl))
.child(tarjeta(
"capas",
Shadows::one(BoxShadow::new(0.0, 4.0, 6.0).spread(-1.0).strength(0.5))
.with(BoxShadow::new(0.0, 12.0, 24.0).spread(-4.0).strength(0.6)),
))
.child(tarjeta("color", BoxShadow::new(0.0, 8.0, 20.0).color(fondo))),
)
.child(
div()
.w(px(16.0))
.h(px(16.0))
.rounded_full()
.bg(Token::Accent)
.opacity(0.4 + 0.6 * pulso)
.glow(Token::Accent, 4.0 + 12.0 * pulso),
)
.child(
Button::new(if self.abierto { "Cerrar" } else { "Abrir" })
.on_click(cx.toggle(|this| &mut this.abierto)),
)
.child(
div()
.ml(px(desplazamiento))
.w(px(160.0))
.p_4()
.rounded_lg()
.bg(fondo)
.shadow_lg()
.child("Panel con muelle"),
)
}
}
aura_ui::app!(AppOptions::new("Vitrina").size(760.0, 520.0), Vitrina { abierto: false });