diff options
Diffstat (limited to '')
| -rw-r--r-- | src/components/select_placeholder.rs | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/src/components/select_placeholder.rs b/src/components/select_placeholder.rs index 947931c..2e0f783 100644 --- a/src/components/select_placeholder.rs +++ b/src/components/select_placeholder.rs @@ -1,37 +1,24 @@ use leptos::{ - IntoView, - attr::{AttributeValue, IntoAttributeValue}, - component, + IntoView, component, + error::Error, html::Select, prelude::{ ClassAttribute, CollectView, ElementChild, GlobalAttributes, NodeRef, NodeRefAttribute, }, + server::LocalResource, view, }; -use crate::components::get_id; +use crate::components::{async_fetch::AsyncFetch, get_id}; #[component] -pub fn SelectPlaceholder<T>( +pub fn SelectPlaceholder( label: &'static str, node_ref: NodeRef<Select>, - options: Vec<(&'static str, T)>, -) -> impl IntoView -where - T: IntoAttributeValue, - <T as IntoAttributeValue>::Output: Send + AttributeValue, -{ + options: LocalResource<Result<Vec<(String, String)>, Error>>, +) -> impl IntoView { let id = get_id(); - let options = options - .into_iter() - .map(|(label, value)| { - view! { - <option value=value>{label}</option> - } - }) - .collect_view(); - view! { <div class="relative h-14"> <select @@ -54,7 +41,18 @@ where " node_ref=node_ref > - {options} + {move || AsyncFetch! { + @map_error_in_producer + from_resource = options + producer = |options| { + options + .into_iter() + .map(|(label, value)| { + view! { <option value=value>{label}</option> } + }) + .collect_view() + } + }} </select> // TODO: Reference `var(--tw-border-2)` instead of the `2 px` <2025-10-01> |
