mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-22 22:09:22 -05:00
cargo fmt & leptosfmt
This commit is contained in:
parent
4652706fa4
commit
482bfdb875
9 changed files with 112 additions and 98 deletions
|
@ -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 {
|
||||
OptionModelWithValue::T(v) => v == date.deref(),
|
||||
OptionModelWithValue::Option(v) => v.as_ref() == Some(date.deref()),
|
||||
}
|
||||
})
|
||||
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 = {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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(
|
||||
|
@ -21,12 +23,12 @@ pub fn DatePicker(
|
|||
let update_show_date_text = move || {
|
||||
value.with_untracked(move |date| {
|
||||
let text = match date {
|
||||
OptionModelWithValue::T(v) => v.format(show_date_format).to_string(),
|
||||
OptionModelWithValue::T(v) => v.format(show_date_format).to_string(),
|
||||
OptionModelWithValue::Option(v) => v.map_or(String::new(), |date| {
|
||||
date.format(show_date_format).to_string()
|
||||
}),
|
||||
};
|
||||
|
||||
|
||||
show_date_text.set(text);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -51,68 +51,86 @@ 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! {
|
||||
<div class="thaw-field__validation-message">
|
||||
<span class="thaw-field__validation-message-icon thaw-field__validation-message-icon--error">
|
||||
<svg
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
width="12"
|
||||
height="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>
|
||||
</svg>
|
||||
</span>
|
||||
{message}
|
||||
</div>
|
||||
}),
|
||||
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
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
width="12"
|
||||
height="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>
|
||||
</svg>
|
||||
</span>
|
||||
{message}
|
||||
</div>
|
||||
}),
|
||||
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
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
width="12"
|
||||
height="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>
|
||||
</svg>
|
||||
</span>
|
||||
{message}
|
||||
</div>
|
||||
})
|
||||
{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
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
width="12"
|
||||
height="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>
|
||||
</svg>
|
||||
</span>
|
||||
{message}
|
||||
</div>
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
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
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
width="12"
|
||||
height="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>
|
||||
</svg>
|
||||
</span>
|
||||
{message}
|
||||
</div>
|
||||
},
|
||||
)
|
||||
}
|
||||
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
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
width="12"
|
||||
height="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>
|
||||
</svg>
|
||||
</span>
|
||||
{message}
|
||||
</div>
|
||||
},
|
||||
)
|
||||
}
|
||||
}}
|
||||
|
||||
</OptionComp>
|
||||
}
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -17,12 +17,10 @@ pub fn NavItem(
|
|||
let value = value.get_untracked();
|
||||
if nav_drawer
|
||||
.selected_value
|
||||
.with_untracked(|selected_value|
|
||||
match selected_value {
|
||||
OptionModelWithValue::T(v) => v != &value,
|
||||
OptionModelWithValue::Option(v) => v.as_ref() != Some(&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 {
|
||||
OptionModelWithValue::T(v) => v == 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 {
|
||||
|
|
|
@ -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 {
|
||||
OptionModelWithValue::T(v) => v == 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),
|
||||
}))
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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(
|
||||
|
@ -24,7 +26,7 @@ pub fn TimePicker(
|
|||
let update_show_time_text = move || {
|
||||
value.with_untracked(move |time| {
|
||||
let text = match time {
|
||||
OptionModelWithValue::T(v) => v.format(show_time_format).to_string(),
|
||||
OptionModelWithValue::T(v) => v.format(show_time_format).to_string(),
|
||||
OptionModelWithValue::Option(v) => v.map_or(String::new(), |time| {
|
||||
time.format(show_time_format).to_string()
|
||||
}),
|
||||
|
|
Loading…
Add table
Reference in a new issue