Add an example of colocating a story for a UI component with its definition

This commit is contained in:
Marshall Bowers 2023-10-10 15:30:16 -04:00
parent 5b7ca6435c
commit b1d88ced61
9 changed files with 95 additions and 83 deletions

View file

@ -88,3 +88,33 @@ impl<S: 'static + Send + Sync + Clone> AssistantPanel<S> {
.width(AbsoluteLength::Rems(rems(32.)))
}
}
#[cfg(feature = "stories")]
pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use crate::story::Story;
use super::*;
#[derive(Element)]
pub struct AssistantPanelStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
impl<S: 'static + Send + Sync + Clone> AssistantPanelStory<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::<_, AssistantPanel<S>>(cx))
.child(Story::label(cx, "Default"))
.child(AssistantPanel::new())
}
}
}