Factor story boilerplate out into separate components (#3016)

This PR factors out the bulk of the boilerplate required to setup a
story in the storybook out into separate components.

The pattern we're using here is adapted from the "[associated
component](https://maxdeviant.com/posts/2021/react-associated-components/)"
pattern in React.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-09-22 11:38:01 -04:00 committed by GitHub
parent afa7045847
commit d8c6adf338
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 55 deletions

View file

@ -2,6 +2,7 @@
mod collab_panel;
mod stories;
mod story;
mod workspace;
use std::str::FromStr;
@ -24,12 +25,12 @@ gpui2::actions! {
}
#[derive(Debug, Clone, Copy)]
enum Story {
enum StorySelector {
Element(ElementStory),
Component(ComponentStory),
}
impl FromStr for Story {
impl FromStr for StorySelector {
type Err = anyhow::Error;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
@ -55,7 +56,7 @@ enum ComponentStory {
#[derive(Parser)]
struct Args {
story: Option<Story>,
story: Option<StorySelector>,
}
fn main() {
@ -79,13 +80,13 @@ fn main() {
..Default::default()
},
|cx| match args.story {
Some(Story::Element(ElementStory::Avatar)) => {
Some(StorySelector::Element(ElementStory::Avatar)) => {
view(|cx| render_story(&mut ViewContext::new(cx), AvatarStory::default()))
}
Some(Story::Component(ComponentStory::Facepile)) => {
Some(StorySelector::Component(ComponentStory::Facepile)) => {
view(|cx| render_story(&mut ViewContext::new(cx), FacepileStory::default()))
}
Some(Story::Component(ComponentStory::TrafficLights)) => view(|cx| {
Some(StorySelector::Component(ComponentStory::TrafficLights)) => view(|cx| {
render_story(&mut ViewContext::new(cx), TrafficLightsStory::default())
}),
None => {