thaw/src/space/mod.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2023-04-03 15:21:23 +08:00
use crate::utils::mount_style::mount_style;
use leptos::*;
#[derive(Default)]
pub enum SpaceGap {
2023-10-16 21:15:43 +08:00
Small,
2023-04-03 15:21:23 +08:00
#[default]
2023-10-16 21:15:43 +08:00
Medium,
Large,
Size(u16),
/// width and height
WH(u16, u16),
2023-04-03 15:21:23 +08:00
}
#[component]
2023-10-04 22:48:08 +08:00
pub fn Space(
#[prop(optional)] gap: SpaceGap,
#[prop(optional)] vertical: bool,
children: Children,
) -> impl IntoView {
2023-10-07 21:41:03 +08:00
mount_style("space", include_str!("./space.css"));
2023-04-03 15:21:23 +08:00
let gap = match gap {
2023-10-16 21:15:43 +08:00
SpaceGap::Small => "4px 8px".into(),
SpaceGap::Medium => "8px 12px".into(),
SpaceGap::Large => "12px 16px".into(),
SpaceGap::Size(size) => format!("{size}px {size}px"),
SpaceGap::WH(width, height) => format!("{width}px {height}px"),
2023-04-03 15:21:23 +08:00
};
view! {
2023-10-08 09:28:13 +08:00
<div
2023-11-05 16:03:58 +08:00
class="thaw-space"
2023-10-08 09:28:13 +08:00
style:gap=gap
style:flex-direction=if vertical { "column" } else { "row" }
>
{children()
.nodes
.into_iter()
.map(|node| {
2023-11-05 16:03:58 +08:00
view! { <div class="thaw-space__item">{node}</div> }
2023-10-08 09:28:13 +08:00
})
.collect::<Vec<_>>()}
2023-04-03 15:21:23 +08:00
</div>
}
}