Skip to content

Commit 8fe168b

Browse files
committed
feat: drawer adds mount prop
1 parent 453554f commit 8fe168b

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

demo_markdown/docs/drawer/mod.md

+17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ view! {
2222
}
2323
```
2424

25+
### Customize display area
26+
27+
```rust demo
28+
let show = create_rw_signal(false);
29+
30+
view! {
31+
<div style="position: relative; height: 200px; background-color: #0078ff88;">
32+
<Button on_click=move |_| show.set(true)>"Open"</Button>
33+
<Drawer show mount=DrawerMount::None>
34+
"Current position"
35+
</Drawer>
36+
</div>
37+
}
38+
```
39+
2540
### Drawer Props
2641

2742
| Name | Type | Default | Desciption |
@@ -32,4 +47,6 @@ view! {
3247
| placement | `MaybeSignal<DrawerPlacement>` | `DrawerPlacement::Right` | Drawer placement. |
3348
| width | `MaybeSignal<String>` | `520px` | Drawer width. |
3449
| height | `MaybeSignal<String>` | `260px` | Drawer height. |
50+
| z_index | `MaybeSignal<i16>` | `2000` | z-index of the drawer. |
51+
| mount | `DrawerMount` | `DrawerMount::Body` | Container node of the drawer. |
3552
| children | `Children` | | Drawer content. |

thaw/src/drawer/mod.rs

+32-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pub fn Drawer(
1212
#[prop(optional, into)] placement: MaybeSignal<DrawerPlacement>,
1313
#[prop(default = MaybeSignal::Static("520px".to_string()), into)] width: MaybeSignal<String>,
1414
#[prop(default = MaybeSignal::Static("260px".to_string()), into)] height: MaybeSignal<String>,
15-
#[prop(default = MaybeSignal::Static("2000".to_string()), into)] z_index: MaybeSignal<String>,
15+
#[prop(default = 2000.into(), into)] z_index: MaybeSignal<i16>,
16+
#[prop(optional, into)] mount: DrawerMount,
1617
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
1718
children: Children,
1819
) -> impl IntoView {
@@ -24,8 +25,17 @@ pub fn Drawer(
2425
css_vars
2526
});
2627

27-
view! {
28-
<Teleport>
28+
#[component]
29+
fn DrawerInnr(
30+
show: Model<bool>,
31+
title: OptionalProp<MaybeSignal<String>>,
32+
placement: MaybeSignal<DrawerPlacement>,
33+
z_index: MaybeSignal<i16>,
34+
class: OptionalProp<MaybeSignal<String>>,
35+
css_vars: Memo<String>,
36+
children: Children,
37+
) -> impl IntoView {
38+
view! {
2939
<div
3040
class="thaw-drawer-container"
3141
style=move || if show.get() { format!("z-index: {}", z_index.get()) } else { "display: none".to_string() }
@@ -42,7 +52,18 @@ pub fn Drawer(
4252
<Card title>{children()}</Card>
4353
</div>
4454
</div>
45-
</Teleport>
55+
}
56+
}
57+
58+
match mount {
59+
DrawerMount::None => view! {
60+
<DrawerInnr show title placement z_index class css_vars children />
61+
},
62+
DrawerMount::Body => view! {
63+
<Teleport>
64+
<DrawerInnr show title placement z_index class css_vars children />
65+
</Teleport>
66+
},
4667
}
4768
}
4869

@@ -65,3 +86,10 @@ impl DrawerPlacement {
6586
}
6687
}
6788
}
89+
90+
#[derive(Default)]
91+
pub enum DrawerMount {
92+
None,
93+
#[default]
94+
Body,
95+
}

0 commit comments

Comments
 (0)