Skip to content

Commit

Permalink
Fix storybook (#3379)
Browse files Browse the repository at this point in the history
This PR fixes storybook and gets it back into a compiling and running
state.

Release Notes:

- N/A
  • Loading branch information
maxdeviant authored Nov 21, 2023
1 parent 6fe7b22 commit a94cf54
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 231 deletions.
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ members = [
"crates/sqlez",
"crates/sqlez_macros",
"crates/rich_text",
# "crates/storybook2",
# "crates/storybook3",
"crates/storybook2",
"crates/sum_tree",
"crates/terminal",
"crates/terminal2",
Expand Down
2 changes: 0 additions & 2 deletions crates/storybook2/src/stories.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
mod colors;
mod focus;
mod kitchen_sink;
mod picker;
mod scroll;
mod text;
mod z_index;

pub use colors::*;
pub use focus::*;
pub use kitchen_sink::*;
pub use picker::*;
Expand Down
8 changes: 3 additions & 5 deletions crates/storybook2/src/stories/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl FocusStory {
}
}

impl Render<Self> for FocusStory {
impl Render for FocusStory {
type Element = Focusable<Stateful<Div>>;

fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
Expand All @@ -52,10 +52,8 @@ impl Render<Self> for FocusStory {
.on_blur(cx.listener(|_, _, _| println!("Parent blurred")))
.on_focus_in(cx.listener(|_, _, _| println!("Parent focus_in")))
.on_focus_out(cx.listener(|_, _, _| println!("Parent focus_out")))
.on_key_down(
cx.listener(|_, event, phase, _| println!("Key down on parent {:?}", event)),
)
.on_key_up(cx.listener(|_, event, phase, _| println!("Key up on parent {:?}", event)))
.on_key_down(cx.listener(|_, event, _| println!("Key down on parent {:?}", event)))
.on_key_up(cx.listener(|_, event, _| println!("Key up on parent {:?}", event)))
.size_full()
.bg(color_1)
.focus(|style| style.bg(color_2))
Expand Down
10 changes: 6 additions & 4 deletions crates/storybook2/src/stories/kitchen_sink.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{story::Story, story_selector::ComponentStory};
use gpui::{prelude::*, Div, Render, Stateful, View};
use story::Story;
use strum::IntoEnumIterator;
use ui::prelude::*;

use crate::story_selector::ComponentStory;

pub struct KitchenSinkStory;

impl KitchenSinkStory {
Expand All @@ -19,11 +21,11 @@ impl Render for KitchenSinkStory {
.map(|selector| selector.story(cx))
.collect::<Vec<_>>();

Story::container(cx)
Story::container()
.id("kitchen-sink")
.overflow_y_scroll()
.child(Story::title(cx, "Kitchen Sink"))
.child(Story::label(cx, "Components"))
.child(Story::title("Kitchen Sink"))
.child(Story::label("Components"))
.child(div().flex().flex_col().children(component_stories))
// Add a bit of space at the bottom of the kitchen sink so elements
// don't end up squished right up against the bottom of the screen.
Expand Down
6 changes: 3 additions & 3 deletions crates/storybook2/src/stories/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Delegate {
}

impl PickerDelegate for Delegate {
type ListItem = Div<Picker<Self>>;
type ListItem = Div;

fn match_count(&self) -> usize {
self.candidates.len()
Expand Down Expand Up @@ -205,8 +205,8 @@ impl PickerStory {
}
}

impl Render<Self> for PickerStory {
type Element = Div<Self>;
impl Render for PickerStory {
type Element = Div;

fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
div()
Expand Down
6 changes: 3 additions & 3 deletions crates/storybook2/src/stories/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ impl ScrollStory {
}
}

impl Render<Self> for ScrollStory {
type Element = Stateful<Self, Div<Self>>;
impl Render for ScrollStory {
type Element = Stateful<Div>;

fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
let theme = cx.theme();
Expand All @@ -38,7 +38,7 @@ impl Render<Self> for ScrollStory {
};
div()
.id(id)
.tooltip(move |_, cx| Tooltip::text(format!("{}, {}", row, column), cx))
.tooltip(move |cx| Tooltip::text(format!("{}, {}", row, column), cx))
.bg(bg)
.size(px(100. as f32))
.when(row >= 5 && column >= 5, |d| {
Expand Down
85 changes: 41 additions & 44 deletions crates/storybook2/src/stories/z_index.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,49 @@
use gpui::{px, rgb, Div, Hsla, Render, RenderOnce};
use story::Story;
use ui::prelude::*;

use crate::story::Story;

/// A reimplementation of the MDN `z-index` example, found here:
/// [https://developer.mozilla.org/en-US/docs/Web/CSS/z-index](https://developer.mozilla.org/en-US/docs/Web/CSS/z-index).
pub struct ZIndexStory;

impl Render<Self> for ZIndexStory {
type Element = Div<Self>;
impl Render for ZIndexStory {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title(cx, "z-index"))
.child(
div()
.flex()
.child(
div()
.w(px(250.))
.child(Story::label(cx, "z-index: auto"))
.child(ZIndexExample::new(0)),
)
.child(
div()
.w(px(250.))
.child(Story::label(cx, "z-index: 1"))
.child(ZIndexExample::new(1)),
)
.child(
div()
.w(px(250.))
.child(Story::label(cx, "z-index: 3"))
.child(ZIndexExample::new(3)),
)
.child(
div()
.w(px(250.))
.child(Story::label(cx, "z-index: 5"))
.child(ZIndexExample::new(5)),
)
.child(
div()
.w(px(250.))
.child(Story::label(cx, "z-index: 7"))
.child(ZIndexExample::new(7)),
),
)
Story::container().child(Story::title("z-index")).child(
div()
.flex()
.child(
div()
.w(px(250.))
.child(Story::label("z-index: auto"))
.child(ZIndexExample::new(0)),
)
.child(
div()
.w(px(250.))
.child(Story::label("z-index: 1"))
.child(ZIndexExample::new(1)),
)
.child(
div()
.w(px(250.))
.child(Story::label("z-index: 3"))
.child(ZIndexExample::new(3)),
)
.child(
div()
.w(px(250.))
.child(Story::label("z-index: 5"))
.child(ZIndexExample::new(5)),
)
.child(
div()
.w(px(250.))
.child(Story::label("z-index: 7"))
.child(ZIndexExample::new(7)),
),
)
}
}

Expand Down Expand Up @@ -77,17 +74,17 @@ trait Styles: Styled + Sized {
}
}

impl<V: 'static> Styles for Div<V> {}
impl Styles for Div {}

#[derive(RenderOnce)]
struct ZIndexExample {
z_index: u32,
}

impl<V: 'static> Component<V> for ZIndexExample {
type Rendered = Div<V>;
impl Component for ZIndexExample {
type Rendered = Div;

fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
div()
.relative()
.size_full()
Expand Down
1 change: 0 additions & 1 deletion crates/storybook2/src/story.rs

This file was deleted.

56 changes: 1 addition & 55 deletions crates/storybook2/src/story_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,94 +8,40 @@ use clap::ValueEnum;
use gpui::{AnyView, VisualContext};
use strum::{EnumIter, EnumString, IntoEnumIterator};
use ui::prelude::*;
use ui::{AvatarStory, ButtonStory, DetailsStory, IconStory, InputStory, LabelStory};
use ui::{AvatarStory, ButtonStory, IconStory, InputStory, LabelStory};

#[derive(Debug, PartialEq, Eq, Clone, Copy, strum::Display, EnumString, EnumIter)]
#[strum(serialize_all = "snake_case")]
pub enum ComponentStory {
AssistantPanel,
Avatar,
Breadcrumb,
Buffer,
Button,
ChatPanel,
Checkbox,
CollabPanel,
Colors,
CommandPalette,
ContextMenu,
Copilot,
Details,
Facepile,
Focus,
Icon,
Input,
Keybinding,
Label,
LanguageSelector,
MultiBuffer,
NotificationsPanel,
Palette,
Panel,
ProjectPanel,
Players,
RecentProjects,
Scroll,
Tab,
TabBar,
Terminal,
Text,
ThemeSelector,
TitleBar,
Toast,
Toolbar,
TrafficLights,
Workspace,
ZIndex,
Picker,
}

impl ComponentStory {
pub fn story(&self, cx: &mut WindowContext) -> AnyView {
match self {
Self::AssistantPanel => cx.build_view(|_| ui::AssistantPanelStory).into(),
Self::Avatar => cx.build_view(|_| AvatarStory).into(),
Self::Breadcrumb => cx.build_view(|_| ui::BreadcrumbStory).into(),
Self::Buffer => cx.build_view(|_| ui::BufferStory).into(),
Self::Button => cx.build_view(|_| ButtonStory).into(),
Self::ChatPanel => cx.build_view(|_| ui::ChatPanelStory).into(),
Self::Checkbox => cx.build_view(|_| ui::CheckboxStory).into(),
Self::CollabPanel => cx.build_view(|_| ui::CollabPanelStory).into(),
Self::Colors => cx.build_view(|_| ColorsStory).into(),
Self::CommandPalette => cx.build_view(|_| ui::CommandPaletteStory).into(),
Self::ContextMenu => cx.build_view(|_| ui::ContextMenuStory).into(),
Self::Copilot => cx.build_view(|_| ui::CopilotModalStory).into(),
Self::Details => cx.build_view(|_| DetailsStory).into(),
Self::Facepile => cx.build_view(|_| ui::FacepileStory).into(),
Self::Focus => FocusStory::view(cx).into(),
Self::Icon => cx.build_view(|_| IconStory).into(),
Self::Input => cx.build_view(|_| InputStory).into(),
Self::Keybinding => cx.build_view(|_| ui::KeybindingStory).into(),
Self::Label => cx.build_view(|_| LabelStory).into(),
Self::LanguageSelector => cx.build_view(|_| ui::LanguageSelectorStory).into(),
Self::MultiBuffer => cx.build_view(|_| ui::MultiBufferStory).into(),
Self::NotificationsPanel => cx.build_view(|cx| ui::NotificationsPanelStory).into(),
Self::Palette => cx.build_view(|cx| ui::PaletteStory).into(),
Self::Players => cx.build_view(|_| theme2::PlayerStory).into(),
Self::Panel => cx.build_view(|cx| ui::PanelStory).into(),
Self::ProjectPanel => cx.build_view(|_| ui::ProjectPanelStory).into(),
Self::RecentProjects => cx.build_view(|_| ui::RecentProjectsStory).into(),
Self::Scroll => ScrollStory::view(cx).into(),
Self::Tab => cx.build_view(|_| ui::TabStory).into(),
Self::TabBar => cx.build_view(|_| ui::TabBarStory).into(),
Self::Terminal => cx.build_view(|_| ui::TerminalStory).into(),
Self::Text => TextStory::view(cx).into(),
Self::ThemeSelector => cx.build_view(|_| ui::ThemeSelectorStory).into(),
Self::TitleBar => ui::TitleBarStory::view(cx).into(),
Self::Toast => cx.build_view(|_| ui::ToastStory).into(),
Self::Toolbar => cx.build_view(|_| ui::ToolbarStory).into(),
Self::TrafficLights => cx.build_view(|_| ui::TrafficLightsStory).into(),
Self::Workspace => ui::WorkspaceStory::view(cx).into(),
Self::ZIndex => cx.build_view(|_| ZIndexStory).into(),
Self::Picker => PickerStory::new(cx).into(),
}
Expand Down
Loading

0 comments on commit a94cf54

Please sign in to comment.