Skip to content

Commit 8a6e0ee

Browse files
committed
feat: Layout scrollbar
1 parent a1a301a commit 8a6e0ee

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

demo/src/pages/components.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn ComponentsPage() -> impl IntoView {
5656

5757
</Menu>
5858
</LayoutSider>
59-
<Layout style="padding: 8px 12px 28px; overflow-y: auto;">
59+
<Layout content_style="padding: 8px 12px 28px;">
6060
<Outlet/>
6161
</Layout>
6262
</Layout>

demo/src/pages/guide.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn GuidePage() -> impl IntoView {
5555

5656
</Menu>
5757
</LayoutSider>
58-
<Layout style="padding: 8px 12px 28px; overflow-y: auto;">
58+
<Layout content_style="padding: 8px 12px 28px;">
5959
<Outlet/>
6060
</Layout>
6161
</Layout>

demo_markdown/docs/layout/mod.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ view! {
3535

3636
| Name | Type | Default | Description |
3737
| --- | --- | --- | --- |
38-
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the layout element. |
38+
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Class of scrollable content node. |
3939
| style | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Layout's style. |
40+
| content_class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the layout element. |
41+
| content_style | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Style of scrollable content node. |
4042
| 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. |
4143
| has_sider | `MaybeSignal<bool>` | `false` | Whether the component has sider inside. If so it must be true. |
4244
| children | `Children` | | Layout's content. |

thaw/src/layout/layout.css

+6
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
bottom: 0;
1010
left: 0;
1111
}
12+
13+
.thaw-layout--absolute-positioned
14+
> .thaw-scrollbar
15+
> .thaw-scrollbar__container {
16+
display: flex;
17+
}

thaw/src/layout/layout_sider.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
use crate::Scrollbar;
12
use leptos::*;
23
use thaw_utils::{class_list, mount_style, OptionalProp};
34

45
#[component]
56
pub fn LayoutSider(
67
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
78
#[prop(optional, into)] style: OptionalProp<MaybeSignal<String>>,
9+
#[prop(optional, into)] content_class: OptionalProp<MaybeSignal<String>>,
10+
#[prop(optional, into)] content_style: OptionalProp<MaybeSignal<String>>,
811
children: Children,
912
) -> impl IntoView {
1013
mount_style("layout-sider", include_str!("./layout-sider.css"));
@@ -13,7 +16,9 @@ pub fn LayoutSider(
1316
class=class_list!["thaw-layout-sider", class.map(| c | move || c.get())]
1417
style=style.map(|s| move || s.get())
1518
>
16-
{children()}
19+
<Scrollbar content_class content_style>
20+
{children()}
21+
</Scrollbar>
1722
</div>
1823
}
1924
}

thaw/src/layout/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod layout_sider;
44
pub use layout_header::*;
55
pub use layout_sider::*;
66

7+
use crate::Scrollbar;
78
use leptos::*;
89
use thaw_utils::{class_list, mount_style, OptionalProp};
910

@@ -27,31 +28,29 @@ impl LayoutPosition {
2728
pub fn Layout(
2829
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
2930
#[prop(optional, into)] style: OptionalProp<MaybeSignal<String>>,
31+
#[prop(optional, into)] content_class: OptionalProp<MaybeSignal<String>>,
32+
#[prop(optional, into)] content_style: OptionalProp<MaybeSignal<String>>,
3033
#[prop(optional)] position: LayoutPosition,
3134
#[prop(optional, into)] has_sider: MaybeSignal<bool>,
3235
children: Children,
3336
) -> impl IntoView {
3437
mount_style("layout", include_str!("./layout.css"));
3538

36-
let style = create_memo(move |_| {
37-
let mut new_style = style.as_ref().map(|s| s.get()).unwrap_or_default();
39+
let sider_style = create_memo(move |_| {
3840
if has_sider.get() {
39-
new_style
40-
.push_str("display: flex; flex-wrap: nowrap; flex-direction: row; width: 100%;");
41-
42-
Some(new_style)
43-
} else if style.is_some() {
44-
Some(new_style)
41+
Some("display: flex; flex-wrap: nowrap; flex-direction: row; width: 100%;")
4542
} else {
4643
None
4744
}
4845
});
4946
view! {
5047
<div
5148
class=class_list![gen_class(position), class.map(| c | move || c.get())]
52-
style=move || style.get()
49+
style=move || style.as_ref().map(|s| s.get())
5350
>
54-
{children()}
51+
<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())))>
52+
{children()}
53+
</Scrollbar>
5554
</div>
5655
}
5756
}

0 commit comments

Comments
 (0)