ui2: Get component stories compiling again (#3376)

Marshall Bowers created

This PR gets the component stories defined in `ui2` compiling again.

Release Notes:

- N/A

Change summary

crates/ui2/src/components.rs                      |   8 
crates/ui2/src/components/stories.rs              |   8 
crates/ui2/src/components/stories/avatar.rs       |  37 -
crates/ui2/src/components/stories/button.rs       | 297 +++++++---------
crates/ui2/src/components/stories/checkbox.rs     |  93 ++--
crates/ui2/src/components/stories/context_menu.rs | 195 +++++-----
crates/ui2/src/components/stories/icon.rs         |  33 -
crates/ui2/src/components/stories/input.rs        |  27 
crates/ui2/src/components/stories/keybinding.rs   | 110 ++---
crates/ui2/src/components/stories/label.rs        |  45 +-
crates/ui2/src/components/stories/mod.rs          |   1 
11 files changed, 399 insertions(+), 455 deletions(-)

Detailed changes

crates/ui2/src/components.rs 🔗

@@ -12,10 +12,12 @@ mod label;
 mod list;
 mod slot;
 mod stack;
-mod stories;
 mod toggle;
 mod tooltip;
 
+#[cfg(feature = "stories")]
+mod stories;
+
 pub use avatar::*;
 pub use button::*;
 pub use checkbox::*;
@@ -30,6 +32,8 @@ pub use label::*;
 pub use list::*;
 pub use slot::*;
 pub use stack::*;
-pub use stories::*;
 pub use toggle::*;
 pub use tooltip::*;
+
+#[cfg(feature = "stories")]
+pub use stories::*;

crates/ui2/src/components/stories/avatar.rs 🔗

@@ -1,27 +1,22 @@
-#[cfg(feature = "stories")]
-pub use stories::*;
+use gpui::{Div, Render};
 
-#[cfg(feature = "stories")]
-mod stories {
-    use super::*;
-    use crate::Story;
-    use gpui::{Div, Render};
+use crate::prelude::*;
+use crate::{Avatar, Story};
 
-    pub struct AvatarStory;
+pub struct AvatarStory;
 
-    impl Render for AvatarStory {
-        type Element = Div;
+impl Render for AvatarStory {
+    type Element = Div;
 
-        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
-            Story::container(cx)
-                .child(Story::title_for::<Avatar>(cx))
-                .child(Story::label(cx, "Default"))
-                .child(Avatar::new(
-                    "https://avatars.githubusercontent.com/u/1714999?v=4",
-                ))
-                .child(Avatar::new(
-                    "https://avatars.githubusercontent.com/u/326587?v=4",
-                ))
-        }
+    fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
+        Story::container(cx)
+            .child(Story::title_for::<Avatar>(cx))
+            .child(Story::label(cx, "Default"))
+            .child(Avatar::new(
+                "https://avatars.githubusercontent.com/u/1714999?v=4",
+            ))
+            .child(Avatar::new(
+                "https://avatars.githubusercontent.com/u/326587?v=4",
+            ))
     }
 }

crates/ui2/src/components/stories/button.rs 🔗

@@ -1,167 +1,144 @@
-#[cfg(feature = "stories")]
-pub use stories::*;
+use gpui::{rems, Div, Render};
+use strum::IntoEnumIterator;
 
-#[cfg(feature = "stories")]
-mod stories {
-    use super::*;
-    use crate::{h_stack, v_stack, Color, Story};
-    use gpui::{rems, Div, Render};
-    use strum::IntoEnumIterator;
+use crate::prelude::*;
+use crate::{h_stack, v_stack, Button, Icon, IconPosition, Label, Story};
 
-    pub struct ButtonStory;
+pub struct ButtonStory;
 
-    impl Render for ButtonStory {
-        type Element = Div;
+impl Render for ButtonStory {
+    type Element = Div;
 
-        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
-            let states = InteractionState::iter();
+    fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
+        let states = InteractionState::iter();
 
-            Story::container(cx)
-                .child(Story::title_for::<Button>(cx))
-                .child(
-                    div()
-                        .flex()
-                        .gap_8()
-                        .child(
-                            div()
-                                .child(Story::label(cx, "Ghost (Default)"))
-                                .child(h_stack().gap_2().children(states.clone().map(|state| {
-                                    v_stack()
-                                        .gap_1()
-                                        .child(
-                                            Label::new(state.to_string()).color(TextColor::Muted),
-                                        )
-                                        .child(
-                                            Button::new("Label").variant(ButtonVariant::Ghost), // .state(state),
-                                        )
-                                })))
-                                .child(Story::label(cx, "Ghost – Left Icon"))
-                                .child(h_stack().gap_2().children(states.clone().map(|state| {
-                                    v_stack()
-                                        .gap_1()
-                                        .child(
-                                            Label::new(state.to_string()).color(TextColor::Muted),
-                                        )
-                                        .child(
-                                            Button::new("Label")
-                                                .variant(ButtonVariant::Ghost)
-                                                .icon(Icon::Plus)
-                                                .icon_position(IconPosition::Left), // .state(state),
-                                        )
-                                })))
-                                .child(Story::label(cx, "Ghost – Right Icon"))
-                                .child(h_stack().gap_2().children(states.clone().map(|state| {
-                                    v_stack()
-                                        .gap_1()
-                                        .child(
-                                            Label::new(state.to_string()).color(TextColor::Muted),
-                                        )
-                                        .child(
-                                            Button::new("Label")
-                                                .variant(ButtonVariant::Ghost)
-                                                .icon(Icon::Plus)
-                                                .icon_position(IconPosition::Right), // .state(state),
-                                        )
-                                }))),
-                        )
-                        .child(
-                            div()
-                                .child(Story::label(cx, "Filled"))
-                                .child(h_stack().gap_2().children(states.clone().map(|state| {
-                                    v_stack()
-                                        .gap_1()
-                                        .child(
-                                            Label::new(state.to_string()).color(TextColor::Muted),
-                                        )
-                                        .child(
-                                            Button::new("Label").variant(ButtonVariant::Filled), // .state(state),
-                                        )
-                                })))
-                                .child(Story::label(cx, "Filled – Left Button"))
-                                .child(h_stack().gap_2().children(states.clone().map(|state| {
-                                    v_stack()
-                                        .gap_1()
-                                        .child(
-                                            Label::new(state.to_string()).color(TextColor::Muted),
-                                        )
-                                        .child(
-                                            Button::new("Label")
-                                                .variant(ButtonVariant::Filled)
-                                                .icon(Icon::Plus)
-                                                .icon_position(IconPosition::Left), // .state(state),
-                                        )
-                                })))
-                                .child(Story::label(cx, "Filled – Right Button"))
-                                .child(h_stack().gap_2().children(states.clone().map(|state| {
-                                    v_stack()
-                                        .gap_1()
-                                        .child(
-                                            Label::new(state.to_string()).color(TextColor::Muted),
-                                        )
-                                        .child(
-                                            Button::new("Label")
-                                                .variant(ButtonVariant::Filled)
-                                                .icon(Icon::Plus)
-                                                .icon_position(IconPosition::Right), // .state(state),
-                                        )
-                                }))),
-                        )
-                        .child(
-                            div()
-                                .child(Story::label(cx, "Fixed With"))
-                                .child(h_stack().gap_2().children(states.clone().map(|state| {
-                                    v_stack()
-                                        .gap_1()
-                                        .child(
-                                            Label::new(state.to_string()).color(TextColor::Muted),
-                                        )
-                                        .child(
-                                            Button::new("Label")
-                                                .variant(ButtonVariant::Filled)
-                                                // .state(state)
-                                                .width(Some(rems(6.).into())),
-                                        )
-                                })))
-                                .child(Story::label(cx, "Fixed With – Left Icon"))
-                                .child(h_stack().gap_2().children(states.clone().map(|state| {
-                                    v_stack()
-                                        .gap_1()
-                                        .child(
-                                            Label::new(state.to_string()).color(TextColor::Muted),
-                                        )
-                                        .child(
-                                            Button::new("Label")
-                                                .variant(ButtonVariant::Filled)
-                                                // .state(state)
-                                                .icon(Icon::Plus)
-                                                .icon_position(IconPosition::Left)
-                                                .width(Some(rems(6.).into())),
-                                        )
-                                })))
-                                .child(Story::label(cx, "Fixed With – Right Icon"))
-                                .child(h_stack().gap_2().children(states.clone().map(|state| {
-                                    v_stack()
-                                        .gap_1()
-                                        .child(
-                                            Label::new(state.to_string()).color(TextColor::Muted),
-                                        )
-                                        .child(
-                                            Button::new("Label")
-                                                .variant(ButtonVariant::Filled)
-                                                // .state(state)
-                                                .icon(Icon::Plus)
-                                                .icon_position(IconPosition::Right)
-                                                .width(Some(rems(6.).into())),
-                                        )
-                                }))),
-                        ),
-                )
-                .child(Story::label(cx, "Button with `on_click`"))
-                .child(
-                    Button::new("Label")
-                        .variant(ButtonVariant::Ghost)
-                        .on_click(|_, cx| println!("Button clicked.")),
-                )
-        }
+        Story::container(cx)
+            .child(Story::title_for::<Button>(cx))
+            .child(
+                div()
+                    .flex()
+                    .gap_8()
+                    .child(
+                        div()
+                            .child(Story::label(cx, "Ghost (Default)"))
+                            .child(h_stack().gap_2().children(states.clone().map(|state| {
+                                v_stack()
+                                    .gap_1()
+                                    .child(Label::new(state.to_string()).color(Color::Muted))
+                                    .child(
+                                        Button::new("Label").variant(ButtonVariant::Ghost), // .state(state),
+                                    )
+                            })))
+                            .child(Story::label(cx, "Ghost – Left Icon"))
+                            .child(h_stack().gap_2().children(states.clone().map(|state| {
+                                v_stack()
+                                    .gap_1()
+                                    .child(Label::new(state.to_string()).color(Color::Muted))
+                                    .child(
+                                        Button::new("Label")
+                                            .variant(ButtonVariant::Ghost)
+                                            .icon(Icon::Plus)
+                                            .icon_position(IconPosition::Left), // .state(state),
+                                    )
+                            })))
+                            .child(Story::label(cx, "Ghost – Right Icon"))
+                            .child(h_stack().gap_2().children(states.clone().map(|state| {
+                                v_stack()
+                                    .gap_1()
+                                    .child(Label::new(state.to_string()).color(Color::Muted))
+                                    .child(
+                                        Button::new("Label")
+                                            .variant(ButtonVariant::Ghost)
+                                            .icon(Icon::Plus)
+                                            .icon_position(IconPosition::Right), // .state(state),
+                                    )
+                            }))),
+                    )
+                    .child(
+                        div()
+                            .child(Story::label(cx, "Filled"))
+                            .child(h_stack().gap_2().children(states.clone().map(|state| {
+                                v_stack()
+                                    .gap_1()
+                                    .child(Label::new(state.to_string()).color(Color::Muted))
+                                    .child(
+                                        Button::new("Label").variant(ButtonVariant::Filled), // .state(state),
+                                    )
+                            })))
+                            .child(Story::label(cx, "Filled – Left Button"))
+                            .child(h_stack().gap_2().children(states.clone().map(|state| {
+                                v_stack()
+                                    .gap_1()
+                                    .child(Label::new(state.to_string()).color(Color::Muted))
+                                    .child(
+                                        Button::new("Label")
+                                            .variant(ButtonVariant::Filled)
+                                            .icon(Icon::Plus)
+                                            .icon_position(IconPosition::Left), // .state(state),
+                                    )
+                            })))
+                            .child(Story::label(cx, "Filled – Right Button"))
+                            .child(h_stack().gap_2().children(states.clone().map(|state| {
+                                v_stack()
+                                    .gap_1()
+                                    .child(Label::new(state.to_string()).color(Color::Muted))
+                                    .child(
+                                        Button::new("Label")
+                                            .variant(ButtonVariant::Filled)
+                                            .icon(Icon::Plus)
+                                            .icon_position(IconPosition::Right), // .state(state),
+                                    )
+                            }))),
+                    )
+                    .child(
+                        div()
+                            .child(Story::label(cx, "Fixed With"))
+                            .child(h_stack().gap_2().children(states.clone().map(|state| {
+                                v_stack()
+                                    .gap_1()
+                                    .child(Label::new(state.to_string()).color(Color::Muted))
+                                    .child(
+                                        Button::new("Label")
+                                            .variant(ButtonVariant::Filled)
+                                            // .state(state)
+                                            .width(Some(rems(6.).into())),
+                                    )
+                            })))
+                            .child(Story::label(cx, "Fixed With – Left Icon"))
+                            .child(h_stack().gap_2().children(states.clone().map(|state| {
+                                v_stack()
+                                    .gap_1()
+                                    .child(Label::new(state.to_string()).color(Color::Muted))
+                                    .child(
+                                        Button::new("Label")
+                                            .variant(ButtonVariant::Filled)
+                                            // .state(state)
+                                            .icon(Icon::Plus)
+                                            .icon_position(IconPosition::Left)
+                                            .width(Some(rems(6.).into())),
+                                    )
+                            })))
+                            .child(Story::label(cx, "Fixed With – Right Icon"))
+                            .child(h_stack().gap_2().children(states.clone().map(|state| {
+                                v_stack()
+                                    .gap_1()
+                                    .child(Label::new(state.to_string()).color(Color::Muted))
+                                    .child(
+                                        Button::new("Label")
+                                            .variant(ButtonVariant::Filled)
+                                            // .state(state)
+                                            .icon(Icon::Plus)
+                                            .icon_position(IconPosition::Right)
+                                            .width(Some(rems(6.).into())),
+                                    )
+                            }))),
+                    ),
+            )
+            .child(Story::label(cx, "Button with `on_click`"))
+            .child(
+                Button::new("Label")
+                    .variant(ButtonVariant::Ghost)
+                    .on_click(|_, cx| println!("Button clicked.")),
+            )
     }
 }

crates/ui2/src/components/stories/checkbox.rs 🔗

@@ -1,59 +1,48 @@
-#[cfg(feature = "stories")]
-pub use stories::*;
+use gpui::{Div, Render, ViewContext};
 
-#[cfg(feature = "stories")]
-mod stories {
-    use super::*;
-    use crate::{h_stack, Story};
-    use gpui::{Div, Render, ViewContext};
+use crate::prelude::*;
+use crate::{h_stack, Checkbox, Story};
 
-    pub struct CheckboxStory;
+pub struct CheckboxStory;
 
-    impl Render for CheckboxStory {
-        type Element = Div;
+impl Render for CheckboxStory {
+    type Element = Div;
 
-        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
-            Story::container(cx)
-                .child(Story::title_for::<Checkbox>(cx))
-                .child(Story::label(cx, "Default"))
-                .child(
-                    h_stack()
-                        .p_2()
-                        .gap_2()
-                        .rounded_md()
-                        .border()
-                        .border_color(cx.theme().colors().border)
-                        .child(Checkbox::new("checkbox-enabled", Selection::Unselected))
-                        .child(Checkbox::new(
-                            "checkbox-intermediate",
-                            Selection::Indeterminate,
-                        ))
-                        .child(Checkbox::new("checkbox-selected", Selection::Selected)),
-                )
-                .child(Story::label(cx, "Disabled"))
-                .child(
-                    h_stack()
-                        .p_2()
-                        .gap_2()
-                        .rounded_md()
-                        .border()
-                        .border_color(cx.theme().colors().border)
-                        .child(
-                            Checkbox::new("checkbox-disabled", Selection::Unselected)
-                                .disabled(true),
-                        )
-                        .child(
-                            Checkbox::new(
-                                "checkbox-disabled-intermediate",
-                                Selection::Indeterminate,
-                            )
+    fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
+        Story::container(cx)
+            .child(Story::title_for::<Checkbox>(cx))
+            .child(Story::label(cx, "Default"))
+            .child(
+                h_stack()
+                    .p_2()
+                    .gap_2()
+                    .rounded_md()
+                    .border()
+                    .border_color(cx.theme().colors().border)
+                    .child(Checkbox::new("checkbox-enabled", Selection::Unselected))
+                    .child(Checkbox::new(
+                        "checkbox-intermediate",
+                        Selection::Indeterminate,
+                    ))
+                    .child(Checkbox::new("checkbox-selected", Selection::Selected)),
+            )
+            .child(Story::label(cx, "Disabled"))
+            .child(
+                h_stack()
+                    .p_2()
+                    .gap_2()
+                    .rounded_md()
+                    .border()
+                    .border_color(cx.theme().colors().border)
+                    .child(Checkbox::new("checkbox-disabled", Selection::Unselected).disabled(true))
+                    .child(
+                        Checkbox::new("checkbox-disabled-intermediate", Selection::Indeterminate)
                             .disabled(true),
-                        )
-                        .child(
-                            Checkbox::new("checkbox-disabled-selected", Selection::Selected)
-                                .disabled(true),
-                        ),
-                )
-        }
+                    )
+                    .child(
+                        Checkbox::new("checkbox-disabled-selected", Selection::Selected)
+                            .disabled(true),
+                    ),
+            )
     }
 }

crates/ui2/src/components/stories/context_menu.rs 🔗

@@ -1,112 +1,107 @@
-#[cfg(feature = "stories")]
-pub use stories::*;
+use gpui::{actions, Action, AnchorCorner, Div, Render, View};
 
-#[cfg(feature = "stories")]
-mod stories {
-    use super::*;
-    use crate::{story::Story, Label};
-    use gpui::{actions, Div, Render};
+use crate::prelude::*;
+use crate::{menu_handle, ContextMenu, Label, ListItem, Story};
 
-    actions!(PrintCurrentDate, PrintBestFood);
+actions!(PrintCurrentDate, PrintBestFood);
 
-    fn build_menu(cx: &mut WindowContext, header: impl Into<SharedString>) -> View<ContextMenu> {
-        ContextMenu::build(cx, |menu, _| {
-            menu.header(header)
-                .separator()
-                .entry(
-                    ListItem::new("Print current time", Label::new("Print current time")),
-                    |v, cx| {
-                        println!("dispatching PrintCurrentTime action");
-                        cx.dispatch_action(PrintCurrentDate.boxed_clone())
-                    },
-                )
-                .entry(
-                    ListItem::new("Print best food", Label::new("Print best food")),
-                    |v, cx| cx.dispatch_action(PrintBestFood.boxed_clone()),
-                )
-        })
-    }
+fn build_menu(cx: &mut WindowContext, header: impl Into<SharedString>) -> View<ContextMenu> {
+    ContextMenu::build(cx, |menu, _| {
+        menu.header(header)
+            .separator()
+            .entry(
+                ListItem::new("Print current time", Label::new("Print current time")),
+                |v, cx| {
+                    println!("dispatching PrintCurrentTime action");
+                    cx.dispatch_action(PrintCurrentDate.boxed_clone())
+                },
+            )
+            .entry(
+                ListItem::new("Print best food", Label::new("Print best food")),
+                |v, cx| cx.dispatch_action(PrintBestFood.boxed_clone()),
+            )
+    })
+}
 
-    pub struct ContextMenuStory;
+pub struct ContextMenuStory;
 
-    impl Render for ContextMenuStory {
-        type Element = Div;
+impl Render for ContextMenuStory {
+    type Element = Div;
 
-        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
-            Story::container(cx)
-                .on_action(|_: &PrintCurrentDate, _| {
-                    println!("printing unix time!");
-                    if let Ok(unix_time) = std::time::UNIX_EPOCH.elapsed() {
-                        println!("Current Unix time is {:?}", unix_time.as_secs());
-                    }
-                })
-                .on_action(|_: &PrintBestFood, _| {
-                    println!("burrito");
-                })
-                .flex()
-                .flex_row()
-                .justify_between()
-                .child(
-                    div()
-                        .flex()
-                        .flex_col()
-                        .justify_between()
-                        .child(
-                            menu_handle("test2")
-                                .child(|is_open| {
-                                    Label::new(if is_open {
-                                        "TOP LEFT"
-                                    } else {
-                                        "RIGHT CLICK ME"
-                                    })
+    fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
+        Story::container(cx)
+            .on_action(|_: &PrintCurrentDate, _| {
+                println!("printing unix time!");
+                if let Ok(unix_time) = std::time::UNIX_EPOCH.elapsed() {
+                    println!("Current Unix time is {:?}", unix_time.as_secs());
+                }
+            })
+            .on_action(|_: &PrintBestFood, _| {
+                println!("burrito");
+            })
+            .flex()
+            .flex_row()
+            .justify_between()
+            .child(
+                div()
+                    .flex()
+                    .flex_col()
+                    .justify_between()
+                    .child(
+                        menu_handle("test2")
+                            .child(|is_open| {
+                                Label::new(if is_open {
+                                    "TOP LEFT"
+                                } else {
+                                    "RIGHT CLICK ME"
                                 })
-                                .menu(move |cx| build_menu(cx, "top left")),
-                        )
-                        .child(
-                            menu_handle("test1")
-                                .child(|is_open| {
-                                    Label::new(if is_open {
-                                        "BOTTOM LEFT"
-                                    } else {
-                                        "RIGHT CLICK ME"
-                                    })
+                            })
+                            .menu(move |cx| build_menu(cx, "top left")),
+                    )
+                    .child(
+                        menu_handle("test1")
+                            .child(|is_open| {
+                                Label::new(if is_open {
+                                    "BOTTOM LEFT"
+                                } else {
+                                    "RIGHT CLICK ME"
                                 })
-                                .anchor(AnchorCorner::BottomLeft)
-                                .attach(AnchorCorner::TopLeft)
-                                .menu(move |cx| build_menu(cx, "bottom left")),
-                        ),
-                )
-                .child(
-                    div()
-                        .flex()
-                        .flex_col()
-                        .justify_between()
-                        .child(
-                            menu_handle("test3")
-                                .child(|is_open| {
-                                    Label::new(if is_open {
-                                        "TOP RIGHT"
-                                    } else {
-                                        "RIGHT CLICK ME"
-                                    })
+                            })
+                            .anchor(AnchorCorner::BottomLeft)
+                            .attach(AnchorCorner::TopLeft)
+                            .menu(move |cx| build_menu(cx, "bottom left")),
+                    ),
+            )
+            .child(
+                div()
+                    .flex()
+                    .flex_col()
+                    .justify_between()
+                    .child(
+                        menu_handle("test3")
+                            .child(|is_open| {
+                                Label::new(if is_open {
+                                    "TOP RIGHT"
+                                } else {
+                                    "RIGHT CLICK ME"
                                 })
-                                .anchor(AnchorCorner::TopRight)
-                                .menu(move |cx| build_menu(cx, "top right")),
-                        )
-                        .child(
-                            menu_handle("test4")
-                                .child(|is_open| {
-                                    Label::new(if is_open {
-                                        "BOTTOM RIGHT"
-                                    } else {
-                                        "RIGHT CLICK ME"
-                                    })
+                            })
+                            .anchor(AnchorCorner::TopRight)
+                            .menu(move |cx| build_menu(cx, "top right")),
+                    )
+                    .child(
+                        menu_handle("test4")
+                            .child(|is_open| {
+                                Label::new(if is_open {
+                                    "BOTTOM RIGHT"
+                                } else {
+                                    "RIGHT CLICK ME"
                                 })
-                                .anchor(AnchorCorner::BottomRight)
-                                .attach(AnchorCorner::TopRight)
-                                .menu(move |cx| build_menu(cx, "bottom right")),
-                        ),
-                )
-        }
+                            })
+                            .anchor(AnchorCorner::BottomRight)
+                            .attach(AnchorCorner::TopRight)
+                            .menu(move |cx| build_menu(cx, "bottom right")),
+                    ),
+            )
     }
 }

crates/ui2/src/components/stories/icon.rs 🔗

@@ -1,27 +1,20 @@
-#[cfg(feature = "stories")]
-pub use stories::*;
+use gpui::{Div, Render};
+use strum::IntoEnumIterator;
 
-#[cfg(feature = "stories")]
-mod stories {
-    use gpui::{Div, Render};
-    use strum::IntoEnumIterator;
+use crate::prelude::*;
+use crate::{Icon, IconElement, Story};
 
-    use crate::Story;
+pub struct IconStory;
 
-    use super::*;
+impl Render for IconStory {
+    type Element = Div;
 
-    pub struct IconStory;
+    fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
+        let icons = Icon::iter();
 
-    impl Render for IconStory {
-        type Element = Div;
-
-        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
-            let icons = Icon::iter();
-
-            Story::container(cx)
-                .child(Story::title_for::<IconElement>(cx))
-                .child(Story::label(cx, "All Icons"))
-                .child(div().flex().gap_3().children(icons.map(IconElement::new)))
-        }
+        Story::container(cx)
+            .child(Story::title_for::<IconElement>(cx))
+            .child(Story::label(cx, "All Icons"))
+            .child(div().flex().gap_3().children(icons.map(IconElement::new)))
     }
 }

crates/ui2/src/components/stories/input.rs 🔗

@@ -1,22 +1,17 @@
-#[cfg(feature = "stories")]
-pub use stories::*;
+use gpui::{Div, Render};
 
-#[cfg(feature = "stories")]
-mod stories {
-    use super::*;
-    use crate::Story;
-    use gpui::{Div, Render};
+use crate::prelude::*;
+use crate::{Input, Story};
 
-    pub struct InputStory;
+pub struct InputStory;
 
-    impl Render for InputStory {
-        type Element = Div;
+impl Render for InputStory {
+    type Element = Div;
 
-        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
-            Story::container(cx)
-                .child(Story::title_for::<Input>(cx))
-                .child(Story::label(cx, "Default"))
-                .child(div().flex().child(Input::new("Search")))
-        }
+    fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
+        Story::container(cx)
+            .child(Story::title_for::<Input>(cx))
+            .child(Story::label(cx, "Default"))
+            .child(div().flex().child(Input::new("Search")))
     }
 }

crates/ui2/src/components/stories/keybinding.rs 🔗

@@ -1,66 +1,60 @@
-#[cfg(feature = "stories")]
-pub use stories::*;
+use gpui::{actions, Div, Render};
+use itertools::Itertools;
 
-#[cfg(feature = "stories")]
-mod stories {
-    use super::*;
-    pub use crate::KeyBinding;
-    use crate::Story;
-    use gpui::{actions, Div, Render};
-    use itertools::Itertools;
-    pub struct KeybindingStory;
+use crate::prelude::*;
+use crate::{KeyBinding, Story};
 
-    actions!(NoAction);
+pub struct KeybindingStory;
 
-    pub fn binding(key: &str) -> gpui::KeyBinding {
-        gpui::KeyBinding::new(key, NoAction {}, None)
-    }
+actions!(NoAction);
+
+pub fn binding(key: &str) -> gpui::KeyBinding {
+    gpui::KeyBinding::new(key, NoAction {}, None)
+}
 
-    impl Render for KeybindingStory {
-        type Element = Div;
+impl Render for KeybindingStory {
+    type Element = Div;
 
-        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
-            let all_modifier_permutations =
-                ["ctrl", "alt", "cmd", "shift"].into_iter().permutations(2);
+    fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
+        let all_modifier_permutations = ["ctrl", "alt", "cmd", "shift"].into_iter().permutations(2);
 
-            Story::container(cx)
-                .child(Story::title_for::<KeyBinding>(cx))
-                .child(Story::label(cx, "Single Key"))
-                .child(KeyBinding::new(binding("Z")))
-                .child(Story::label(cx, "Single Key with Modifier"))
-                .child(
-                    div()
-                        .flex()
-                        .gap_3()
-                        .child(KeyBinding::new(binding("ctrl-c")))
-                        .child(KeyBinding::new(binding("alt-c")))
-                        .child(KeyBinding::new(binding("cmd-c")))
-                        .child(KeyBinding::new(binding("shift-c"))),
-                )
-                .child(Story::label(cx, "Single Key with Modifier (Permuted)"))
-                .child(
-                    div().flex().flex_col().children(
-                        all_modifier_permutations
-                            .chunks(4)
-                            .into_iter()
-                            .map(|chunk| {
-                                div()
-                                    .flex()
-                                    .gap_4()
-                                    .py_3()
-                                    .children(chunk.map(|permutation| {
-                                        KeyBinding::new(binding(&*(permutation.join("-") + "-x")))
-                                    }))
-                            }),
-                    ),
-                )
-                .child(Story::label(cx, "Single Key with All Modifiers"))
-                .child(KeyBinding::new(binding("ctrl-alt-cmd-shift-z")))
-                .child(Story::label(cx, "Chord"))
-                .child(KeyBinding::new(binding("a z")))
-                .child(Story::label(cx, "Chord with Modifier"))
-                .child(KeyBinding::new(binding("ctrl-a shift-z")))
-                .child(KeyBinding::new(binding("fn-s")))
-        }
+        Story::container(cx)
+            .child(Story::title_for::<KeyBinding>(cx))
+            .child(Story::label(cx, "Single Key"))
+            .child(KeyBinding::new(binding("Z")))
+            .child(Story::label(cx, "Single Key with Modifier"))
+            .child(
+                div()
+                    .flex()
+                    .gap_3()
+                    .child(KeyBinding::new(binding("ctrl-c")))
+                    .child(KeyBinding::new(binding("alt-c")))
+                    .child(KeyBinding::new(binding("cmd-c")))
+                    .child(KeyBinding::new(binding("shift-c"))),
+            )
+            .child(Story::label(cx, "Single Key with Modifier (Permuted)"))
+            .child(
+                div().flex().flex_col().children(
+                    all_modifier_permutations
+                        .chunks(4)
+                        .into_iter()
+                        .map(|chunk| {
+                            div()
+                                .flex()
+                                .gap_4()
+                                .py_3()
+                                .children(chunk.map(|permutation| {
+                                    KeyBinding::new(binding(&*(permutation.join("-") + "-x")))
+                                }))
+                        }),
+                ),
+            )
+            .child(Story::label(cx, "Single Key with All Modifiers"))
+            .child(KeyBinding::new(binding("ctrl-alt-cmd-shift-z")))
+            .child(Story::label(cx, "Chord"))
+            .child(KeyBinding::new(binding("a z")))
+            .child(Story::label(cx, "Chord with Modifier"))
+            .child(KeyBinding::new(binding("ctrl-a shift-z")))
+            .child(KeyBinding::new(binding("fn-s")))
     }
 }

crates/ui2/src/components/stories/label.rs 🔗

@@ -1,31 +1,26 @@
-#[cfg(feature = "stories")]
-pub use stories::*;
+use gpui::{Div, Render};
 
-#[cfg(feature = "stories")]
-mod stories {
-    use super::*;
-    use crate::Story;
-    use gpui::{Div, Render};
+use crate::prelude::*;
+use crate::{HighlightedLabel, Label, Story};
 
-    pub struct LabelStory;
+pub struct LabelStory;
 
-    impl Render for LabelStory {
-        type Element = Div;
+impl Render for LabelStory {
+    type Element = Div;
 
-        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
-            Story::container(cx)
-                .child(Story::title_for::<Label>(cx))
-                .child(Story::label(cx, "Default"))
-                .child(Label::new("Hello, world!"))
-                .child(Story::label(cx, "Highlighted"))
-                .child(HighlightedLabel::new(
-                    "Hello, world!",
-                    vec![0, 1, 2, 7, 8, 12],
-                ))
-                .child(HighlightedLabel::new(
-                    "Héllo, world!",
-                    vec![0, 1, 3, 8, 9, 13],
-                ))
-        }
+    fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
+        Story::container(cx)
+            .child(Story::title_for::<Label>(cx))
+            .child(Story::label(cx, "Default"))
+            .child(Label::new("Hello, world!"))
+            .child(Story::label(cx, "Highlighted"))
+            .child(HighlightedLabel::new(
+                "Hello, world!",
+                vec![0, 1, 2, 7, 8, 12],
+            ))
+            .child(HighlightedLabel::new(
+                "Héllo, world!",
+                vec![0, 1, 3, 8, 9, 13],
+            ))
     }
 }