Remove unneeded wrapping div
s in ListItem
left content (#3438)
This PR removes some unneeded wrapping `div`s around the left content in `ListItem`s. Release Notes: - N/A
This commit is contained in:
commit
043cef89eb
2 changed files with 26 additions and 16 deletions
|
@ -285,19 +285,6 @@ impl RenderOnce for ListItem {
|
||||||
type Rendered = Stateful<Div>;
|
type Rendered = Stateful<Div>;
|
||||||
|
|
||||||
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
|
||||||
let left_content = match self.left_slot.clone() {
|
|
||||||
Some(GraphicSlot::Icon(i)) => Some(
|
|
||||||
h_stack().child(
|
|
||||||
IconElement::new(i)
|
|
||||||
.size(IconSize::Small)
|
|
||||||
.color(Color::Muted),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Some(GraphicSlot::Avatar(src)) => Some(h_stack().child(Avatar::source(src))),
|
|
||||||
Some(GraphicSlot::PublicActor(src)) => Some(h_stack().child(Avatar::uri(src))),
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.id(self.id)
|
.id(self.id)
|
||||||
.relative()
|
.relative()
|
||||||
|
@ -312,7 +299,7 @@ impl RenderOnce for ListItem {
|
||||||
.when(self.selected, |this| {
|
.when(self.selected, |this| {
|
||||||
this.bg(cx.theme().colors().ghost_element_selected)
|
this.bg(cx.theme().colors().ghost_element_selected)
|
||||||
})
|
})
|
||||||
.when_some(self.on_click.clone(), |this, on_click| {
|
.when_some(self.on_click, |this, on_click| {
|
||||||
this.cursor_pointer().on_click(move |event, cx| {
|
this.cursor_pointer().on_click(move |event, cx| {
|
||||||
// HACK: GPUI currently fires `on_click` with any mouse button,
|
// HACK: GPUI currently fires `on_click` with any mouse button,
|
||||||
// but we only care about the left button.
|
// but we only care about the left button.
|
||||||
|
@ -335,7 +322,16 @@ impl RenderOnce for ListItem {
|
||||||
.items_center()
|
.items_center()
|
||||||
.relative()
|
.relative()
|
||||||
.child(disclosure_control(self.toggle, self.on_toggle))
|
.child(disclosure_control(self.toggle, self.on_toggle))
|
||||||
.children(left_content)
|
.map(|this| match self.left_slot {
|
||||||
|
Some(GraphicSlot::Icon(i)) => this.child(
|
||||||
|
IconElement::new(i)
|
||||||
|
.size(IconSize::Small)
|
||||||
|
.color(Color::Muted),
|
||||||
|
),
|
||||||
|
Some(GraphicSlot::Avatar(src)) => this.child(Avatar::source(src)),
|
||||||
|
Some(GraphicSlot::PublicActor(src)) => this.child(Avatar::uri(src)),
|
||||||
|
None => this,
|
||||||
|
})
|
||||||
.children(self.children),
|
.children(self.children),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use gpui::{Div, Render};
|
||||||
use story::Story;
|
use story::Story;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::ListItem;
|
use crate::{Icon, ListItem};
|
||||||
|
|
||||||
pub struct ListItemStory;
|
pub struct ListItemStory;
|
||||||
|
|
||||||
|
@ -14,6 +14,20 @@ impl Render for ListItemStory {
|
||||||
.child(Story::title_for::<ListItem>())
|
.child(Story::title_for::<ListItem>())
|
||||||
.child(Story::label("Default"))
|
.child(Story::label("Default"))
|
||||||
.child(ListItem::new("hello_world").child("Hello, world!"))
|
.child(ListItem::new("hello_world").child("Hello, world!"))
|
||||||
|
.child(Story::label("With left icon"))
|
||||||
|
.child(
|
||||||
|
ListItem::new("with_left_icon")
|
||||||
|
.child("Hello, world!")
|
||||||
|
.left_icon(Icon::Bell),
|
||||||
|
)
|
||||||
|
.child(Story::label("With left avatar"))
|
||||||
|
.child(
|
||||||
|
ListItem::new("with_left_avatar")
|
||||||
|
.child("Hello, world!")
|
||||||
|
.left_avatar(SharedString::from(
|
||||||
|
"https://avatars.githubusercontent.com/u/1714999?v=4",
|
||||||
|
)),
|
||||||
|
)
|
||||||
.child(Story::label("With `on_click`"))
|
.child(Story::label("With `on_click`"))
|
||||||
.child(
|
.child(
|
||||||
ListItem::new("with_on_click")
|
ListItem::new("with_on_click")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue