mirror of
https://github.com/adoyle0/thaw.git
synced 2025-03-13 05:59:49 -04:00
✨ feat: add option component
This commit is contained in:
parent
13df204940
commit
10f5403826
4 changed files with 27 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
|||
mod theme;
|
||||
use crate::{theme::*, utils::mount_style::mount_style};
|
||||
use crate::{components::*, theme::*, utils::mount_style::mount_style};
|
||||
use leptos::*;
|
||||
use leptos_icons::*;
|
||||
use stylers::style_sheet_str;
|
||||
|
@ -63,7 +63,7 @@ pub fn Button(
|
|||
});
|
||||
let class_name = mount_style("button", || style_sheet_str!("./src/button/button.css"));
|
||||
|
||||
let icon_style= if children.is_some() {
|
||||
let icon_style = if children.is_some() {
|
||||
"margin-right: 6px"
|
||||
} else {
|
||||
""
|
||||
|
@ -77,22 +77,14 @@ pub fn Button(
|
|||
class=("melt-button--round", move || round.get())
|
||||
style=move || css_vars.get()
|
||||
>
|
||||
{
|
||||
if let Some(icon) = icon {
|
||||
<OptionComp value=icon view=move |cx, icon| {
|
||||
view!{cx,
|
||||
<Icon icon=icon style=icon_style/>
|
||||
}.into()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
{
|
||||
if let Some(children) = children {
|
||||
children(cx).into()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}/>
|
||||
<OptionComp value=children view=move |cx, children| {
|
||||
children(cx).into_view(cx)
|
||||
}/>
|
||||
</button>
|
||||
}
|
||||
}
|
||||
|
|
3
src/components/mod.rs
Normal file
3
src/components/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod option_comp;
|
||||
|
||||
pub use option_comp::*;
|
14
src/components/option_comp.rs
Normal file
14
src/components/option_comp.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use leptos::*;
|
||||
|
||||
#[component]
|
||||
pub fn OptionComp<T, VF, IV>(cx: Scope, value: Option<T>, view: VF) -> impl IntoView
|
||||
where
|
||||
VF: Fn(Scope, T) -> IV + 'static,
|
||||
IV: IntoView,
|
||||
{
|
||||
if let Some(value) = value {
|
||||
view(cx, value).into_view(cx)
|
||||
} else {
|
||||
().into_view(cx)
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
mod button;
|
||||
mod card;
|
||||
mod checkbox;
|
||||
mod components;
|
||||
mod input;
|
||||
mod modal;
|
||||
mod progress;
|
||||
|
|
Loading…
Add table
Reference in a new issue