From e3ad2d2ed261abb7c6b423a519076f93abacaba1 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 14 Sep 2020 07:01:53 +0200 Subject: [PATCH] Clean-up --- src/buttons.rs | 5 ++++- src/forms/controls.rs | 2 ++ src/icon.rs | 9 +++------ src/lib.rs | 12 ++++++++++-- src/tree.rs | 10 +++++----- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/buttons.rs b/src/buttons.rs index 2084845..6321666 100644 --- a/src/buttons.rs +++ b/src/buttons.rs @@ -8,6 +8,7 @@ pub struct Button { pub struct Props { #[prop_or_default] pub title: String, + #[prop_or_default] pub onclick: Callback, pub children: html::Children, } @@ -35,7 +36,9 @@ impl Component for Button { fn view(&self) -> Html { html! { - + } } } diff --git a/src/forms/controls.rs b/src/forms/controls.rs index ec65573..f9ef6bf 100644 --- a/src/forms/controls.rs +++ b/src/forms/controls.rs @@ -8,7 +8,9 @@ pub struct Switch { pub struct Props { #[prop_or_default] pub checked: bool, + #[prop_or_default] pub onclick: Callback, + #[prop_or_default] pub label: String, } diff --git a/src/icon.rs b/src/icon.rs index c5e801d..282a831 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -55,12 +55,9 @@ impl Component for Icon { } fn view(&self) -> Html { - let mut class = "bp3-icon ".to_string(); - class.push_str(self.props.class.as_str()); - class.push_str(" "); - if let Some(intent) = self.props.intent { - class.push_str(intent.into()); - } + let mut class = Classes::from("bp3-icon"); + class.push(self.props.class.as_str()); + class = class.extend(&self.props.intent); let paths = if self.props.icon_size == SIZE_STANDARD { icon_svg_paths_16(self.props.icon) diff --git a/src/lib.rs b/src/lib.rs index eb2177a..0ad9a81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,8 @@ pub mod forms; pub mod icon; pub mod tree; +use yew::virtual_dom::Classes; + #[cfg(feature = "dev")] #[macro_export] macro_rules! log { @@ -32,9 +34,15 @@ pub enum Intent { Danger, } -impl From for &'static str { +impl From for Classes { fn from(intent: Intent) -> Self { - match intent { + Classes::from(intent.as_ref()) + } +} + +impl AsRef for Intent { + fn as_ref(&self) -> &'static str { + match self { Intent::Primary => "bp3-intent-primary", Intent::Success => "bp3-intent-success", Intent::Warning => "bp3-intent-warning", diff --git a/src/tree.rs b/src/tree.rs index bb42670..6bcc809 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -192,16 +192,16 @@ impl Component for TreeNode { } fn view(&self) -> Html { - let mut content_class = "bp3-tree-node-content ".to_string(); - content_class.push_str(&format!("bp3-tree-node-content-{}", self.props.depth)); + let mut content_class = Classes::from("bp3-tree-node-content"); + content_class.push(&format!("bp3-tree-node-content-{}", self.props.depth)); html! {
  • { if self.props.has_caret { - let mut class = "bp3-tree-node-caret ".to_string(); - class.push_str(if self.props.is_expanded { + let mut class = Classes::from("bp3-tree-node-caret"); + class.push(if self.props.is_expanded { "bp3-tree-node-caret-open" } else { "bp3-tree-node-caret-closed" @@ -209,7 +209,7 @@ impl Component for TreeNode { html! {