cargo fmt & leptosfmt

This commit is contained in:
luoxiao 2024-08-22 00:09:30 +08:00 committed by luoxiaozero
parent 4652706fa4
commit 482bfdb875
9 changed files with 112 additions and 98 deletions

View file

@ -136,12 +136,12 @@ fn CalendarItem(
) -> impl IntoView { ) -> impl IntoView {
let is_selected = Memo::new({ let is_selected = Memo::new({
let date = date.clone(); let date = date.clone();
move |_| value.with(|value_date| { move |_| {
match value_date { value.with(|value_date| match value_date {
OptionModelWithValue::T(v) => v == date.deref(), OptionModelWithValue::T(v) => v == date.deref(),
OptionModelWithValue::Option(v) => v.as_ref() == Some(date.deref()), OptionModelWithValue::Option(v) => v.as_ref() == Some(date.deref()),
}
}) })
}
}); });
let weekday_str = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; let weekday_str = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
let on_click = { let on_click = {

View file

@ -27,12 +27,11 @@ pub fn CheckboxGroup(
}); });
view! { view! {
<Provider value=CheckboxGroupInjection{ value, name }> <Provider value=CheckboxGroupInjection {
<div value,
class=class_list!["thaw-checkbox-group", class] name,
id=id }>
role="group" <div class=class_list!["thaw-checkbox-group", class] id=id role="group">
>
{children()} {children()}
</div> </div>
</Provider> </Provider>

View file

@ -4,7 +4,9 @@ use chrono::NaiveDate;
use leptos::{html, prelude::*}; use leptos::{html, prelude::*};
use panel::{Panel, PanelRef}; use panel::{Panel, PanelRef};
use thaw_components::{Binder, Follower, FollowerPlacement}; use thaw_components::{Binder, Follower, FollowerPlacement};
use thaw_utils::{class_list, mount_style, now_date, ComponentRef, OptionModel, OptionModelWithValue}; use thaw_utils::{
class_list, mount_style, now_date, ComponentRef, OptionModel, OptionModelWithValue,
};
#[component] #[component]
pub fn DatePicker( pub fn DatePicker(

View file

@ -51,13 +51,19 @@ pub fn Field(
} }
} }
} }
<Provider value=FieldInjection { id, name, label, validation_state }>{children()}</Provider> <Provider value=FieldInjection {
id,
name,
label,
validation_state,
}>{children()}</Provider>
{move || { {move || {
view! { view! {
<OptionComp value=validation_state.get() let:validation_state> <OptionComp value=validation_state.get() let:validation_state>
{ {match validation_state {
match validation_state { FieldValidationState::Error(message) => {
FieldValidationState::Error(message) => EitherOf3::A(view! { EitherOf3::A(
view! {
<div class="thaw-field__validation-message"> <div class="thaw-field__validation-message">
<span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--error"> <span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--error">
<svg <svg
@ -65,17 +71,22 @@ pub fn Field(
aria-hidden="true" aria-hidden="true"
width="12" width="12"
height="12" height="12"
viewBox="0 0 12 12"> viewBox="0 0 12 12"
>
<path <path
d="M6 11A5 5 0 1 0 6 1a5 5 0 0 0 0 10Zm-.75-2.75a.75.75 0 1 1 1.5 0 .75.75 0 0 1-1.5 0Zm.26-4.84a.5.5 0 0 1 .98 0l.01.09v2.59a.5.5 0 0 1-1 0V3.41Z" d="M6 11A5 5 0 1 0 6 1a5 5 0 0 0 0 10Zm-.75-2.75a.75.75 0 1 1 1.5 0 .75.75 0 0 1-1.5 0Zm.26-4.84a.5.5 0 0 1 .98 0l.01.09v2.59a.5.5 0 0 1-1 0V3.41Z"
fill="currentColor"> fill="currentColor"
</path> ></path>
</svg> </svg>
</span> </span>
{message} {message}
</div> </div>
}), },
FieldValidationState::Success(message) => EitherOf3::B(view! { )
}
FieldValidationState::Success(message) => {
EitherOf3::B(
view! {
<div class="thaw-field__validation-message"> <div class="thaw-field__validation-message">
<span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--success"> <span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--success">
<svg <svg
@ -83,17 +94,22 @@ pub fn Field(
aria-hidden="true" aria-hidden="true"
width="12" width="12"
height="12" height="12"
viewBox="0 0 12 12"> viewBox="0 0 12 12"
>
<path <path
d="M1 6a5 5 0 1 1 10 0A5 5 0 0 1 1 6Zm7.35-.9a.5.5 0 1 0-.7-.7L5.5 6.54 4.35 5.4a.5.5 0 1 0-.7.7l1.5 1.5c.2.2.5.2.7 0l2.5-2.5Z" d="M1 6a5 5 0 1 1 10 0A5 5 0 0 1 1 6Zm7.35-.9a.5.5 0 1 0-.7-.7L5.5 6.54 4.35 5.4a.5.5 0 1 0-.7.7l1.5 1.5c.2.2.5.2.7 0l2.5-2.5Z"
fill="currentColor"> fill="currentColor"
</path> ></path>
</svg> </svg>
</span> </span>
{message} {message}
</div> </div>
}), },
FieldValidationState::Warning(message) => EitherOf3::C(view! { )
}
FieldValidationState::Warning(message) => {
EitherOf3::C(
view! {
<div class="thaw-field__validation-message"> <div class="thaw-field__validation-message">
<span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--warning"> <span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--warning">
<svg <svg
@ -101,18 +117,20 @@ pub fn Field(
aria-hidden="true" aria-hidden="true"
width="12" width="12"
height="12" height="12"
viewBox="0 0 12 12"> viewBox="0 0 12 12"
>
<path <path
d="M5.21 1.46a.9.9 0 0 1 1.58 0l4.09 7.17a.92.92 0 0 1-.79 1.37H1.91a.92.92 0 0 1-.79-1.37l4.1-7.17ZM5.5 4.5v1a.5.5 0 0 0 1 0v-1a.5.5 0 0 0-1 0ZM6 6.75a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z" d="M5.21 1.46a.9.9 0 0 1 1.58 0l4.09 7.17a.92.92 0 0 1-.79 1.37H1.91a.92.92 0 0 1-.79-1.37l4.1-7.17ZM5.5 4.5v1a.5.5 0 0 0 1 0v-1a.5.5 0 0 0-1 0ZM6 6.75a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z"
fill="currentColor"> fill="currentColor"
</path> ></path>
</svg> </svg>
</span> </span>
{message} {message}
</div> </div>
}) },
} )
} }
}}
</OptionComp> </OptionComp>
} }

View file

@ -3,9 +3,7 @@ use slotmap::{DefaultKey, SlotMap};
#[component] #[component]
pub fn FieldContextProvider(children: Children) -> impl IntoView { pub fn FieldContextProvider(children: Children) -> impl IntoView {
view! { view! { <Provider value=FieldContextInjection::new()>{children()}</Provider> }
<Provider value=FieldContextInjection::new()>{children()}</Provider>
}
} }
#[derive(Clone)] #[derive(Clone)]

View file

@ -17,12 +17,10 @@ pub fn NavItem(
let value = value.get_untracked(); let value = value.get_untracked();
if nav_drawer if nav_drawer
.selected_value .selected_value
.with_untracked(|selected_value| .with_untracked(|selected_value| match selected_value {
match selected_value {
OptionModelWithValue::T(v) => v != &value, OptionModelWithValue::T(v) => v != &value,
OptionModelWithValue::Option(v) => v.as_ref() != Some(&value), OptionModelWithValue::Option(v) => v.as_ref() != Some(&value),
} })
)
{ {
nav_drawer.selected_value.set(Some(value)); nav_drawer.selected_value.set(Some(value));
} }
@ -42,12 +40,12 @@ pub fn NavItem(
}; };
let selected = Memo::new(move |_| { let selected = Memo::new(move |_| {
nav_drawer nav_drawer.selected_value.with(|selected_value| {
.selected_value value.with(|value| match selected_value {
.with(|selected_value| value.with(|value| match selected_value {
OptionModelWithValue::T(v) => v == value, OptionModelWithValue::T(v) => v == value,
OptionModelWithValue::Option(v) => v.as_ref() == Some(&value), OptionModelWithValue::Option(v) => v.as_ref() == Some(&value),
})) })
})
}); });
if let Some(href) = href { if let Some(href) = href {

View file

@ -25,11 +25,12 @@ pub fn Radio(
let checked = Memo::new({ let checked = Memo::new({
let group = group.clone(); let group = group.clone();
move |_| { move |_| {
item_value item_value.with_value(|value| {
.with_value(|value| group.value.with(|group_value| match group_value { group.value.with(|group_value| match group_value {
OptionModelWithValue::T(v) => v == value, OptionModelWithValue::T(v) => v == value,
OptionModelWithValue::Option(v) => v.as_ref() == Some(value), OptionModelWithValue::Option(v) => v.as_ref() == Some(value),
})) })
})
} }
}); });

View file

@ -33,11 +33,7 @@ pub fn RadioGroup(
view! { view! {
<Provider value=RadioGroupInjection { value, name }> <Provider value=RadioGroupInjection { value, name }>
<div <div class=class_list!["thaw-radio-group", class] id=id role="radiogroup">
class=class_list!["thaw-radio-group", class]
id=id
role="radiogroup"
>
{children()} {children()}
</div> </div>
</Provider> </Provider>

View file

@ -5,7 +5,9 @@ use crate::{
use chrono::{Local, NaiveTime, Timelike}; use chrono::{Local, NaiveTime, Timelike};
use leptos::{html, prelude::*}; use leptos::{html, prelude::*};
use thaw_components::{Binder, CSSTransition, Follower, FollowerPlacement}; use thaw_components::{Binder, CSSTransition, Follower, FollowerPlacement};
use thaw_utils::{class_list, mount_style, ArcOneCallback, ComponentRef, OptionModel, OptionModelWithValue}; use thaw_utils::{
class_list, mount_style, ArcOneCallback, ComponentRef, OptionModel, OptionModelWithValue,
};
#[component] #[component]
pub fn TimePicker( pub fn TimePicker(