Fix stories

co-authored-by: Piotrek <piotr@zed.dev>
This commit is contained in:
Mikayla 2023-11-20 16:06:03 -08:00
parent 8049ec674e
commit a844bf7d41
No known key found for this signature in database
14 changed files with 22 additions and 62 deletions

View File

@ -54,7 +54,7 @@ mod stories {
impl Render for AvatarStory {
type Element = Div;
fn render(&mut self, cx: &mut WindowContext) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<Avatar>(cx))
.child(Story::label(cx, "Default"))

View File

@ -251,7 +251,7 @@ mod stories {
let states = InteractionState::iter();
Story::container(cx)
.child(Story::title_for::<_, Button>(cx))
.child(Story::title_for::<Button>(cx))
.child(
div()
.flex()
@ -394,7 +394,7 @@ mod stories {
.child(
Button::new("Label")
.variant(ButtonVariant::Ghost)
.on_click(cx.callback(|_view, _, cx| println!("Button clicked."))),
.on_click(|_, cx| println!("Button clicked.")),
)
}
}

View File

@ -291,7 +291,7 @@ pub use stories::*;
mod stories {
use super::*;
use crate::{h_stack, Story};
use gpui::{Div, Render};
use gpui::{Div, Render, ViewContext};
pub struct CheckboxStory;
@ -300,7 +300,7 @@ mod stories {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<_, Checkbox<Self>>(cx))
.child(Story::title_for::<Checkbox>(cx))
.child(Story::label(cx, "Default"))
.child(
h_stack()

View File

@ -309,10 +309,7 @@ mod stories {
actions!(PrintCurrentDate, PrintBestFood);
fn build_menu<V: Render>(
cx: &mut WindowContext,
header: impl Into<SharedString>,
) -> View<ContextMenu> {
fn build_menu(cx: &mut WindowContext, header: impl Into<SharedString>) -> View<ContextMenu> {
ContextMenu::build(cx, |menu, _| {
menu.header(header)
.separator()
@ -337,13 +334,13 @@ mod stories {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.on_action(|_, _: &PrintCurrentDate, _| {
.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, _| {
.on_action(|_: &PrintBestFood, _| {
println!("burrito");
})
.flex()
@ -363,7 +360,7 @@ mod stories {
"RIGHT CLICK ME"
})
})
.menu(move |_, cx| build_menu(cx, "top left")),
.menu(move |cx| build_menu(cx, "top left")),
)
.child(
menu_handle("test1")
@ -376,7 +373,7 @@ mod stories {
})
.anchor(AnchorCorner::BottomLeft)
.attach(AnchorCorner::TopLeft)
.menu(move |_, cx| build_menu(cx, "bottom left")),
.menu(move |cx| build_menu(cx, "bottom left")),
),
)
.child(
@ -394,7 +391,7 @@ mod stories {
})
})
.anchor(AnchorCorner::TopRight)
.menu(move |_, cx| build_menu(cx, "top right")),
.menu(move |cx| build_menu(cx, "top right")),
)
.child(
menu_handle("test4")
@ -407,7 +404,7 @@ mod stories {
})
.anchor(AnchorCorner::BottomRight)
.attach(AnchorCorner::TopRight)
.menu(move |_, cx| build_menu(cx, "bottom right")),
.menu(move |cx| build_menu(cx, "bottom right")),
),
)
}

View File

@ -61,7 +61,7 @@ mod stories {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<_, Details<Self>>(cx))
.child(Story::title_for::<Details>(cx))
.child(Story::label(cx, "Default"))
.child(Details::new("The quick brown fox jumps over the lazy dog"))
.child(Story::label(cx, "With meta"))

View File

@ -31,34 +31,3 @@ impl Facepile {
}
use gpui::{Div, RenderOnce};
#[cfg(feature = "stories")]
pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use super::*;
use crate::{static_players, Story};
use gpui::{Div, Render};
pub struct FacepileStory;
impl Render for FacepileStory {
type Element = Div;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
let players = static_players();
Story::container(cx)
.child(Story::title_for::<_, Facepile>(cx))
.child(Story::label(cx, "Default"))
.child(
div()
.flex()
.gap_3()
.child(Facepile::new(players.clone().into_iter().take(1)))
.child(Facepile::new(players.clone().into_iter().take(2)))
.child(Facepile::new(players.clone().into_iter().take(3))),
)
}
}
}

View File

@ -215,7 +215,7 @@ mod stories {
let icons = Icon::iter();
Story::container(cx)
.child(Story::title_for::<_, IconElement>(cx))
.child(Story::title_for::<IconElement>(cx))
.child(Story::label(cx, "All Icons"))
.child(div().flex().gap_3().children(icons.map(IconElement::new)))
}

View File

@ -123,7 +123,7 @@ mod stories {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<_, Input>(cx))
.child(Story::title_for::<Input>(cx))
.child(Story::label(cx, "Default"))
.child(div().flex().child(Input::new("Search")))
}

View File

@ -96,7 +96,7 @@ mod stories {
["ctrl", "alt", "cmd", "shift"].into_iter().permutations(2);
Story::container(cx)
.child(Story::title_for::<_, KeyBinding>(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"))

View File

@ -247,7 +247,7 @@ mod stories {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<_, Label>(cx))
.child(Story::title_for::<Label>(cx))
.child(Story::label(cx, "Default"))
.child(Label::new("Hello, world!"))
.child(Story::label(cx, "Highlighted"))

View File

@ -178,7 +178,7 @@ mod stories {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
{
Story::container(cx)
.child(Story::title_for::<_, Palette>(cx))
.child(Story::title_for::<Palette>(cx))
.child(Story::label(cx, "Default"))
.child(Palette::new("palette-1"))
.child(Story::label(cx, "With Items"))

View File

@ -137,7 +137,7 @@ mod stories {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<Panel<Self>>(cx))
.child(Story::title_for::<Panel>(cx))
.child(Story::label(cx, "Default"))
.child(
Panel::new("panel", cx).child(

View File

@ -109,7 +109,7 @@ mod stories {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<Toast<Self>>(cx))
.child(Story::title_for::<Toast>(cx))
.child(Story::label(cx, "Default"))
.child(Toast::new(ToastOrigin::Bottom).child(Label::new("label")))
}

View File

@ -15,10 +15,7 @@ impl Story {
.bg(cx.theme().colors().background)
}
pub fn title<V: 'static>(
cx: &mut WindowContext,
title: impl Into<SharedString>,
) -> impl Element {
pub fn title(cx: &mut WindowContext, title: impl Into<SharedString>) -> impl Element {
div()
.text_xl()
.text_color(cx.theme().colors().text)
@ -29,10 +26,7 @@ impl Story {
Self::title(cx, std::any::type_name::<T>())
}
pub fn label<V: 'static>(
cx: &mut WindowContext,
label: impl Into<SharedString>,
) -> impl Element {
pub fn label(cx: &mut WindowContext, label: impl Into<SharedString>) -> impl Element {
div()
.mt_4()
.mb_2()