nightshade-api 0.51.0

Procedural high level API for the nightshade game engine
Documentation
use leptos::prelude::*;

/// A styled `<button>`. Pass extra classes via `class` and a click handler via
/// the optional `on_click` callback.
#[component]
pub fn Button(
    #[prop(into, optional)] class: String,
    #[prop(optional)] on_click: Option<Callback<web_sys::MouseEvent>>,
    children: Children,
) -> impl IntoView {
    let handle = move |event: web_sys::MouseEvent| {
        if let Some(callback) = on_click {
            callback.run(event);
        }
    };
    view! {
        <button class=format!("nightshade-button {class}") on:click=handle>
            {children()}
        </button>
    }
}

/// A square, icon-only button variant. Pass extra classes via `class` and a
/// click handler via the optional `on_click` callback.
#[component]
pub fn IconButton(
    #[prop(into, optional)] class: String,
    #[prop(optional)] on_click: Option<Callback<web_sys::MouseEvent>>,
    children: Children,
) -> impl IntoView {
    let handle = move |event: web_sys::MouseEvent| {
        if let Some(callback) = on_click {
            callback.run(event);
        }
    };
    view! {
        <button class=format!("nightshade-icon-button {class}") on:click=handle>
            {children()}
        </button>
    }
}