27 changed files with 600 additions and 496 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, |
||||
} |
||||
} |
||||
} |
@ -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, |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@
|
||||
use super::InputType; |
||||
use crate::{ |
||||
prelude::*, |
||||
props::{collect_props, BootstrapProps}, |
||||
}; |
||||
use std::collections::HashMap; |
||||
use yew::{html::Children, prelude::*}; |
||||
|
||||
#[derive(Properties, Clone, PartialEq)] |
||||
pub struct Props { |
||||
// component specific
|
||||
#[prop_or_default] |
||||
pub name: Option<String>, |
||||
#[prop_or_default] |
||||
pub value: String, |
||||
#[prop_or_default] |
||||
pub valid: Option<bool>, |
||||
pub on_change: Callback<String>, |
||||
#[prop_or_default] |
||||
pub readonly: bool, |
||||
#[prop_or_default] |
||||
pub input_type: Option<InputType>, |
||||
|
||||
// bootstrap specific
|
||||
#[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>, |
||||
|
||||
// html specific
|
||||
#[prop_or_default] |
||||
pub id: Option<String>, |
||||
#[prop_or_default] |
||||
pub class: Classes, |
||||
#[prop_or_default] |
||||
pub style: Option<String>, |
||||
#[prop_or_default] |
||||
pub children: Children, |
||||
} |
||||
|
||||
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 mut attributes = HashMap::new(); |
||||
if let Some(ref style) = props.style { |
||||
attributes.insert("style", style); |
||||
} |
||||
if let Some(ref id) = props.id { |
||||
attributes.insert("id", id); |
||||
} |
||||
if let Some(ref name) = props.name { |
||||
attributes.insert("name", name); |
||||
} |
||||
BootstrapProps { |
||||
class, |
||||
borders, |
||||
margins, |
||||
paddings, |
||||
attributes, |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,54 @@
|
||||
use std::fmt::{Display, Formatter, Result}; |
||||
|
||||
#[derive(Debug, Clone, PartialEq)] |
||||
pub enum Edge { |
||||
All, |
||||
Top, |
||||
Right, |
||||
Bottom, |
||||
Left, |
||||
LeftAndRight, |
||||
TopAndBottom, |
||||
} |
||||
|
||||
impl Display for Edge { |
||||
fn fmt(&self, fmt: &mut Formatter) -> Result { |
||||
match self { |
||||
Self::All => write!(fmt, ""), |
||||
Self::Top => write!(fmt, "t"), |
||||
Self::Bottom => write!(fmt, "b"), |
||||
Self::Right => write!(fmt, "r"), |
||||
Self::Left => write!(fmt, "l"), |
||||
Self::LeftAndRight => write!(fmt, "x"), |
||||
Self::TopAndBottom => write!(fmt, "y"), |
||||
} |
||||
} |
||||
} |
||||
|
||||
impl Edge { |
||||
fn suffix(&self) -> &str { |
||||
match self { |
||||
Self::Top => "-top", |
||||
_ => "", |
||||
} |
||||
} |
||||
|
||||
pub(crate) fn with_prefix<S: AsRef<str>>(&self, prefix: S) -> String { |
||||
match self { |
||||
Self::All => prefix.as_ref().to_owned(), |
||||
Self::LeftAndRight => format!( |
||||
"{0}{1} {0}{2}", |
||||
prefix.as_ref(), |
||||
Self::Left.suffix(), |
||||
Self::Right.suffix() |
||||
), |
||||
Self::TopAndBottom => format!( |
||||
"{0}{1} {0}{2}", |
||||
prefix.as_ref(), |
||||
Self::Top.suffix(), |
||||
Self::Bottom.suffix() |
||||
), |
||||
_ => format!("{}{}", prefix.as_ref(), self.suffix()), |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,142 @@
|
||||
use crate::prelude::*; |
||||
use std::collections::HashMap; |
||||
use yew::{prelude::*, virtual_dom::VNode}; |
||||
|
||||
pub(crate) trait IntoBsClass { |
||||
fn as_classname(&self) -> String; |
||||
} |
||||
|
||||
pub(crate) fn collect_props<'a, T>(t: &'a Option<T>, ts: &'a [T]) -> Vec<&'a T> { |
||||
if let Some(t) = t.as_ref() { |
||||
let mut r = vec![t]; |
||||
r.append(&mut ts.iter().collect()); |
||||
r |
||||
} else { |
||||
ts.iter().collect() |
||||
} |
||||
} |
||||
|
||||