Colocate element stories with their elements

This commit is contained in:
Marshall Bowers 2023-10-10 16:00:04 -04:00
parent 30088afa89
commit f2ee61553f
16 changed files with 379 additions and 364 deletions

View file

@ -108,3 +108,33 @@ impl<S: 'static + Send + Sync> Input<S> {
)
}
}
#[cfg(feature = "stories")]
pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use crate::Story;
use super::*;
#[derive(Element)]
pub struct InputStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
impl<S: 'static + Send + Sync + Clone> InputStory<S> {
pub fn new() -> Self {
Self {
state_type: PhantomData,
}
}
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
Story::container(cx)
.child(Story::title_for::<_, Input<S>>(cx))
.child(Story::label(cx, "Default"))
.child(div().flex().child(Input::new("Search")))
}
}
}