mirror of
https://github.com/yewprint/yewprint
synced 2024-11-28 22:40:22 +00:00
Clean-up
This commit is contained in:
parent
6089ca39c7
commit
e3ad2d2ed2
5 changed files with 24 additions and 14 deletions
|
@ -8,6 +8,7 @@ pub struct Button {
|
||||||
pub struct Props {
|
pub struct Props {
|
||||||
#[prop_or_default]
|
#[prop_or_default]
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
#[prop_or_default]
|
||||||
pub onclick: Callback<MouseEvent>,
|
pub onclick: Callback<MouseEvent>,
|
||||||
pub children: html::Children,
|
pub children: html::Children,
|
||||||
}
|
}
|
||||||
|
@ -35,7 +36,9 @@ impl Component for Button {
|
||||||
|
|
||||||
fn view(&self) -> Html {
|
fn view(&self) -> Html {
|
||||||
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>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,9 @@ pub struct Switch {
|
||||||
pub struct Props {
|
pub struct Props {
|
||||||
#[prop_or_default]
|
#[prop_or_default]
|
||||||
pub checked: bool,
|
pub checked: bool,
|
||||||
|
#[prop_or_default]
|
||||||
pub onclick: Callback<MouseEvent>,
|
pub onclick: Callback<MouseEvent>,
|
||||||
|
#[prop_or_default]
|
||||||
pub label: String,
|
pub label: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,9 @@ impl Component for Icon {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Html {
|
fn view(&self) -> Html {
|
||||||
let mut class = "bp3-icon ".to_string();
|
let mut class = Classes::from("bp3-icon");
|
||||||
class.push_str(self.props.class.as_str());
|
class.push(self.props.class.as_str());
|
||||||
class.push_str(" ");
|
class = class.extend(&self.props.intent);
|
||||||
if let Some(intent) = self.props.intent {
|
|
||||||
class.push_str(intent.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let paths = if self.props.icon_size == SIZE_STANDARD {
|
let paths = if self.props.icon_size == SIZE_STANDARD {
|
||||||
icon_svg_paths_16(self.props.icon)
|
icon_svg_paths_16(self.props.icon)
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -8,6 +8,8 @@ pub mod forms;
|
||||||
pub mod icon;
|
pub mod icon;
|
||||||
pub mod tree;
|
pub mod tree;
|
||||||
|
|
||||||
|
use yew::virtual_dom::Classes;
|
||||||
|
|
||||||
#[cfg(feature = "dev")]
|
#[cfg(feature = "dev")]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! log {
|
macro_rules! log {
|
||||||
|
@ -32,9 +34,15 @@ pub enum Intent {
|
||||||
Danger,
|
Danger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Intent> for &'static str {
|
impl From<Intent> for Classes {
|
||||||
fn from(intent: Intent) -> Self {
|
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::Primary => "bp3-intent-primary",
|
||||||
Intent::Success => "bp3-intent-success",
|
Intent::Success => "bp3-intent-success",
|
||||||
Intent::Warning => "bp3-intent-warning",
|
Intent::Warning => "bp3-intent-warning",
|
||||||
|
|
10
src/tree.rs
10
src/tree.rs
|
@ -192,16 +192,16 @@ impl Component for TreeNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Html {
|
fn view(&self) -> Html {
|
||||||
let mut content_class = "bp3-tree-node-content ".to_string();
|
let mut content_class = Classes::from("bp3-tree-node-content");
|
||||||
content_class.push_str(&format!("bp3-tree-node-content-{}", self.props.depth));
|
content_class.push(&format!("bp3-tree-node-content-{}", self.props.depth));
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
<li class="bp3-tree-node">
|
<li class="bp3-tree-node">
|
||||||
<div class=content_class>
|
<div class=content_class>
|
||||||
{
|
{
|
||||||
if self.props.has_caret {
|
if self.props.has_caret {
|
||||||
let mut class = "bp3-tree-node-caret ".to_string();
|
let mut class = Classes::from("bp3-tree-node-caret");
|
||||||
class.push_str(if self.props.is_expanded {
|
class.push(if self.props.is_expanded {
|
||||||
"bp3-tree-node-caret-open"
|
"bp3-tree-node-caret-open"
|
||||||
} else {
|
} else {
|
||||||
"bp3-tree-node-caret-closed"
|
"bp3-tree-node-caret-closed"
|
||||||
|
@ -209,7 +209,7 @@ impl Component for TreeNode {
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
<Icon
|
<Icon
|
||||||
class=class
|
class=class.to_string()
|
||||||
icon=IconName::ChevronRight
|
icon=IconName::ChevronRight
|
||||||
onclick={
|
onclick={
|
||||||
if self.props.disabled {
|
if self.props.disabled {
|
||||||
|
|
Loading…
Reference in a new issue