Re-factor props and attrs handling.
This commit is contained in:
parent
c6ba1f9b11
commit
6236cf6ae9
27 changed files with 604 additions and 500 deletions
|
@ -1,17 +0,0 @@
|
|||
use super::Props;
|
||||
use crate::prelude::*;
|
||||
|
||||
impl<'a> From<&'a Props> for BootstrapProps<'a> {
|
||||
fn from(props: &Props) -> BootstrapProps {
|
||||
let class = &props.class;
|
||||
let borders = collect_bs(&props.border, &props.borders);
|
||||
let margins = collect_bs(&props.margin, &props.margins);
|
||||
let paddings = collect_bs(&props.padding, &props.paddings);
|
||||
BootstrapProps {
|
||||
class,
|
||||
borders,
|
||||
margins,
|
||||
paddings,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +1,14 @@
|
|||
mod convert;
|
||||
mod props;
|
||||
|
||||
use crate::prelude::*;
|
||||
use yew::{html::Children, prelude::*};
|
||||
use self::props::Props;
|
||||
use crate::{prelude::*, render};
|
||||
use yew::prelude::*;
|
||||
|
||||
pub struct Alert {
|
||||
link: ComponentLink<Self>,
|
||||
props: Props,
|
||||
}
|
||||
|
||||
#[derive(Properties, Default, Clone, PartialEq)]
|
||||
pub struct Props {
|
||||
pub on_close: Callback<()>,
|
||||
pub color: Color,
|
||||
#[prop_or_default]
|
||||
pub aria_label: String,
|
||||
#[prop_or_default]
|
||||
pub role: String,
|
||||
#[prop_or_default]
|
||||
pub border: Option<Border>,
|
||||
#[prop_or_default]
|
||||
pub borders: Vec<Border>,
|
||||
#[prop_or_default]
|
||||
pub margin: Option<Margin>,
|
||||
#[prop_or_default]
|
||||
pub margins: Vec<Margin>,
|
||||
#[prop_or_default]
|
||||
pub padding: Option<Padding>,
|
||||
#[prop_or_default]
|
||||
pub paddings: Vec<Padding>,
|
||||
#[prop_or_default]
|
||||
pub class: String,
|
||||
#[prop_or_default]
|
||||
pub style: String,
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
}
|
||||
|
||||
impl Component for Alert {
|
||||
type Properties = Props;
|
||||
type Message = ();
|
||||
|
@ -54,10 +27,8 @@ impl Component for Alert {
|
|||
}
|
||||
|
||||
fn view(&self) -> Html {
|
||||
let color_class = self.props.color.with_prefix("alert");
|
||||
let class = calculate_classes(format!("alert {}", color_class), (&self.props).into());
|
||||
html! {
|
||||
<div class=class>
|
||||
let html = html! {
|
||||
<div>
|
||||
{ self.props.children.render() }
|
||||
<button
|
||||
type="button"
|
||||
|
@ -69,6 +40,11 @@ impl Component for Alert {
|
|||
<span aria-hidden="true">{ "×" }</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
};
|
||||
render::render_with_prefix(
|
||||
&self.props,
|
||||
vec!["alert", &self.props.color.with_prefix("alert")],
|
||||
html,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
55
src/alert/props.rs
Normal file
55
src/alert/props.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use crate::{prelude::*, props::*};
|
||||
use std::collections::HashMap;
|
||||
use yew::prelude::*;
|
||||
|
||||
#[derive(Properties, Default, Clone, PartialEq)]
|
||||
pub struct Props {
|
||||
// component specific
|
||||
pub on_close: Callback<()>,
|
||||
pub color: Color,
|
||||
|
||||
// html specific
|
||||
#[prop_or_default]
|
||||
pub id: Option<String>,
|
||||
#[prop_or_default]
|
||||
pub class: Classes,
|
||||
#[prop_or_default]
|
||||
pub style: String,
|
||||
#[prop_or_default]
|
||||
pub aria_label: Option<String>,
|
||||
#[prop_or_default]
|
||||
pub role: Option<String>,
|
||||
#[prop_or_default]
|
||||
pub children: Children,
|
||||
|
||||
// bootstrap
|
||||
#[prop_or_default]
|
||||
pub border: Option<Border>,
|
||||
#[prop_or_default]
|
||||
pub borders: Vec<Border>,
|
||||
#[prop_or_default]
|
||||
pub margin: Option<Margin>,
|
||||
#[prop_or_default]
|
||||
pub margins: Vec<Margin>,
|
||||
#[prop_or_default]
|
||||
pub padding: Option<Padding>,
|
||||
#[prop_or_default]
|
||||
pub paddings: Vec<Padding>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Props> for BootstrapProps<'a> {
|
||||
fn from(props: &Props) -> BootstrapProps {
|
||||
let class = &props.class;
|
||||
let borders = collect_props(&props.border, &props.borders);
|
||||
let margins = collect_props(&props.margin, &props.margins);
|
||||
let paddings = collect_props(&props.padding, &props.paddings);
|
||||
let attributes = HashMap::new();
|
||||
BootstrapProps {
|
||||
class,
|
||||
borders,
|
||||
margins,
|
||||
paddings,
|
||||
attributes,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue