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 {
let is_selected = Memo::new({
let date = date.clone();
move |_| value.with(|value_date| {
match value_date {
move |_| {
value.with(|value_date| match value_date {
OptionModelWithValue::T(v) => v == date.deref(),
OptionModelWithValue::Option(v) => v.as_ref() == Some(date.deref()),
}
})
}
});
let weekday_str = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
let on_click = {

View file

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

View file

@ -4,7 +4,9 @@ use chrono::NaiveDate;
use leptos::{html, prelude::*};
use panel::{Panel, PanelRef};
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]
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 || {
view! {
<OptionComp value=validation_state.get() let:validation_state>
{
match validation_state {
FieldValidationState::Error(message) => EitherOf3::A(view! {
{match validation_state {
FieldValidationState::Error(message) => {
EitherOf3::A(
view! {
<div class="thaw-field__validation-message">
<span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--error">
<svg
@ -65,17 +71,22 @@ pub fn Field(
aria-hidden="true"
width="12"
height="12"
viewBox="0 0 12 12">
viewBox="0 0 12 12"
>
<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"
fill="currentColor">
</path>
fill="currentColor"
></path>
</svg>
</span>
{message}
</div>
}),
FieldValidationState::Success(message) => EitherOf3::B(view! {
},
)
}
FieldValidationState::Success(message) => {
EitherOf3::B(
view! {
<div class="thaw-field__validation-message">
<span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--success">
<svg
@ -83,17 +94,22 @@ pub fn Field(
aria-hidden="true"
width="12"
height="12"
viewBox="0 0 12 12">
viewBox="0 0 12 12"
>
<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"
fill="currentColor">
</path>
fill="currentColor"
></path>
</svg>
</span>
{message}
</div>
}),
FieldValidationState::Warning(message) => EitherOf3::C(view! {
},
)
}
FieldValidationState::Warning(message) => {
EitherOf3::C(
view! {
<div class="thaw-field__validation-message">
<span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--warning">
<svg
@ -101,18 +117,20 @@ pub fn Field(
aria-hidden="true"
width="12"
height="12"
viewBox="0 0 12 12">
viewBox="0 0 12 12"
>
<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"
fill="currentColor">
</path>
fill="currentColor"
></path>
</svg>
</span>
{message}
</div>
})
}
},
)
}
}}
</OptionComp>
}

View file

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

View file

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

View file

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

View file

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

View file

@ -5,7 +5,9 @@ use crate::{
use chrono::{Local, NaiveTime, Timelike};
use leptos::{html, prelude::*};
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]
pub fn TimePicker(