From bd3cdd716767b537cecc4c56cba70f24bc469f40 Mon Sep 17 00:00:00 2001 From: Floyd Wang Date: Fri, 17 Jan 2025 16:24:46 +0800 Subject: [PATCH] dropdown_button: Add more style preferences (#554) --- crates/story/src/button_story.rs | 32 ++++-- crates/ui/src/button/button.rs | 1 + crates/ui/src/button/dropdown_button.rs | 130 ++++++++++++++++-------- 3 files changed, 111 insertions(+), 52 deletions(-) diff --git a/crates/story/src/button_story.rs b/crates/story/src/button_story.rs index d5eee0c9..17bdc1cc 100644 --- a/crates/story/src/button_story.rs +++ b/crates/story/src/button_story.rs @@ -552,16 +552,28 @@ impl Render for ButtonStory { ), ) .child( - section("Dropdown Button", cx).child( - DropdownButton::new("dropdown-button") - .button(Button::new("dropdown-button-button").label("Click Me")) - .popup_menu(move |this, _| { - this.menu("Disabled", Box::new(Disabled)) - .menu("Loading", Box::new(Loading)) - .menu("Selected", Box::new(Selected)) - .menu("Compact", Box::new(Compact)) - }), - ), + section("Dropdown Button", cx) + .child( + DropdownButton::new("dropdown-button1") + .small() + .button(Button::new("dropdown-button-button1").label("Click Me")) + .popup_menu(move |this, _| { + this.menu("Disabled", Box::new(Disabled)) + .menu("Loading", Box::new(Loading)) + .menu("Selected", Box::new(Selected)) + .menu("Compact", Box::new(Compact)) + }), + ) + .child( + DropdownButton::new("dropdown-button") + .button(Button::new("dropdown-button-button").label("Click Me")) + .popup_menu(move |this, _| { + this.menu("Disabled", Box::new(Disabled)) + .menu("Loading", Box::new(Loading)) + .menu("Selected", Box::new(Selected)) + .menu("Compact", Box::new(Compact)) + }), + ), ) .child( section("Icon Button", cx) diff --git a/crates/ui/src/button/button.rs b/crates/ui/src/button/button.rs index 79498641..cb03c5b8 100644 --- a/crates/ui/src/button/button.rs +++ b/crates/ui/src/button/button.rs @@ -11,6 +11,7 @@ use gpui::{ RenderOnce, SharedString, StatefulInteractiveElement as _, Styled, WindowContext, }; +#[derive(Clone, Copy)] pub enum ButtonRounded { None, Small, diff --git a/crates/ui/src/button/dropdown_button.rs b/crates/ui/src/button/dropdown_button.rs index 003898a9..51b02512 100644 --- a/crates/ui/src/button/dropdown_button.rs +++ b/crates/ui/src/button/dropdown_button.rs @@ -1,48 +1,47 @@ use gpui::{ - prelude::FluentBuilder, Corner, Corners, Edges, ElementId, IntoElement, ParentElement, - RenderOnce, ViewContext, WindowContext, + prelude::FluentBuilder, Corner, Corners, Div, Edges, ElementId, IntoElement, ParentElement, + RenderOnce, Styled, ViewContext, WindowContext, }; use crate::{ h_flex, popup_menu::{PopupMenu, PopupMenuExt}, - IconName, + IconName, Sizable, Size, }; -use super::Button; +use super::{Button, ButtonRounded, ButtonVariant, ButtonVariants}; #[derive(IntoElement)] pub struct DropdownButton { + base: Div, id: ElementId, button: Option