2023-04-03 15:21:23 +08:00
|
|
|
use crate::utils::mount_style::mount_style;
|
|
|
|
use leptos::*;
|
|
|
|
use stylers::style_sheet_str;
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub enum SpaceGap {
|
|
|
|
SMALL,
|
|
|
|
#[default]
|
|
|
|
MEDIUM,
|
|
|
|
LARGE,
|
|
|
|
NUMBER(u16),
|
|
|
|
TUPLE(u16, u16),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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-04-03 15:21:23 +08:00
|
|
|
let class_name = mount_style("space", || style_sheet_str!("./src/space/space.css"));
|
|
|
|
let gap = match gap {
|
2023-10-04 22:48:08 +08:00
|
|
|
SpaceGap::SMALL => "4px 8px".into(),
|
|
|
|
SpaceGap::MEDIUM => "8px 12px".into(),
|
|
|
|
SpaceGap::LARGE => "12px 16px".into(),
|
|
|
|
SpaceGap::NUMBER(size) => format!("{size}px {size}px"),
|
|
|
|
SpaceGap::TUPLE(x, y) => format!("{x}px {y}px"),
|
2023-04-03 15:21:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
view! {
|
2023-08-29 09:11:22 +08:00
|
|
|
class=class_name,
|
2023-10-04 22:48:08 +08:00
|
|
|
<div class="melt-space" style:gap={gap} style:flex-direction=if vertical { "column" } else { "row" }>
|
2023-04-03 15:21:23 +08:00
|
|
|
{
|
2023-08-29 09:11:22 +08:00
|
|
|
children().nodes.into_iter().map(|node| {
|
2023-04-03 15:21:23 +08:00
|
|
|
view! {
|
2023-08-29 09:11:22 +08:00
|
|
|
class=class_name,
|
2023-04-03 15:21:23 +08:00
|
|
|
<div class="melt-space__item">
|
|
|
|
{node}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}).collect::<Vec<_>>()
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|