use crate::util::Color;
use yew::prelude::*;
pub struct Link {}
#[derive(Properties, Clone, PartialEq)]
pub struct LinkProps {
#[prop_or_default]
pub class: String,
#[prop_or_default]
pub children: Children,
#[prop_or_default]
pub stretched: bool,
#[prop_or_default]
pub style: Option<Color>,
#[prop_or_default]
pub url: Option<AttrValue>,
#[prop_or_default]
pub target: Option<AttrValue>,
#[prop_or_default]
pub text: String,
#[prop_or_default]
pub node_ref: NodeRef,
}
impl Component for Link {
type Message = ();
type Properties = LinkProps;
fn create(_ctx: &Context<Self>) -> Self {
Self {}
}
fn view(&self, ctx: &Context<Self>) -> Html {
let props = ctx.props();
let mut classes = Classes::new();
if let Some(style) = props.style.clone() {
classes.push(format!("link-{}", style));
}
if props.stretched {
classes.push("stretched-link");
}
classes.push(props.class.clone());
html! {
<a
class={classes}
role={props.url.is_none().then_some("button")}
href={props.url.clone()}
target={props.target.clone()}
ref={props.node_ref.clone()}
>
{ &props.text }
{ for props.children.iter() }
</a>
}
}
}