euv-example 0.5.38

An example application demonstrating the euv UI framework with reactive signals, custom components, and WebAssembly.
Documentation
use crate::*;

/// A primary button component with customizable label and click handler.
///
/// The button stretches to full width when alone, and evenly shares
/// available width with sibling buttons inside a flex container.
///
/// # Arguments
///
/// - `VirtualNode<PrimaryButtonProps>` - The props node containing label, onclick, and disabled.
///
/// # Returns
///
/// - `VirtualNode` - A styled button element.
#[component]
pub(crate) fn primary_button(node: VirtualNode<PrimaryButtonProps>) -> VirtualNode {
    let PrimaryButtonProps {
        label,
        onclick: click_handler,
        disabled,
    }: PrimaryButtonProps = node.try_get_props().unwrap_or_default();
    let children: VirtualNode = node.try_get_child_node();
    let content: VirtualNode = match children {
        VirtualNode::Empty => VirtualNode::Text(TextNode::new(label.to_string(), None)),
        other => other,
    };
    html! {
        button {
            class: if { disabled.get() } {
                c_primary_button_disabled()
            } else {
                c_primary_button()
            }
            onclick: click_handler
            content
        }
    }
}

/// A modal primary button component with the same style as `primary_button` but without full width on mobile.
///
/// Used inside modal dialogs where the button should not stretch to 100% width on mobile viewports.
///
/// # Arguments
///
/// - `VirtualNode<PrimaryButtonProps>` - The props node containing label, onclick, and disabled.
///
/// # Returns
///
/// - `VirtualNode` - A styled button element.
#[component]
pub(crate) fn modal_primary_button(node: VirtualNode<PrimaryButtonProps>) -> VirtualNode {
    let PrimaryButtonProps {
        label,
        onclick: click_handler,
        disabled,
    }: PrimaryButtonProps = node.try_get_props().unwrap_or_default();
    let children: VirtualNode = node.try_get_child_node();
    let content: VirtualNode = match children {
        VirtualNode::Empty => VirtualNode::Text(TextNode::new(label.to_string(), None)),
        other => other,
    };
    html! {
        button {
            class: if { disabled.get() } {
                c_modal_primary_button_disabled()
            } else {
                c_modal_primary_button()
            }
            onclick: click_handler
            content
        }
    }
}