Initial commit
This commit is contained in:
commit
96b6152d7b
20 changed files with 914 additions and 0 deletions
20
src/prelude/border.rs
Normal file
20
src/prelude/border.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
#[derive(Clone, PartialEq)]
|
||||
pub enum Border {
|
||||
All,
|
||||
Top,
|
||||
Right,
|
||||
Bottom,
|
||||
Left,
|
||||
}
|
||||
|
||||
impl super::BootstrapClass for Border {
|
||||
fn as_classname(&self) -> String {
|
||||
match self {
|
||||
Self::All => "border".into(),
|
||||
Self::Top => "border-top".into(),
|
||||
Self::Right => "border-right".into(),
|
||||
Self::Bottom => "border-bottom".into(),
|
||||
Self::Left => "border-left".into(),
|
||||
}
|
||||
}
|
||||
}
|
22
src/prelude/border_color.rs
Normal file
22
src/prelude/border_color.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
#[derive(Clone, PartialEq)]
|
||||
pub enum BorderColor {
|
||||
Primary,
|
||||
Secondary,
|
||||
Unset,
|
||||
}
|
||||
|
||||
impl Default for BorderColor {
|
||||
fn default() -> Self {
|
||||
BorderColor::Unset
|
||||
}
|
||||
}
|
||||
|
||||
impl super::BootstrapClass for BorderColor {
|
||||
fn as_classname(&self) -> String {
|
||||
match self {
|
||||
Self::Primary => "border-primary".into(),
|
||||
Self::Secondary => "border-secondary".into(),
|
||||
Self::Unset => "".into(),
|
||||
}
|
||||
}
|
||||
}
|
8
src/prelude/margin.rs
Normal file
8
src/prelude/margin.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Margin(pub super::Edge, pub usize);
|
||||
|
||||
impl super::BootstrapClass for Margin {
|
||||
fn as_classname(&self) -> String {
|
||||
format!("m{}-{}", self.0, self.1)
|
||||
}
|
||||
}
|
76
src/prelude/mod.rs
Normal file
76
src/prelude/mod.rs
Normal file
|
@ -0,0 +1,76 @@
|
|||
mod border;
|
||||
mod border_color;
|
||||
mod margin;
|
||||
|
||||
pub use self::{border::Border, border_color::BorderColor, margin::Margin};
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
use yew::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Edge {
|
||||
Top,
|
||||
Right,
|
||||
Bottom,
|
||||
Left,
|
||||
}
|
||||
|
||||
impl Display for Edge {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result {
|
||||
match self {
|
||||
Self::Top => write!(fmt, "t"),
|
||||
Self::Bottom => write!(fmt, "b"),
|
||||
Self::Right => write!(fmt, "r"),
|
||||
Self::Left => write!(fmt, "l"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait BootstrapClass {
|
||||
fn as_classname(&self) -> String;
|
||||
}
|
||||
|
||||
pub struct BootstrapProps<'a> {
|
||||
pub borders: Vec<&'a Border>,
|
||||
pub border_colors: Vec<&'a BorderColor>,
|
||||
pub margins: Vec<&'a Margin>,
|
||||
}
|
||||
|
||||
pub fn render_on_change<P: Properties + PartialEq>(
|
||||
props_on_comp: &mut P,
|
||||
props: P,
|
||||
) -> ShouldRender {
|
||||
if props_on_comp == &props {
|
||||
false
|
||||
} else {
|
||||
*props_on_comp = props;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect_bs<'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()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn calculate_classes(props: BootstrapProps) -> String {
|
||||
let BootstrapProps {
|
||||
borders,
|
||||
border_colors,
|
||||
margins,
|
||||
} = props;
|
||||
let mut classes = Vec::new();
|
||||
classes.append(&mut into_classnames(borders));
|
||||
classes.append(&mut into_classnames(border_colors));
|
||||
classes.append(&mut into_classnames(margins));
|
||||
|
||||
classes.join(" ")
|
||||
}
|
||||
|
||||
fn into_classnames<C: BootstrapClass>(c: Vec<&C>) -> Vec<String> {
|
||||
c.into_iter().map(|c| c.as_classname()).collect()
|
||||
}
|
8
src/prelude/padding.rs
Normal file
8
src/prelude/padding.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Padding(pub super::Edge, pub usize);
|
||||
|
||||
impl super::BootstrapClass for Padding {
|
||||
fn as_classname(&self) -> String {
|
||||
format!("m{}-{}", self.0, self.1)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue