mirror of
https://github.com/adoyle0/thaw.git
synced 2025-03-13 05:59:49 -04:00
feat: Layout scrollbar
This commit is contained in:
parent
a1a301a765
commit
8a6e0ee787
6 changed files with 26 additions and 14 deletions
|
@ -56,7 +56,7 @@ pub fn ComponentsPage() -> impl IntoView {
|
||||||
|
|
||||||
</Menu>
|
</Menu>
|
||||||
</LayoutSider>
|
</LayoutSider>
|
||||||
<Layout style="padding: 8px 12px 28px; overflow-y: auto;">
|
<Layout content_style="padding: 8px 12px 28px;">
|
||||||
<Outlet/>
|
<Outlet/>
|
||||||
</Layout>
|
</Layout>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn GuidePage() -> impl IntoView {
|
||||||
|
|
||||||
</Menu>
|
</Menu>
|
||||||
</LayoutSider>
|
</LayoutSider>
|
||||||
<Layout style="padding: 8px 12px 28px; overflow-y: auto;">
|
<Layout content_style="padding: 8px 12px 28px;">
|
||||||
<Outlet/>
|
<Outlet/>
|
||||||
</Layout>
|
</Layout>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
@ -35,8 +35,10 @@ view! {
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the layout element. |
|
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Class of scrollable content node. |
|
||||||
| style | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Layout's style. |
|
| style | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Layout's style. |
|
||||||
|
| content_class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the layout element. |
|
||||||
|
| content_style | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Style of scrollable content node. |
|
||||||
| position | `LayoutPosition` | `LayoutPosition::Static` | static position will make it css position set to static. absolute position will make it css position set to absolute and left, right, top, bottom to 0. absolute position is very useful when you want to make content scroll in a fixed container or make the whole page's layout in a fixed position. You may need to change the style of the component to make it display as you expect. |
|
| position | `LayoutPosition` | `LayoutPosition::Static` | static position will make it css position set to static. absolute position will make it css position set to absolute and left, right, top, bottom to 0. absolute position is very useful when you want to make content scroll in a fixed container or make the whole page's layout in a fixed position. You may need to change the style of the component to make it display as you expect. |
|
||||||
| has_sider | `MaybeSignal<bool>` | `false` | Whether the component has sider inside. If so it must be true. |
|
| has_sider | `MaybeSignal<bool>` | `false` | Whether the component has sider inside. If so it must be true. |
|
||||||
| children | `Children` | | Layout's content. |
|
| children | `Children` | | Layout's content. |
|
||||||
|
|
|
@ -9,3 +9,9 @@
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.thaw-layout--absolute-positioned
|
||||||
|
> .thaw-scrollbar
|
||||||
|
> .thaw-scrollbar__container {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::Scrollbar;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use thaw_utils::{class_list, mount_style, OptionalProp};
|
use thaw_utils::{class_list, mount_style, OptionalProp};
|
||||||
|
|
||||||
|
@ -5,6 +6,8 @@ use thaw_utils::{class_list, mount_style, OptionalProp};
|
||||||
pub fn LayoutSider(
|
pub fn LayoutSider(
|
||||||
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
|
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
|
||||||
#[prop(optional, into)] style: OptionalProp<MaybeSignal<String>>,
|
#[prop(optional, into)] style: OptionalProp<MaybeSignal<String>>,
|
||||||
|
#[prop(optional, into)] content_class: OptionalProp<MaybeSignal<String>>,
|
||||||
|
#[prop(optional, into)] content_style: OptionalProp<MaybeSignal<String>>,
|
||||||
children: Children,
|
children: Children,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
mount_style("layout-sider", include_str!("./layout-sider.css"));
|
mount_style("layout-sider", include_str!("./layout-sider.css"));
|
||||||
|
@ -13,7 +16,9 @@ pub fn LayoutSider(
|
||||||
class=class_list!["thaw-layout-sider", class.map(| c | move || c.get())]
|
class=class_list!["thaw-layout-sider", class.map(| c | move || c.get())]
|
||||||
style=style.map(|s| move || s.get())
|
style=style.map(|s| move || s.get())
|
||||||
>
|
>
|
||||||
|
<Scrollbar content_class content_style>
|
||||||
{children()}
|
{children()}
|
||||||
|
</Scrollbar>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ mod layout_sider;
|
||||||
pub use layout_header::*;
|
pub use layout_header::*;
|
||||||
pub use layout_sider::*;
|
pub use layout_sider::*;
|
||||||
|
|
||||||
|
use crate::Scrollbar;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use thaw_utils::{class_list, mount_style, OptionalProp};
|
use thaw_utils::{class_list, mount_style, OptionalProp};
|
||||||
|
|
||||||
|
@ -27,21 +28,17 @@ impl LayoutPosition {
|
||||||
pub fn Layout(
|
pub fn Layout(
|
||||||
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
|
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
|
||||||
#[prop(optional, into)] style: OptionalProp<MaybeSignal<String>>,
|
#[prop(optional, into)] style: OptionalProp<MaybeSignal<String>>,
|
||||||
|
#[prop(optional, into)] content_class: OptionalProp<MaybeSignal<String>>,
|
||||||
|
#[prop(optional, into)] content_style: OptionalProp<MaybeSignal<String>>,
|
||||||
#[prop(optional)] position: LayoutPosition,
|
#[prop(optional)] position: LayoutPosition,
|
||||||
#[prop(optional, into)] has_sider: MaybeSignal<bool>,
|
#[prop(optional, into)] has_sider: MaybeSignal<bool>,
|
||||||
children: Children,
|
children: Children,
|
||||||
) -> impl IntoView {
|
) -> impl IntoView {
|
||||||
mount_style("layout", include_str!("./layout.css"));
|
mount_style("layout", include_str!("./layout.css"));
|
||||||
|
|
||||||
let style = create_memo(move |_| {
|
let sider_style = create_memo(move |_| {
|
||||||
let mut new_style = style.as_ref().map(|s| s.get()).unwrap_or_default();
|
|
||||||
if has_sider.get() {
|
if has_sider.get() {
|
||||||
new_style
|
Some("display: flex; flex-wrap: nowrap; flex-direction: row; width: 100%;")
|
||||||
.push_str("display: flex; flex-wrap: nowrap; flex-direction: row; width: 100%;");
|
|
||||||
|
|
||||||
Some(new_style)
|
|
||||||
} else if style.is_some() {
|
|
||||||
Some(new_style)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -49,9 +46,11 @@ pub fn Layout(
|
||||||
view! {
|
view! {
|
||||||
<div
|
<div
|
||||||
class=class_list![gen_class(position), class.map(| c | move || c.get())]
|
class=class_list![gen_class(position), class.map(| c | move || c.get())]
|
||||||
style=move || style.get()
|
style=move || style.as_ref().map(|s| s.get())
|
||||||
>
|
>
|
||||||
|
<Scrollbar content_class content_style=Signal::derive(move || format!("{} {}", sider_style.get().unwrap_or_default(), content_style.as_ref().map_or(String::new(), |s| s.get())))>
|
||||||
{children()}
|
{children()}
|
||||||
|
</Scrollbar>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue