This commit is contained in:
Cecile Tonglet 2020-09-14 07:01:53 +02:00
parent 6089ca39c7
commit e3ad2d2ed2
5 changed files with 24 additions and 14 deletions

View file

@ -8,6 +8,7 @@ pub struct Button {
pub struct Props {
#[prop_or_default]
pub title: String,
#[prop_or_default]
pub onclick: Callback<MouseEvent>,
pub children: html::Children,
}
@ -35,7 +36,9 @@ impl Component for Button {
fn view(&self) -> Html {
html! {
<button class="bp3-button" onclick={self.props.onclick.clone()}>{self.props.children.clone()}</button>
<button class="bp3-button" onclick={self.props.onclick.clone()}>
{self.props.children.clone()}
</button>
}
}
}

View file

@ -8,7 +8,9 @@ pub struct Switch {
pub struct Props {
#[prop_or_default]
pub checked: bool,
#[prop_or_default]
pub onclick: Callback<MouseEvent>,
#[prop_or_default]
pub label: String,
}

View file

@ -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)

View file

@ -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<Intent> for &'static str {
impl From<Intent> for Classes {
fn from(intent: Intent) -> Self {
match intent {
Classes::from(intent.as_ref())
}
}
impl AsRef<str> 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",

View file

@ -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! {
<li class="bp3-tree-node">
<div class=content_class>
{
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! {
<Icon
class=class
class=class.to_string()
icon=IconName::ChevronRight
onclick={
if self.props.disabled {