canonrs-server 0.1.0

CanonRS server-side rendering support
#![allow(unreachable_pub, dead_code)]
use leptos::prelude::*;
use canonrs_core::meta::{SelectionState, DisabledState, VisibilityState};
use canonrs_core::primitives::{
    SelectPrimitive, SelectTriggerPrimitive, SelectValuePrimitive,
    SelectContentPrimitive, SelectItemPrimitive, SelectSeparatorPrimitive,
};

#[component]
pub fn Select(
    children: Children,
    #[prop(optional)] node_ref: Option<NodeRef<leptos::html::Div>>,
    #[prop(default = DisabledState::Enabled)] disabled: DisabledState,
    #[prop(into, default = String::new())] class: String,
) -> impl IntoView {
    view! {
        <SelectPrimitive state=VisibilityState::Closed disabled=disabled class=class node_ref=node_ref.unwrap_or_default()>
            {children()}
        </SelectPrimitive>
    }
}

#[component]
pub fn SelectTrigger(
    children: Children,
    #[prop(default = DisabledState::Enabled)] disabled: DisabledState,
    #[prop(into, default = String::new())] class: String,
) -> impl IntoView {
    view! {
        <SelectTriggerPrimitive disabled=disabled class=class>
            {children()}
        </SelectTriggerPrimitive>
    }
}

#[component]
pub fn SelectValue(
    children: Children,
    #[prop(into, default = String::new())] placeholder: String,
    #[prop(into, default = String::new())] class: String,
) -> impl IntoView {
    view! {
        <SelectValuePrimitive placeholder=placeholder class=class>
            {children()}
        </SelectValuePrimitive>
    }
}

#[component]
pub fn SelectContent(
    children: Children,
    #[prop(into, default = String::new())] class: String,
) -> impl IntoView {
    view! {
        <SelectContentPrimitive class=class>
            {children()}
        </SelectContentPrimitive>
    }
}

#[component]
pub fn SelectItem(
    children: Children,
    #[prop(default = SelectionState::Unselected)] selected: SelectionState,
    #[prop(default = DisabledState::Enabled)] disabled: DisabledState,
    #[prop(into, default = String::new())] value: String,
    #[prop(into, default = String::new())] class: String,
) -> impl IntoView {
    view! {
        <SelectItemPrimitive selected=selected disabled=disabled value=value class=class>
            {children()}
        </SelectItemPrimitive>
    }
}

#[component]
pub fn SelectSeparator(
    #[prop(into, default = String::new())] class: String,
) -> impl IntoView {
    view! { <SelectSeparatorPrimitive class=class /> }
}