use std::fmt;
use yew::prelude::*;
use crate::util::Color;
pub struct Display {}
#[derive(Properties, Clone, PartialEq)]
pub struct DisplayProps {
#[prop_or_default]
pub class: String,
#[prop_or_default]
pub children: Children,
#[prop_or(Color::Dark)]
pub style: Color,
#[prop_or(DisplaySize::One)]
pub size: DisplaySize,
#[prop_or_default]
pub text: String,
}
impl Component for Display {
type Message = ();
type Properties = DisplayProps;
fn create(_ctx: &Context<Self>) -> Self {
Self {}
}
fn view(&self, ctx: &Context<Self>) -> Html {
let props = ctx.props();
let mut classes = Classes::new();
classes.push(format!("display-{}", props.size));
classes.push(format!("text-{}", props.style));
classes.push(props.class.clone());
html! {
<h1 class={classes}>
{ &props.text }
{ for props.children.iter() }
</h1>
}
}
}
#[derive(Clone, PartialEq, Eq)]
pub enum DisplaySize {
One,
Two,
Three,
Four,
Five,
Six,
}
impl fmt::Display for DisplaySize {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
DisplaySize::One => write!(f, "1"),
DisplaySize::Two => write!(f, "2"),
DisplaySize::Three => write!(f, "3"),
DisplaySize::Four => write!(f, "4"),
DisplaySize::Five => write!(f, "5"),
DisplaySize::Six => write!(f, "6"),
}
}
}