mirror of
https://github.com/adoyle0/thaw.git
synced 2025-03-13 05:59:49 -04:00
feat: Tag adds align and justify prop (#139)
This commit is contained in:
parent
12273fc7c4
commit
dc1f9842a2
2 changed files with 107 additions and 1 deletions
|
@ -39,6 +39,54 @@ view! {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Align
|
||||||
|
|
||||||
|
```rust demo
|
||||||
|
view! {
|
||||||
|
<Space vertical=true>
|
||||||
|
<Space align=SpaceAlign::Start>
|
||||||
|
<Button style="height: 60px">"Start"</Button>
|
||||||
|
<Button style="height: 40px">"Start"</Button>
|
||||||
|
<Button>"Start"</Button>
|
||||||
|
</Space>
|
||||||
|
<Space align=SpaceAlign::Center>
|
||||||
|
<Button style="height: 60px">"Center"</Button>
|
||||||
|
<Button style="height: 40px">"Center"</Button>
|
||||||
|
<Button>"Center"</Button>
|
||||||
|
</Space>
|
||||||
|
<Space align=SpaceAlign::End>
|
||||||
|
<Button style="height: 60px">"End"</Button>
|
||||||
|
<Button style="height: 40px">"End"</Button>
|
||||||
|
<Button>"End"</Button>
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Justify
|
||||||
|
|
||||||
|
```rust demo
|
||||||
|
view! {
|
||||||
|
<Space vertical=true>
|
||||||
|
<Space justify=SpaceJustify::SpaceAround>
|
||||||
|
<Button>"SpaceAround"</Button>
|
||||||
|
<Button>"SpaceAround"</Button>
|
||||||
|
<Button>"SpaceAround"</Button>
|
||||||
|
</Space>
|
||||||
|
<Space justify=SpaceJustify::Center>
|
||||||
|
<Button>"Center"</Button>
|
||||||
|
<Button>"Center"</Button>
|
||||||
|
<Button>"Center"</Button>
|
||||||
|
</Space>
|
||||||
|
<Space justify=SpaceJustify::End>
|
||||||
|
<Button>"End"</Button>
|
||||||
|
<Button>"End"</Button>
|
||||||
|
<Button>"End"</Button>
|
||||||
|
</Space>
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Space Props
|
### Space Props
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|
@ -46,4 +94,6 @@ view! {
|
||||||
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the space element. |
|
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the space element. |
|
||||||
| vertical | `bool` | `false` | Whether to lay out vertically. |
|
| vertical | `bool` | `false` | Whether to lay out vertically. |
|
||||||
| gap | `SpaceGap` | `SpaceGap::Medium` | Space's gap. |
|
| gap | `SpaceGap` | `SpaceGap::Medium` | Space's gap. |
|
||||||
|
| align | `OptionalMaybeSignal<SpaceAlign>` | `None` | Vertical arrangement. |
|
||||||
|
| justify | `OptionalMaybeSignal<SpaceJustify>` | `None` | Horizontal arrangement. |
|
||||||
| children | `Children` | | Space's content. |
|
| children | `Children` | | Space's content. |
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::utils::{class_list::class_list, mount_style, OptionalProp};
|
use crate::utils::{class_list::class_list, mount_style, OptionalMaybeSignal, OptionalProp};
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -16,6 +16,8 @@ pub enum SpaceGap {
|
||||||
pub fn Space(
|
pub fn Space(
|
||||||
#[prop(optional)] gap: SpaceGap,
|
#[prop(optional)] gap: SpaceGap,
|
||||||
#[prop(optional)] vertical: bool,
|
#[prop(optional)] vertical: bool,
|
||||||
|
#[prop(optional, into)] align: OptionalMaybeSignal<SpaceAlign>,
|
||||||
|
#[prop(optional, into)] justify: OptionalMaybeSignal<SpaceJustify>,
|
||||||
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
|
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
|
||||||
children: Children,
|
children: Children,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
|
@ -32,6 +34,8 @@ pub fn Space(
|
||||||
<div
|
<div
|
||||||
class=class_list!["thaw-space", class.map(| c | move || c.get())]
|
class=class_list!["thaw-space", class.map(| c | move || c.get())]
|
||||||
style:gap=gap
|
style:gap=gap
|
||||||
|
style:align-items=move || align.get().map(|a| a.as_str())
|
||||||
|
style:justify-content=move || justify.get().map(|j| j.as_str())
|
||||||
style:flex-direction=if vertical { "column" } else { "row" }
|
style:flex-direction=if vertical { "column" } else { "row" }
|
||||||
>
|
>
|
||||||
|
|
||||||
|
@ -46,3 +50,55 @@ pub fn Space(
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum SpaceAlign {
|
||||||
|
FlexStart,
|
||||||
|
FlexEnd,
|
||||||
|
Start,
|
||||||
|
End,
|
||||||
|
Center,
|
||||||
|
Baseline,
|
||||||
|
Stretch,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpaceAlign {
|
||||||
|
fn as_str(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::FlexStart => "flex-start",
|
||||||
|
Self::FlexEnd => "flex-end",
|
||||||
|
Self::Start => "start",
|
||||||
|
Self::End => "end",
|
||||||
|
Self::Center => "center",
|
||||||
|
Self::Baseline => "baseline",
|
||||||
|
Self::Stretch => "stretch",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum SpaceJustify {
|
||||||
|
FlexStart,
|
||||||
|
FlexEnd,
|
||||||
|
Start,
|
||||||
|
End,
|
||||||
|
Center,
|
||||||
|
SpaceAround,
|
||||||
|
SpaceBetween,
|
||||||
|
SpaceEvenly,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SpaceJustify {
|
||||||
|
fn as_str(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Self::FlexStart => "flex-start",
|
||||||
|
Self::FlexEnd => "flex-end",
|
||||||
|
Self::Start => "start",
|
||||||
|
Self::End => "end",
|
||||||
|
Self::Center => "center",
|
||||||
|
Self::SpaceAround => "space-around",
|
||||||
|
Self::SpaceBetween => "space-between",
|
||||||
|
Self::SpaceEvenly => "space-evenly",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue