Pref/231219 (#54)

* demo: AutoComplete add Prefix and Suffix

* pref: cargo clippy

* pref: fmt
This commit is contained in:
luoxiaozero 2023-12-19 16:26:51 +08:00 committed by GitHub
parent 6c9e0c397f
commit 7ac738fb2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 106 additions and 44 deletions

View file

@ -78,6 +78,42 @@ pub fn AutoCompletePage() -> impl IntoView {
</DemoCode> </DemoCode>
</Demo> </Demo>
<h2>"Prefix & Suffix"</h2>
<Demo>
<Space vertical=true>
<AutoComplete value options>
<AutoCompletePrefix slot>
<Icon icon=icondata::Icon::from(icondata::AiIcon::AiUserOutlined)/>
</AutoCompletePrefix>
</AutoComplete>
<AutoComplete value options>
<AutoCompleteSuffix slot>
<Icon icon=icondata::Icon::from(icondata::AiIcon::AiGithubOutlined)/>
</AutoCompleteSuffix>
</AutoComplete>
</Space>
<DemoCode slot>
{highlight_str!(
r#"
<Space vertical=true>
<AutoComplete value options>
<AutoCompletePrefix slot>
<Icon icon=icondata::Icon::from(icondata::AiIcon::AiUserOutlined)/>
</AutoCompletePrefix>
</AutoComplete>
<AutoComplete value options>
<AutoCompleteSuffix slot>
<Icon icon=icondata::Icon::from(icondata::AiIcon::AiGithubOutlined)/>
</AutoCompleteSuffix>
</AutoComplete>
</Space>
"#,
"rust"
)}
</DemoCode>
</Demo>
<h3>"AutoComplete Props"</h3> <h3>"AutoComplete Props"</h3>
<Table single_column=true> <Table single_column=true>
<thead> <thead>
@ -161,6 +197,32 @@ pub fn AutoCompletePage() -> impl IntoView {
</tr> </tr>
</tbody> </tbody>
</Table> </Table>
<h3>"AutoComplete Slots"</h3>
<Table single_column=true>
<thead>
<tr>
<th>"Name"</th>
<th>"Default"</th>
<th>"Description"</th>
</tr>
</thead>
<tbody>
<tr>
<td>"AutoCompletePrefix"</td>
<td>
<Text code=true>"None"</Text>
</td>
<td>"AutoCompletePrefix content."</td>
</tr>
<tr>
<td>"AutoCompleteSuffix"</td>
<td>
<Text code=true>"None"</Text>
</td>
<td>"AutoCompleteSuffix content."</td>
</tr>
</tbody>
</Table>
<h3>"AutoComplete Ref"</h3> <h3>"AutoComplete Ref"</h3>
<Table single_column=true> <Table single_column=true>
<thead> <thead>

View file

@ -92,7 +92,8 @@ pub fn Alert(
class=ssr_class class=ssr_class
use:dyn_classes=class use:dyn_classes=class
class:thaw-alert=true class:thaw-alert=true
style=move || css_vars.get()> style=move || css_vars.get()
>
<Icon icon class="thaw-alert__icon"/> <Icon icon class="thaw-alert__icon"/>
<div> <div>

View file

@ -129,7 +129,13 @@ pub fn AutoComplete(
let ssr_class = ssr_class(&class); let ssr_class = ssr_class(&class);
view! { view! {
<Binder target_ref=auto_complete_ref> <Binder target_ref=auto_complete_ref>
<div class=ssr_class use:dyn_classes=class class:thaw-auto-complete=true ref=auto_complete_ref on:keydown=on_keydown> <div
class=ssr_class
use:dyn_classes=class
class:thaw-auto-complete=true
ref=auto_complete_ref
on:keydown=on_keydown
>
<Input <Input
value value
placeholder placeholder
@ -141,22 +147,22 @@ pub fn AutoComplete(
comp_ref=input_ref comp_ref=input_ref
> >
<InputPrefix if_=auto_complete_prefix.is_some() slot> <InputPrefix if_=auto_complete_prefix.is_some() slot>
{
if let Some(auto_complete_prefix) = auto_complete_prefix { {if let Some(auto_complete_prefix) = auto_complete_prefix {
Some((auto_complete_prefix.children)()) Some((auto_complete_prefix.children)())
} else { } else {
None None
} }}
}
</InputPrefix> </InputPrefix>
<InputSuffix if_=auto_complete_suffix.is_some() slot> <InputSuffix if_=auto_complete_suffix.is_some() slot>
{
if let Some(auto_complete_suffix) = auto_complete_suffix { {if let Some(auto_complete_suffix) = auto_complete_suffix {
Some((auto_complete_suffix.children)()) Some((auto_complete_suffix.children)())
} else { } else {
None None
} }}
}
</InputSuffix> </InputSuffix>
</Input> </Input>
</div> </div>

View file

@ -37,7 +37,12 @@ pub fn Avatar(
let ssr_class = ssr_class(&class); let ssr_class = ssr_class(&class);
view! { view! {
<span class=ssr_class use:dyn_classes=class class:thaw-avatar=true style=move || css_vars.get()> <span
class=ssr_class
use:dyn_classes=class
class:thaw-avatar=true
style=move || css_vars.get()
>
{move || { {move || {
let src = src.get(); let src = src.get();
(!src.is_empty()).then(|| view! { <img src=src/> }) (!src.is_empty()).then(|| view! { <img src=src/> })

View file

@ -131,7 +131,7 @@ pub fn Input(
class=("thaw-input--invalid", move || invalid.get()) class=("thaw-input--invalid", move || invalid.get())
style=move || css_vars.get() style=move || css_vars.get()
> >
{if let Some(prefix) = input_prefix.map(|prefix| prefix.if_.then(|| prefix)).flatten() { {if let Some(prefix) = input_prefix.and_then(|prefix| prefix.if_.then_some(prefix)) {
view! { <div class="thaw-input__prefix">{(prefix.children)()}</div> }.into() view! { <div class="thaw-input__prefix">{(prefix.children)()}</div> }.into()
} else { } else {
None None
@ -153,7 +153,7 @@ pub fn Input(
ref=input_ref ref=input_ref
/> />
{if let Some(suffix) = input_suffix.map(|suffix| suffix.if_.then(|| suffix)).flatten() { {if let Some(suffix) = input_suffix.and_then(|suffix| suffix.if_.then_some(suffix)) {
view! { <div class="thaw-input__suffix">{(suffix.children)()}</div> }.into() view! { <div class="thaw-input__suffix">{(suffix.children)()}</div> }.into()
} else { } else {
None None

View file

@ -111,11 +111,7 @@ pub fn Slider(
on_cleanup(move || on_mouse_move.remove()); on_cleanup(move || on_mouse_move.remove());
view! { view! {
<div <div class="thaw-slider" style=move || css_vars.get() on:click=on_mouse_click>
class="thaw-slider"
style=move || css_vars.get()
on:click=on_mouse_click
>
<div class="thaw-slider-rail" ref=rail_ref> <div class="thaw-slider-rail" ref=rail_ref>
<div <div
class="thaw-slider-rail__fill" class="thaw-slider-rail__fill"
@ -128,11 +124,8 @@ pub fn Slider(
<div <div
on:mousedown=on_mouse_down on:mousedown=on_mouse_down
class="thaw-slider-handle" class="thaw-slider-handle"
style=move || { style=move || { format!("left: {}%", percentage.get()) }
format!("left: {}%", percentage.get()) ></div>
}
>
</div>
</div> </div>
} }
} }

View file

@ -3,11 +3,7 @@ use leptos::*;
use crate::utils::mount_style; use crate::utils::mount_style;
#[component] #[component]
pub fn SliderLabel( pub fn SliderLabel(#[prop(into)] value: MaybeSignal<f64>, children: Children) -> impl IntoView {
#[prop(into)] value: MaybeSignal<f64>,
children: Children,
) -> impl IntoView {
mount_style("slider-label", include_str!("./slider_label.css")); mount_style("slider-label", include_str!("./slider_label.css"));
view! { view! {
@ -15,9 +11,10 @@ pub fn SliderLabel(
class:thaw-slider-label=true class:thaw-slider-label=true
style=move || { style=move || {
format!("left: calc(calc({} / var(--thaw-slider-max)) * 100%)", value.get()) format!("left: calc(calc({} / var(--thaw-slider-max)) * 100%)", value.get())
}> }
>
{children()} {children()}
</div> </div>
} }
} }

View file

@ -23,15 +23,13 @@ pub fn dyn_classes(el: HtmlElement<AnyElement>, classes_signal: MaybeSignal<Stri
} }
pub fn ssr_class(class: &MaybeSignal<String>) -> String { pub fn ssr_class(class: &MaybeSignal<String>) -> String {
let ssr_class;
cfg_if! { cfg_if! {
if #[cfg(feature = "ssr")] { if #[cfg(feature = "ssr")] {
use leptos::SignalGetUntracked; use leptos::SignalGetUntracked;
ssr_class = class.get_untracked(); class.get_untracked()
} else { } else {
let _ = class; let _ = class;
ssr_class = String::new(); String::new()
}
} }
};
ssr_class
} }