Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow label to be any type that impl IntoView #203

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions thaw/src/auto_complete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ use leptos::*;
use thaw_components::{Binder, CSSTransition, Follower, FollowerPlacement, FollowerWidth};
use thaw_utils::{class_list, mount_style, Model, OptionalProp, StoredMaybeSignal};

#[derive(Clone, PartialEq)]
pub struct AutoCompleteOption {
pub label: String,
#[derive(Clone)]
pub struct AutoCompleteOption<T> {
pub label: T,
pub value: String,
}

impl<T> PartialEq for AutoCompleteOption<T> {
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}

#[slot]
pub struct AutoCompletePrefix {
children: Children,
Expand All @@ -24,10 +30,10 @@ pub struct AutoCompleteSuffix {
}

#[component]
pub fn AutoComplete(
pub fn AutoComplete<T>(
#[prop(optional, into)] value: Model<String>,
#[prop(optional, into)] placeholder: OptionalProp<MaybeSignal<String>>,
#[prop(optional, into)] options: MaybeSignal<Vec<AutoCompleteOption>>,
#[prop(optional, into)] options: MaybeSignal<Vec<AutoCompleteOption<T>>>,
#[prop(optional, into)] clear_after_select: MaybeSignal<bool>,
#[prop(optional, into)] blur_after_select: MaybeSignal<bool>,
#[prop(optional, into)] on_select: Option<Callback<String>>,
Expand All @@ -39,7 +45,10 @@ pub fn AutoComplete(
#[prop(optional)] auto_complete_suffix: Option<AutoCompleteSuffix>,
#[prop(optional)] comp_ref: ComponentRef<AutoCompleteRef>,
#[prop(attrs)] attrs: Vec<(&'static str, Attribute)>,
) -> impl IntoView {
) -> impl IntoView
where
T: IntoView + Clone + 'static,
{
mount_style("auto-complete", include_str!("./auto-complete.css"));
let theme = use_theme(Theme::light);
let menu_css_vars = create_memo(move |_| {
Expand Down
Loading