Colocate component stories with their components

This commit is contained in:
Marshall Bowers 2023-10-10 15:52:58 -04:00
parent b1d88ced61
commit 30088afa89
52 changed files with 1085 additions and 1012 deletions

View file

@ -30,3 +30,42 @@ impl<S: 'static + Send + Sync> Facepile<S> {
div().p_1().flex().items_center().children(player_list)
}
}
#[cfg(feature = "stories")]
pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use crate::{static_players, Story};
use super::*;
#[derive(Element)]
pub struct FacepileStory<S: 'static + Send + Sync> {
state_type: PhantomData<S>,
}
impl<S: 'static + Send + Sync> FacepileStory<S> {
pub fn new() -> Self {
Self {
state_type: PhantomData,
}
}
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
let players = static_players();
Story::container(cx)
.child(Story::title_for::<_, Facepile<S>>(cx))
.child(Story::label(cx, "Default"))
.child(
div()
.flex()
.gap_3()
.child(Facepile::new(players.clone().into_iter().take(1)))
.child(Facepile::new(players.clone().into_iter().take(2)))
.child(Facepile::new(players.clone().into_iter().take(3))),
)
}
}
}