From 4fed1310a4a7a9c1bfec545299ab61597d78919e Mon Sep 17 00:00:00 2001 From: luoxiao Date: Mon, 16 Oct 2023 21:15:43 +0800 Subject: [PATCH] feat: enum prop --- demo/src/components/site_header.rs | 2 +- demo/src/pages/alert/mod.rs | 12 +++--- demo/src/pages/button/mod.rs | 60 +++++++++++++++--------------- demo/src/pages/components.rs | 4 +- demo/src/pages/home.rs | 4 +- demo/src/pages/input/mod.rs | 4 +- demo/src/pages/space/mod.rs | 8 ++-- src/alert/mod.rs | 30 +++++++-------- src/button/mod.rs | 46 +++++++++++------------ src/input/mod.rs | 8 ++-- src/layout/mod.rs | 10 ++--- src/space/mod.rs | 21 ++++++----- 12 files changed, 105 insertions(+), 104 deletions(-) diff --git a/demo/src/components/site_header.rs b/demo/src/components/site_header.rs index 3d758cb..5c79421 100644 --- a/demo/src/components/site_header.rs +++ b/demo/src/components/site_header.rs @@ -17,7 +17,7 @@ pub fn SiteHeader() -> impl IntoView { "Melt UI" - - - + + + + - "PRIMARY" + - - - "#, "rust" @@ -42,26 +42,26 @@ pub fn ButtonPage() -> impl IntoView {

"color"

- - - - + + + + - "PRIMARY Color" + - - - "#, "rust" @@ -74,11 +74,11 @@ pub fn ButtonPage() -> impl IntoView {

"icon"

- - "#, "rust" diff --git a/demo/src/pages/components.rs b/demo/src/pages/components.rs index ee2c327..0c7625a 100644 --- a/demo/src/pages/components.rs +++ b/demo/src/pages/components.rs @@ -25,9 +25,9 @@ pub fn ComponentsPage() -> impl IntoView { selected }); view! { - + - + { diff --git a/demo/src/pages/home.rs b/demo/src/pages/home.rs index 30c619c..de12dae 100644 --- a/demo/src/pages/home.rs +++ b/demo/src/pages/home.rs @@ -11,7 +11,7 @@ pub fn Home() -> impl IntoView { } view! {

"Melt UI"

@@ -22,7 +22,7 @@ pub fn Home() -> impl IntoView { navigate("/components/menu", Default::default()); }>"Read the docs" - + @@ -71,12 +71,12 @@ pub fn SpacePage() -> impl IntoView { slot html=highlight_str!( r#" - + - + diff --git a/src/alert/mod.rs b/src/alert/mod.rs index 280a63c..36b7320 100644 --- a/src/alert/mod.rs +++ b/src/alert/mod.rs @@ -7,31 +7,31 @@ pub use theme::AlertTheme; #[derive(Clone)] pub enum AlertVariant { - SUCCESS, - WARNING, - ERROR, + Success, + Warning, + Error, } impl AlertVariant { pub fn theme_icon_color(&self, theme: &Theme) -> String { match self { - AlertVariant::SUCCESS => theme.common.color_success.clone(), - AlertVariant::WARNING => theme.common.color_warning.clone(), - AlertVariant::ERROR => theme.common.color_error.clone(), + AlertVariant::Success => theme.common.color_success.clone(), + AlertVariant::Warning => theme.common.color_warning.clone(), + AlertVariant::Error => theme.common.color_error.clone(), } } pub fn theme_background_color(&self, theme: &Theme) -> String { match self { - AlertVariant::SUCCESS => theme.alert.success_background_color.clone(), - AlertVariant::WARNING => theme.alert.warning_background_color.clone(), - AlertVariant::ERROR => theme.alert.error_background_color.clone(), + AlertVariant::Success => theme.alert.success_background_color.clone(), + AlertVariant::Warning => theme.alert.warning_background_color.clone(), + AlertVariant::Error => theme.alert.error_background_color.clone(), } } pub fn theme_border_color(&self, theme: &Theme) -> String { match self { - AlertVariant::SUCCESS => theme.alert.success_border_color.clone(), - AlertVariant::WARNING => theme.alert.warning_border_color.clone(), - AlertVariant::ERROR => theme.alert.error_border_color.clone(), + AlertVariant::Success => theme.alert.success_border_color.clone(), + AlertVariant::Warning => theme.alert.warning_border_color.clone(), + AlertVariant::Error => theme.alert.error_border_color.clone(), } } } @@ -72,9 +72,9 @@ pub fn Alert( }); let icon = create_memo(move |_| { match variant.get() { - AlertVariant::SUCCESS => AiIcon::AiCheckCircleFilled, - AlertVariant::WARNING => AiIcon::AiExclamationCircleFilled, - AlertVariant::ERROR => AiIcon::AiCloseCircleFilled, + AlertVariant::Success => AiIcon::AiCheckCircleFilled, + AlertVariant::Warning => AiIcon::AiExclamationCircleFilled, + AlertVariant::Error => AiIcon::AiCloseCircleFilled, } .into() }); diff --git a/src/button/mod.rs b/src/button/mod.rs index ae20207..0f96127 100644 --- a/src/button/mod.rs +++ b/src/button/mod.rs @@ -7,45 +7,45 @@ pub use theme::ButtonTheme; #[derive(Default, PartialEq, Clone, Copy)] pub enum ButtonVariant { #[default] - PRIMARY, - SOLID, - TEXT, - LINK, + Primary, + Solid, + Text, + Link, } #[derive(Default, Clone)] pub enum ButtonColor { #[default] - PRIMARY, - SUCCESS, - WARNING, - ERROR, + Primary, + Success, + Warning, + Error, } impl ButtonColor { pub fn theme_color(&self, theme: &Theme) -> String { match self { - ButtonColor::PRIMARY => theme.common.color_primary.clone(), - ButtonColor::SUCCESS => theme.common.color_success.clone(), - ButtonColor::WARNING => theme.common.color_warning.clone(), - ButtonColor::ERROR => theme.common.color_error.clone(), + ButtonColor::Primary => theme.common.color_primary.clone(), + ButtonColor::Success => theme.common.color_success.clone(), + ButtonColor::Warning => theme.common.color_warning.clone(), + ButtonColor::Error => theme.common.color_error.clone(), } } pub fn theme_color_hover(&self, theme: &Theme) -> String { match self { - ButtonColor::PRIMARY => theme.common.color_primary_hover.clone(), - ButtonColor::SUCCESS => theme.common.color_success_hover.clone(), - ButtonColor::WARNING => theme.common.color_warning_hover.clone(), - ButtonColor::ERROR => theme.common.color_error_hover.clone(), + ButtonColor::Primary => theme.common.color_primary_hover.clone(), + ButtonColor::Success => theme.common.color_success_hover.clone(), + ButtonColor::Warning => theme.common.color_warning_hover.clone(), + ButtonColor::Error => theme.common.color_error_hover.clone(), } } pub fn theme_color_active(&self, theme: &Theme) -> String { match self { - ButtonColor::PRIMARY => theme.common.color_primary_active.clone(), - ButtonColor::SUCCESS => theme.common.color_success_active.clone(), - ButtonColor::WARNING => theme.common.color_warning_active.clone(), - ButtonColor::ERROR => theme.common.color_error_active.clone(), + ButtonColor::Primary => theme.common.color_primary_active.clone(), + ButtonColor::Success => theme.common.color_success_active.clone(), + ButtonColor::Warning => theme.common.color_warning_active.clone(), + ButtonColor::Error => theme.common.color_error_active.clone(), } } } @@ -69,7 +69,7 @@ pub fn Button( let bg_color = color.get().theme_color(&theme); let bg_color_hover = color.get().theme_color_hover(&theme); let bg_color_active = color.get().theme_color_active(&theme); - if variant.get() == ButtonVariant::PRIMARY { + if variant.get() == ButtonVariant::Primary { css_vars.push_str(&format!("--background-color: {bg_color};")); css_vars.push_str(&format!("--background-color-hover: {bg_color_hover};")); css_vars.push_str(&format!("--background-color-active: {bg_color_active};")); @@ -113,8 +113,8 @@ pub fn Button( view! {