Skip to content

Commit dc1f984

Browse files
authored
feat: Tag adds align and justify prop (#139)
1 parent 12273fc commit dc1f984

File tree

2 files changed

+107
-1
lines changed

2 files changed

+107
-1
lines changed

demo_markdown/docs/space/mod.md

+50
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,61 @@ view! {
3939
}
4040
```
4141

42+
### Align
43+
44+
```rust demo
45+
view! {
46+
<Space vertical=true>
47+
<Space align=SpaceAlign::Start>
48+
<Button style="height: 60px">"Start"</Button>
49+
<Button style="height: 40px">"Start"</Button>
50+
<Button>"Start"</Button>
51+
</Space>
52+
<Space align=SpaceAlign::Center>
53+
<Button style="height: 60px">"Center"</Button>
54+
<Button style="height: 40px">"Center"</Button>
55+
<Button>"Center"</Button>
56+
</Space>
57+
<Space align=SpaceAlign::End>
58+
<Button style="height: 60px">"End"</Button>
59+
<Button style="height: 40px">"End"</Button>
60+
<Button>"End"</Button>
61+
</Space>
62+
</Space>
63+
}
64+
```
65+
66+
### Justify
67+
68+
```rust demo
69+
view! {
70+
<Space vertical=true>
71+
<Space justify=SpaceJustify::SpaceAround>
72+
<Button>"SpaceAround"</Button>
73+
<Button>"SpaceAround"</Button>
74+
<Button>"SpaceAround"</Button>
75+
</Space>
76+
<Space justify=SpaceJustify::Center>
77+
<Button>"Center"</Button>
78+
<Button>"Center"</Button>
79+
<Button>"Center"</Button>
80+
</Space>
81+
<Space justify=SpaceJustify::End>
82+
<Button>"End"</Button>
83+
<Button>"End"</Button>
84+
<Button>"End"</Button>
85+
</Space>
86+
</Space>
87+
}
88+
```
89+
4290
### Space Props
4391

4492
| Name | Type | Default | Description |
4593
| -------- | ----------------------------------- | -------------------- | ---------------------------------------- |
4694
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the space element. |
4795
| vertical | `bool` | `false` | Whether to lay out vertically. |
4896
| gap | `SpaceGap` | `SpaceGap::Medium` | Space's gap. |
97+
| align | `OptionalMaybeSignal<SpaceAlign>` | `None` | Vertical arrangement. |
98+
| justify | `OptionalMaybeSignal<SpaceJustify>` | `None` | Horizontal arrangement. |
4999
| children | `Children` | | Space's content. |

thaw/src/space/mod.rs

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{class_list::class_list, mount_style, OptionalProp};
1+
use crate::utils::{class_list::class_list, mount_style, OptionalMaybeSignal, OptionalProp};
22
use leptos::*;
33

44
#[derive(Default)]
@@ -16,6 +16,8 @@ pub enum SpaceGap {
1616
pub fn Space(
1717
#[prop(optional)] gap: SpaceGap,
1818
#[prop(optional)] vertical: bool,
19+
#[prop(optional, into)] align: OptionalMaybeSignal<SpaceAlign>,
20+
#[prop(optional, into)] justify: OptionalMaybeSignal<SpaceJustify>,
1921
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
2022
children: Children,
2123
) -> impl IntoView {
@@ -32,6 +34,8 @@ pub fn Space(
3234
<div
3335
class=class_list!["thaw-space", class.map(| c | move || c.get())]
3436
style:gap=gap
37+
style:align-items=move || align.get().map(|a| a.as_str())
38+
style:justify-content=move || justify.get().map(|j| j.as_str())
3539
style:flex-direction=if vertical { "column" } else { "row" }
3640
>
3741

@@ -46,3 +50,55 @@ pub fn Space(
4650
</div>
4751
}
4852
}
53+
54+
#[derive(Clone)]
55+
pub enum SpaceAlign {
56+
FlexStart,
57+
FlexEnd,
58+
Start,
59+
End,
60+
Center,
61+
Baseline,
62+
Stretch,
63+
}
64+
65+
impl SpaceAlign {
66+
fn as_str(&self) -> &'static str {
67+
match self {
68+
Self::FlexStart => "flex-start",
69+
Self::FlexEnd => "flex-end",
70+
Self::Start => "start",
71+
Self::End => "end",
72+
Self::Center => "center",
73+
Self::Baseline => "baseline",
74+
Self::Stretch => "stretch",
75+
}
76+
}
77+
}
78+
79+
#[derive(Clone)]
80+
pub enum SpaceJustify {
81+
FlexStart,
82+
FlexEnd,
83+
Start,
84+
End,
85+
Center,
86+
SpaceAround,
87+
SpaceBetween,
88+
SpaceEvenly,
89+
}
90+
91+
impl SpaceJustify {
92+
fn as_str(&self) -> &'static str {
93+
match self {
94+
Self::FlexStart => "flex-start",
95+
Self::FlexEnd => "flex-end",
96+
Self::Start => "start",
97+
Self::End => "end",
98+
Self::Center => "center",
99+
Self::SpaceAround => "space-around",
100+
Self::SpaceBetween => "space-between",
101+
Self::SpaceEvenly => "space-evenly",
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)