lan-party-backend/web/src/components/button.rs

61 lines
1.5 KiB
Rust

use yew::{function_component, html, Callback, Classes, Component, Properties};
/*
pub enum Msg {
Click,
}
pub struct Button;
impl Component for Button {
type Message = Msg;
type Properties = Props;
fn create(ctx: &yew::Context<Self>) -> Self {
Self
}
fn update(&mut self, ctx: &yew::Context<Self>, msg: Self::Message) -> bool {
match msg {
Msg::Click => ctx.props().onclick.emit(()),
};
false
}
fn view(&self, ctx: &yew::Context<Self>) -> yew::Html {
let link = ctx.link().clone();
html! {
<button class="bg-gray-700 hover:bg-gray-800 text-gray-400 font-bold py-2 px-2 rounded inline-flex items-center" onclick={link.callback(|_| Msg::Click)}>{ "+1" }</button>
}
}
}
*/
#[derive(Properties, PartialEq, Default)]
pub struct Props {
pub onclick: Callback<()>,
#[prop_or_default]
pub text: String,
#[prop_or_default]
pub icon: String,
}
#[function_component(Button)]
pub fn button(props: &Props) -> Html {
let mut icon_class = Classes::from("mdi");
icon_class.push("text-lg");
if !props.icon.is_empty() {
icon_class.push(&props.icon);
}
html! {
<button class="bg-gray-700 hover:bg-gray-800 text-gray-400 font-bold py-2 px-2 rounded inline-flex items-center" onclick={props.onclick.reform(move |_| ())}>
<span class={icon_class}></span>
<span>{ &props.text }</span>
</button>
}
}