ui2: Get component stories compiling again (#3376)
This PR gets the component stories defined in `ui2` compiling again. Release Notes: - N/A
This commit is contained in:
parent
6cd0bcc578
commit
f4b4bdfd83
11 changed files with 399 additions and 455 deletions
|
@ -12,10 +12,12 @@ mod label;
|
||||||
mod list;
|
mod list;
|
||||||
mod slot;
|
mod slot;
|
||||||
mod stack;
|
mod stack;
|
||||||
mod stories;
|
|
||||||
mod toggle;
|
mod toggle;
|
||||||
mod tooltip;
|
mod tooltip;
|
||||||
|
|
||||||
|
#[cfg(feature = "stories")]
|
||||||
|
mod stories;
|
||||||
|
|
||||||
pub use avatar::*;
|
pub use avatar::*;
|
||||||
pub use button::*;
|
pub use button::*;
|
||||||
pub use checkbox::*;
|
pub use checkbox::*;
|
||||||
|
@ -30,6 +32,8 @@ pub use label::*;
|
||||||
pub use list::*;
|
pub use list::*;
|
||||||
pub use slot::*;
|
pub use slot::*;
|
||||||
pub use stack::*;
|
pub use stack::*;
|
||||||
pub use stories::*;
|
|
||||||
pub use toggle::*;
|
pub use toggle::*;
|
||||||
pub use tooltip::*;
|
pub use tooltip::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "stories")]
|
||||||
|
pub use stories::*;
|
||||||
|
|
8
crates/ui2/src/components/stories.rs
Normal file
8
crates/ui2/src/components/stories.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
mod avatar;
|
||||||
|
mod button;
|
||||||
|
mod checkbox;
|
||||||
|
mod context_menu;
|
||||||
|
mod icon;
|
||||||
|
mod input;
|
||||||
|
mod keybinding;
|
||||||
|
mod label;
|
|
@ -1,27 +1,22 @@
|
||||||
#[cfg(feature = "stories")]
|
use gpui::{Div, Render};
|
||||||
pub use stories::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "stories")]
|
use crate::prelude::*;
|
||||||
mod stories {
|
use crate::{Avatar, Story};
|
||||||
use super::*;
|
|
||||||
use crate::Story;
|
|
||||||
use gpui::{Div, Render};
|
|
||||||
|
|
||||||
pub struct AvatarStory;
|
pub struct AvatarStory;
|
||||||
|
|
||||||
impl Render for AvatarStory {
|
impl Render for AvatarStory {
|
||||||
type Element = Div;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
Story::container(cx)
|
Story::container(cx)
|
||||||
.child(Story::title_for::<Avatar>(cx))
|
.child(Story::title_for::<Avatar>(cx))
|
||||||
.child(Story::label(cx, "Default"))
|
.child(Story::label(cx, "Default"))
|
||||||
.child(Avatar::new(
|
.child(Avatar::new(
|
||||||
"https://avatars.githubusercontent.com/u/1714999?v=4",
|
"https://avatars.githubusercontent.com/u/1714999?v=4",
|
||||||
))
|
))
|
||||||
.child(Avatar::new(
|
.child(Avatar::new(
|
||||||
"https://avatars.githubusercontent.com/u/326587?v=4",
|
"https://avatars.githubusercontent.com/u/326587?v=4",
|
||||||
))
|
))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,167 +1,144 @@
|
||||||
#[cfg(feature = "stories")]
|
use gpui::{rems, Div, Render};
|
||||||
pub use stories::*;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
#[cfg(feature = "stories")]
|
use crate::prelude::*;
|
||||||
mod stories {
|
use crate::{h_stack, v_stack, Button, Icon, IconPosition, Label, Story};
|
||||||
use super::*;
|
|
||||||
use crate::{h_stack, v_stack, Color, Story};
|
|
||||||
use gpui::{rems, Div, Render};
|
|
||||||
use strum::IntoEnumIterator;
|
|
||||||
|
|
||||||
pub struct ButtonStory;
|
pub struct ButtonStory;
|
||||||
|
|
||||||
impl Render for ButtonStory {
|
impl Render for ButtonStory {
|
||||||
type Element = Div;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
let states = InteractionState::iter();
|
let states = InteractionState::iter();
|
||||||
|
|
||||||
Story::container(cx)
|
Story::container(cx)
|
||||||
.child(Story::title_for::<Button>(cx))
|
.child(Story::title_for::<Button>(cx))
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
.gap_8()
|
.gap_8()
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.child(Story::label(cx, "Ghost (Default)"))
|
.child(Story::label(cx, "Ghost (Default)"))
|
||||||
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
||||||
v_stack()
|
v_stack()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(
|
.child(Label::new(state.to_string()).color(Color::Muted))
|
||||||
Label::new(state.to_string()).color(TextColor::Muted),
|
.child(
|
||||||
)
|
Button::new("Label").variant(ButtonVariant::Ghost), // .state(state),
|
||||||
.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| {
|
||||||
.child(Story::label(cx, "Ghost – Left Icon"))
|
v_stack()
|
||||||
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
.gap_1()
|
||||||
v_stack()
|
.child(Label::new(state.to_string()).color(Color::Muted))
|
||||||
.gap_1()
|
.child(
|
||||||
.child(
|
Button::new("Label")
|
||||||
Label::new(state.to_string()).color(TextColor::Muted),
|
.variant(ButtonVariant::Ghost)
|
||||||
)
|
.icon(Icon::Plus)
|
||||||
.child(
|
.icon_position(IconPosition::Left), // .state(state),
|
||||||
Button::new("Label")
|
)
|
||||||
.variant(ButtonVariant::Ghost)
|
})))
|
||||||
.icon(Icon::Plus)
|
.child(Story::label(cx, "Ghost – Right Icon"))
|
||||||
.icon_position(IconPosition::Left), // .state(state),
|
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
||||||
)
|
v_stack()
|
||||||
})))
|
.gap_1()
|
||||||
.child(Story::label(cx, "Ghost – Right Icon"))
|
.child(Label::new(state.to_string()).color(Color::Muted))
|
||||||
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
.child(
|
||||||
v_stack()
|
Button::new("Label")
|
||||||
.gap_1()
|
.variant(ButtonVariant::Ghost)
|
||||||
.child(
|
.icon(Icon::Plus)
|
||||||
Label::new(state.to_string()).color(TextColor::Muted),
|
.icon_position(IconPosition::Right), // .state(state),
|
||||||
)
|
)
|
||||||
.child(
|
}))),
|
||||||
Button::new("Label")
|
)
|
||||||
.variant(ButtonVariant::Ghost)
|
.child(
|
||||||
.icon(Icon::Plus)
|
div()
|
||||||
.icon_position(IconPosition::Right), // .state(state),
|
.child(Story::label(cx, "Filled"))
|
||||||
)
|
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
||||||
}))),
|
v_stack()
|
||||||
)
|
.gap_1()
|
||||||
.child(
|
.child(Label::new(state.to_string()).color(Color::Muted))
|
||||||
div()
|
.child(
|
||||||
.child(Story::label(cx, "Filled"))
|
Button::new("Label").variant(ButtonVariant::Filled), // .state(state),
|
||||||
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
)
|
||||||
v_stack()
|
})))
|
||||||
.gap_1()
|
.child(Story::label(cx, "Filled – Left Button"))
|
||||||
.child(
|
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
||||||
Label::new(state.to_string()).color(TextColor::Muted),
|
v_stack()
|
||||||
)
|
.gap_1()
|
||||||
.child(
|
.child(Label::new(state.to_string()).color(Color::Muted))
|
||||||
Button::new("Label").variant(ButtonVariant::Filled), // .state(state),
|
.child(
|
||||||
)
|
Button::new("Label")
|
||||||
})))
|
.variant(ButtonVariant::Filled)
|
||||||
.child(Story::label(cx, "Filled – Left Button"))
|
.icon(Icon::Plus)
|
||||||
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
.icon_position(IconPosition::Left), // .state(state),
|
||||||
v_stack()
|
)
|
||||||
.gap_1()
|
})))
|
||||||
.child(
|
.child(Story::label(cx, "Filled – Right Button"))
|
||||||
Label::new(state.to_string()).color(TextColor::Muted),
|
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
||||||
)
|
v_stack()
|
||||||
.child(
|
.gap_1()
|
||||||
Button::new("Label")
|
.child(Label::new(state.to_string()).color(Color::Muted))
|
||||||
.variant(ButtonVariant::Filled)
|
.child(
|
||||||
.icon(Icon::Plus)
|
Button::new("Label")
|
||||||
.icon_position(IconPosition::Left), // .state(state),
|
.variant(ButtonVariant::Filled)
|
||||||
)
|
.icon(Icon::Plus)
|
||||||
})))
|
.icon_position(IconPosition::Right), // .state(state),
|
||||||
.child(Story::label(cx, "Filled – Right Button"))
|
)
|
||||||
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
}))),
|
||||||
v_stack()
|
)
|
||||||
.gap_1()
|
.child(
|
||||||
.child(
|
div()
|
||||||
Label::new(state.to_string()).color(TextColor::Muted),
|
.child(Story::label(cx, "Fixed With"))
|
||||||
)
|
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
||||||
.child(
|
v_stack()
|
||||||
Button::new("Label")
|
.gap_1()
|
||||||
.variant(ButtonVariant::Filled)
|
.child(Label::new(state.to_string()).color(Color::Muted))
|
||||||
.icon(Icon::Plus)
|
.child(
|
||||||
.icon_position(IconPosition::Right), // .state(state),
|
Button::new("Label")
|
||||||
)
|
.variant(ButtonVariant::Filled)
|
||||||
}))),
|
// .state(state)
|
||||||
)
|
.width(Some(rems(6.).into())),
|
||||||
.child(
|
)
|
||||||
div()
|
})))
|
||||||
.child(Story::label(cx, "Fixed With"))
|
.child(Story::label(cx, "Fixed With – Left Icon"))
|
||||||
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
||||||
v_stack()
|
v_stack()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(
|
.child(Label::new(state.to_string()).color(Color::Muted))
|
||||||
Label::new(state.to_string()).color(TextColor::Muted),
|
.child(
|
||||||
)
|
Button::new("Label")
|
||||||
.child(
|
.variant(ButtonVariant::Filled)
|
||||||
Button::new("Label")
|
// .state(state)
|
||||||
.variant(ButtonVariant::Filled)
|
.icon(Icon::Plus)
|
||||||
// .state(state)
|
.icon_position(IconPosition::Left)
|
||||||
.width(Some(rems(6.).into())),
|
.width(Some(rems(6.).into())),
|
||||||
)
|
)
|
||||||
})))
|
})))
|
||||||
.child(Story::label(cx, "Fixed With – Left Icon"))
|
.child(Story::label(cx, "Fixed With – Right Icon"))
|
||||||
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
||||||
v_stack()
|
v_stack()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(
|
.child(Label::new(state.to_string()).color(Color::Muted))
|
||||||
Label::new(state.to_string()).color(TextColor::Muted),
|
.child(
|
||||||
)
|
Button::new("Label")
|
||||||
.child(
|
.variant(ButtonVariant::Filled)
|
||||||
Button::new("Label")
|
// .state(state)
|
||||||
.variant(ButtonVariant::Filled)
|
.icon(Icon::Plus)
|
||||||
// .state(state)
|
.icon_position(IconPosition::Right)
|
||||||
.icon(Icon::Plus)
|
.width(Some(rems(6.).into())),
|
||||||
.icon_position(IconPosition::Left)
|
)
|
||||||
.width(Some(rems(6.).into())),
|
}))),
|
||||||
)
|
),
|
||||||
})))
|
)
|
||||||
.child(Story::label(cx, "Fixed With – Right Icon"))
|
.child(Story::label(cx, "Button with `on_click`"))
|
||||||
.child(h_stack().gap_2().children(states.clone().map(|state| {
|
.child(
|
||||||
v_stack()
|
Button::new("Label")
|
||||||
.gap_1()
|
.variant(ButtonVariant::Ghost)
|
||||||
.child(
|
.on_click(|_, cx| println!("Button clicked.")),
|
||||||
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.")),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,59 +1,48 @@
|
||||||
#[cfg(feature = "stories")]
|
use gpui::{Div, Render, ViewContext};
|
||||||
pub use stories::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "stories")]
|
use crate::prelude::*;
|
||||||
mod stories {
|
use crate::{h_stack, Checkbox, Story};
|
||||||
use super::*;
|
|
||||||
use crate::{h_stack, Story};
|
|
||||||
use gpui::{Div, Render, ViewContext};
|
|
||||||
|
|
||||||
pub struct CheckboxStory;
|
pub struct CheckboxStory;
|
||||||
|
|
||||||
impl Render for CheckboxStory {
|
impl Render for CheckboxStory {
|
||||||
type Element = Div;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
Story::container(cx)
|
Story::container(cx)
|
||||||
.child(Story::title_for::<Checkbox>(cx))
|
.child(Story::title_for::<Checkbox>(cx))
|
||||||
.child(Story::label(cx, "Default"))
|
.child(Story::label(cx, "Default"))
|
||||||
.child(
|
.child(
|
||||||
h_stack()
|
h_stack()
|
||||||
.p_2()
|
.p_2()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.rounded_md()
|
.rounded_md()
|
||||||
.border()
|
.border()
|
||||||
.border_color(cx.theme().colors().border)
|
.border_color(cx.theme().colors().border)
|
||||||
.child(Checkbox::new("checkbox-enabled", Selection::Unselected))
|
.child(Checkbox::new("checkbox-enabled", Selection::Unselected))
|
||||||
.child(Checkbox::new(
|
.child(Checkbox::new(
|
||||||
"checkbox-intermediate",
|
"checkbox-intermediate",
|
||||||
Selection::Indeterminate,
|
Selection::Indeterminate,
|
||||||
))
|
))
|
||||||
.child(Checkbox::new("checkbox-selected", Selection::Selected)),
|
.child(Checkbox::new("checkbox-selected", Selection::Selected)),
|
||||||
)
|
)
|
||||||
.child(Story::label(cx, "Disabled"))
|
.child(Story::label(cx, "Disabled"))
|
||||||
.child(
|
.child(
|
||||||
h_stack()
|
h_stack()
|
||||||
.p_2()
|
.p_2()
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.rounded_md()
|
.rounded_md()
|
||||||
.border()
|
.border()
|
||||||
.border_color(cx.theme().colors().border)
|
.border_color(cx.theme().colors().border)
|
||||||
.child(
|
.child(Checkbox::new("checkbox-disabled", Selection::Unselected).disabled(true))
|
||||||
Checkbox::new("checkbox-disabled", Selection::Unselected)
|
.child(
|
||||||
.disabled(true),
|
Checkbox::new("checkbox-disabled-intermediate", Selection::Indeterminate)
|
||||||
)
|
|
||||||
.child(
|
|
||||||
Checkbox::new(
|
|
||||||
"checkbox-disabled-intermediate",
|
|
||||||
Selection::Indeterminate,
|
|
||||||
)
|
|
||||||
.disabled(true),
|
.disabled(true),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
Checkbox::new("checkbox-disabled-selected", Selection::Selected)
|
Checkbox::new("checkbox-disabled-selected", Selection::Selected)
|
||||||
.disabled(true),
|
.disabled(true),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,112 +1,107 @@
|
||||||
#[cfg(feature = "stories")]
|
use gpui::{actions, Action, AnchorCorner, Div, Render, View};
|
||||||
pub use stories::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "stories")]
|
use crate::prelude::*;
|
||||||
mod stories {
|
use crate::{menu_handle, ContextMenu, Label, ListItem, Story};
|
||||||
use super::*;
|
|
||||||
use crate::{story::Story, Label};
|
|
||||||
use gpui::{actions, Div, Render};
|
|
||||||
|
|
||||||
actions!(PrintCurrentDate, PrintBestFood);
|
actions!(PrintCurrentDate, PrintBestFood);
|
||||||
|
|
||||||
fn build_menu(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, _| {
|
ContextMenu::build(cx, |menu, _| {
|
||||||
menu.header(header)
|
menu.header(header)
|
||||||
.separator()
|
.separator()
|
||||||
.entry(
|
.entry(
|
||||||
ListItem::new("Print current time", Label::new("Print current time")),
|
ListItem::new("Print current time", Label::new("Print current time")),
|
||||||
|v, cx| {
|
|v, cx| {
|
||||||
println!("dispatching PrintCurrentTime action");
|
println!("dispatching PrintCurrentTime action");
|
||||||
cx.dispatch_action(PrintCurrentDate.boxed_clone())
|
cx.dispatch_action(PrintCurrentDate.boxed_clone())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.entry(
|
.entry(
|
||||||
ListItem::new("Print best food", Label::new("Print best food")),
|
ListItem::new("Print best food", Label::new("Print best food")),
|
||||||
|v, cx| cx.dispatch_action(PrintBestFood.boxed_clone()),
|
|v, cx| cx.dispatch_action(PrintBestFood.boxed_clone()),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ContextMenuStory;
|
pub struct ContextMenuStory;
|
||||||
|
|
||||||
impl Render for ContextMenuStory {
|
impl Render for ContextMenuStory {
|
||||||
type Element = Div;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
Story::container(cx)
|
Story::container(cx)
|
||||||
.on_action(|_: &PrintCurrentDate, _| {
|
.on_action(|_: &PrintCurrentDate, _| {
|
||||||
println!("printing unix time!");
|
println!("printing unix time!");
|
||||||
if let Ok(unix_time) = std::time::UNIX_EPOCH.elapsed() {
|
if let Ok(unix_time) = std::time::UNIX_EPOCH.elapsed() {
|
||||||
println!("Current Unix time is {:?}", unix_time.as_secs());
|
println!("Current Unix time is {:?}", unix_time.as_secs());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on_action(|_: &PrintBestFood, _| {
|
.on_action(|_: &PrintBestFood, _| {
|
||||||
println!("burrito");
|
println!("burrito");
|
||||||
})
|
})
|
||||||
.flex()
|
.flex()
|
||||||
.flex_row()
|
.flex_row()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.flex()
|
.flex()
|
||||||
.flex_col()
|
.flex_col()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.child(
|
.child(
|
||||||
menu_handle("test2")
|
menu_handle("test2")
|
||||||
.child(|is_open| {
|
.child(|is_open| {
|
||||||
Label::new(if is_open {
|
Label::new(if is_open {
|
||||||
"TOP LEFT"
|
"TOP LEFT"
|
||||||
} else {
|
} else {
|
||||||
"RIGHT CLICK ME"
|
"RIGHT CLICK ME"
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.menu(move |cx| build_menu(cx, "top left")),
|
})
|
||||||
)
|
.menu(move |cx| build_menu(cx, "top left")),
|
||||||
.child(
|
)
|
||||||
menu_handle("test1")
|
.child(
|
||||||
.child(|is_open| {
|
menu_handle("test1")
|
||||||
Label::new(if is_open {
|
.child(|is_open| {
|
||||||
"BOTTOM LEFT"
|
Label::new(if is_open {
|
||||||
} else {
|
"BOTTOM LEFT"
|
||||||
"RIGHT CLICK ME"
|
} else {
|
||||||
})
|
"RIGHT CLICK ME"
|
||||||
})
|
})
|
||||||
.anchor(AnchorCorner::BottomLeft)
|
})
|
||||||
.attach(AnchorCorner::TopLeft)
|
.anchor(AnchorCorner::BottomLeft)
|
||||||
.menu(move |cx| build_menu(cx, "bottom left")),
|
.attach(AnchorCorner::TopLeft)
|
||||||
),
|
.menu(move |cx| build_menu(cx, "bottom left")),
|
||||||
)
|
),
|
||||||
.child(
|
)
|
||||||
div()
|
.child(
|
||||||
.flex()
|
div()
|
||||||
.flex_col()
|
.flex()
|
||||||
.justify_between()
|
.flex_col()
|
||||||
.child(
|
.justify_between()
|
||||||
menu_handle("test3")
|
.child(
|
||||||
.child(|is_open| {
|
menu_handle("test3")
|
||||||
Label::new(if is_open {
|
.child(|is_open| {
|
||||||
"TOP RIGHT"
|
Label::new(if is_open {
|
||||||
} else {
|
"TOP RIGHT"
|
||||||
"RIGHT CLICK ME"
|
} else {
|
||||||
})
|
"RIGHT CLICK ME"
|
||||||
})
|
})
|
||||||
.anchor(AnchorCorner::TopRight)
|
})
|
||||||
.menu(move |cx| build_menu(cx, "top right")),
|
.anchor(AnchorCorner::TopRight)
|
||||||
)
|
.menu(move |cx| build_menu(cx, "top right")),
|
||||||
.child(
|
)
|
||||||
menu_handle("test4")
|
.child(
|
||||||
.child(|is_open| {
|
menu_handle("test4")
|
||||||
Label::new(if is_open {
|
.child(|is_open| {
|
||||||
"BOTTOM RIGHT"
|
Label::new(if is_open {
|
||||||
} else {
|
"BOTTOM RIGHT"
|
||||||
"RIGHT CLICK ME"
|
} else {
|
||||||
})
|
"RIGHT CLICK ME"
|
||||||
})
|
})
|
||||||
.anchor(AnchorCorner::BottomRight)
|
})
|
||||||
.attach(AnchorCorner::TopRight)
|
.anchor(AnchorCorner::BottomRight)
|
||||||
.menu(move |cx| build_menu(cx, "bottom right")),
|
.attach(AnchorCorner::TopRight)
|
||||||
),
|
.menu(move |cx| build_menu(cx, "bottom right")),
|
||||||
)
|
),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,20 @@
|
||||||
#[cfg(feature = "stories")]
|
use gpui::{Div, Render};
|
||||||
pub use stories::*;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
#[cfg(feature = "stories")]
|
use crate::prelude::*;
|
||||||
mod stories {
|
use crate::{Icon, IconElement, Story};
|
||||||
use gpui::{Div, Render};
|
|
||||||
use strum::IntoEnumIterator;
|
|
||||||
|
|
||||||
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 {
|
Story::container(cx)
|
||||||
type Element = Div;
|
.child(Story::title_for::<IconElement>(cx))
|
||||||
|
.child(Story::label(cx, "All Icons"))
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
.child(div().flex().gap_3().children(icons.map(IconElement::new)))
|
||||||
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)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
#[cfg(feature = "stories")]
|
use gpui::{Div, Render};
|
||||||
pub use stories::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "stories")]
|
use crate::prelude::*;
|
||||||
mod stories {
|
use crate::{Input, Story};
|
||||||
use super::*;
|
|
||||||
use crate::Story;
|
|
||||||
use gpui::{Div, Render};
|
|
||||||
|
|
||||||
pub struct InputStory;
|
pub struct InputStory;
|
||||||
|
|
||||||
impl Render for InputStory {
|
impl Render for InputStory {
|
||||||
type Element = Div;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
Story::container(cx)
|
Story::container(cx)
|
||||||
.child(Story::title_for::<Input>(cx))
|
.child(Story::title_for::<Input>(cx))
|
||||||
.child(Story::label(cx, "Default"))
|
.child(Story::label(cx, "Default"))
|
||||||
.child(div().flex().child(Input::new("Search")))
|
.child(div().flex().child(Input::new("Search")))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,66 +1,60 @@
|
||||||
#[cfg(feature = "stories")]
|
use gpui::{actions, Div, Render};
|
||||||
pub use stories::*;
|
use itertools::Itertools;
|
||||||
|
|
||||||
#[cfg(feature = "stories")]
|
use crate::prelude::*;
|
||||||
mod stories {
|
use crate::{KeyBinding, Story};
|
||||||
use super::*;
|
|
||||||
pub use crate::KeyBinding;
|
|
||||||
use crate::Story;
|
|
||||||
use gpui::{actions, Div, Render};
|
|
||||||
use itertools::Itertools;
|
|
||||||
pub struct KeybindingStory;
|
|
||||||
|
|
||||||
actions!(NoAction);
|
pub struct KeybindingStory;
|
||||||
|
|
||||||
pub fn binding(key: &str) -> gpui::KeyBinding {
|
actions!(NoAction);
|
||||||
gpui::KeyBinding::new(key, NoAction {}, None)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Render for KeybindingStory {
|
pub fn binding(key: &str) -> gpui::KeyBinding {
|
||||||
type Element = Div;
|
gpui::KeyBinding::new(key, NoAction {}, None)
|
||||||
|
}
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
impl Render for KeybindingStory {
|
||||||
let all_modifier_permutations =
|
type Element = Div;
|
||||||
["ctrl", "alt", "cmd", "shift"].into_iter().permutations(2);
|
|
||||||
|
|
||||||
Story::container(cx)
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
.child(Story::title_for::<KeyBinding>(cx))
|
let all_modifier_permutations = ["ctrl", "alt", "cmd", "shift"].into_iter().permutations(2);
|
||||||
.child(Story::label(cx, "Single Key"))
|
|
||||||
.child(KeyBinding::new(binding("Z")))
|
Story::container(cx)
|
||||||
.child(Story::label(cx, "Single Key with Modifier"))
|
.child(Story::title_for::<KeyBinding>(cx))
|
||||||
.child(
|
.child(Story::label(cx, "Single Key"))
|
||||||
div()
|
.child(KeyBinding::new(binding("Z")))
|
||||||
.flex()
|
.child(Story::label(cx, "Single Key with Modifier"))
|
||||||
.gap_3()
|
.child(
|
||||||
.child(KeyBinding::new(binding("ctrl-c")))
|
div()
|
||||||
.child(KeyBinding::new(binding("alt-c")))
|
.flex()
|
||||||
.child(KeyBinding::new(binding("cmd-c")))
|
.gap_3()
|
||||||
.child(KeyBinding::new(binding("shift-c"))),
|
.child(KeyBinding::new(binding("ctrl-c")))
|
||||||
)
|
.child(KeyBinding::new(binding("alt-c")))
|
||||||
.child(Story::label(cx, "Single Key with Modifier (Permuted)"))
|
.child(KeyBinding::new(binding("cmd-c")))
|
||||||
.child(
|
.child(KeyBinding::new(binding("shift-c"))),
|
||||||
div().flex().flex_col().children(
|
)
|
||||||
all_modifier_permutations
|
.child(Story::label(cx, "Single Key with Modifier (Permuted)"))
|
||||||
.chunks(4)
|
.child(
|
||||||
.into_iter()
|
div().flex().flex_col().children(
|
||||||
.map(|chunk| {
|
all_modifier_permutations
|
||||||
div()
|
.chunks(4)
|
||||||
.flex()
|
.into_iter()
|
||||||
.gap_4()
|
.map(|chunk| {
|
||||||
.py_3()
|
div()
|
||||||
.children(chunk.map(|permutation| {
|
.flex()
|
||||||
KeyBinding::new(binding(&*(permutation.join("-") + "-x")))
|
.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, "Single Key with All Modifiers"))
|
||||||
.child(Story::label(cx, "Chord with Modifier"))
|
.child(KeyBinding::new(binding("ctrl-alt-cmd-shift-z")))
|
||||||
.child(KeyBinding::new(binding("ctrl-a shift-z")))
|
.child(Story::label(cx, "Chord"))
|
||||||
.child(KeyBinding::new(binding("fn-s")))
|
.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")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,26 @@
|
||||||
#[cfg(feature = "stories")]
|
use gpui::{Div, Render};
|
||||||
pub use stories::*;
|
|
||||||
|
|
||||||
#[cfg(feature = "stories")]
|
use crate::prelude::*;
|
||||||
mod stories {
|
use crate::{HighlightedLabel, Label, Story};
|
||||||
use super::*;
|
|
||||||
use crate::Story;
|
|
||||||
use gpui::{Div, Render};
|
|
||||||
|
|
||||||
pub struct LabelStory;
|
pub struct LabelStory;
|
||||||
|
|
||||||
impl Render for LabelStory {
|
impl Render for LabelStory {
|
||||||
type Element = Div;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
Story::container(cx)
|
Story::container(cx)
|
||||||
.child(Story::title_for::<Label>(cx))
|
.child(Story::title_for::<Label>(cx))
|
||||||
.child(Story::label(cx, "Default"))
|
.child(Story::label(cx, "Default"))
|
||||||
.child(Label::new("Hello, world!"))
|
.child(Label::new("Hello, world!"))
|
||||||
.child(Story::label(cx, "Highlighted"))
|
.child(Story::label(cx, "Highlighted"))
|
||||||
.child(HighlightedLabel::new(
|
.child(HighlightedLabel::new(
|
||||||
"Hello, world!",
|
"Hello, world!",
|
||||||
vec![0, 1, 2, 7, 8, 12],
|
vec![0, 1, 2, 7, 8, 12],
|
||||||
))
|
))
|
||||||
.child(HighlightedLabel::new(
|
.child(HighlightedLabel::new(
|
||||||
"Héllo, world!",
|
"Héllo, world!",
|
||||||
vec![0, 1, 3, 8, 9, 13],
|
vec![0, 1, 3, 8, 9, 13],
|
||||||
))
|
))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue