leptos_ui 0.2.3

Macros to build UI components easily with Leptos and Tailwind CSS.
Documentation
use leptos::prelude::*;

//
// EXPERIMENTAL. WILL CHANGE IN THE FUTURE.
//

/// Slot component that provides asChild pattern functionality for Leptos
///
/// This component allows you to change the underlying element while preserving styling.
///
/// Usage:
/// ```rust
/// <Slot class="btn-primary" as_child=SlotChild::A { href: "/dashboard".to_string() }>
///     "Go to Dashboard"
/// </Slot>
/// // Renders: <a href="/dashboard" class="btn-primary">Go to Dashboard</a>
///
/// <Slot class="btn-primary">
///     "Default Content"
/// </Slot>
/// // Renders: <div class="btn-primary">Default Content</div>
/// ```
#[component]
pub fn Slot(
    #[prop(into, optional)] class: Signal<String>,
    #[prop(into, optional)] style: Option<String>,
    #[prop(into, optional)] id: Signal<String>,
    #[prop(into, optional)] onclick: Option<String>,
    #[prop(into, optional)] data_slot: Signal<String>,
    #[prop(optional)] as_child: Option<SlotChild>,
    children: Children,
) -> impl IntoView {
    match as_child {
        Some(SlotChild::A { href }) => view! {
            <a class=class style=style id=id href=href onclick=onclick data-slot=data_slot>
                {children()}
            </a>
        }
        .into_any(),

        None => view! {
            <div class=class style=style id=id onclick=onclick data-slot=data_slot>
                {children()}
            </div>
        }
        .into_any(),
    }
}

/// Defines the underlying element type for the Slot component
#[derive(Clone, Debug)]
pub enum SlotChild {
    /// Render as an anchor element
    A { href: String },
}