Skip to content

Commit a9f02ed

Browse files
authored
add class to modal (#206)
* add class to modal * add class to modal * add closable option to modal
1 parent cb37d9c commit a9f02ed

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

demo_markdown/docs/modal/mod.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ view! {
1515

1616
| Name | Type | Default | Description |
1717
| -------------- | --------------------- | -------------------- | ------------------------------------------- |
18+
| class | `OptionalProp<MaybeSignal<String>>` | `Default::default()` | Addtional classes for the modal element. |
1819
| show | `Model<bool>` | | Whether to show modal. |
1920
| title | `MaybeSignal<String>` | `Default::default()` | Modal title. |
2021
| width | `MaybeSignal<String>` | `600px` | Modal width. |
2122
| z_index | `MaybeSignal<i16>` | `2000` | z-index of the modal. |
2223
| mask_closeable | `MaybeSignal<bool>` | `true` | Whether to emit hide event when click mask. |
2324
| close_on_esc | `bool` | `true` | Whether to close modal on Esc is pressed. |
25+
| closable | `bool` | `true` | Whether to display the close button. |
2426
| children | `Children` | | Modal's content. |
2527

2628
### Modal Slots

thaw/src/modal/mod.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{Card, CardFooter, CardHeader, CardHeaderExtra, Icon, Scrollbar, ScrollbarRef};
22
use leptos::*;
3-
use thaw_components::{CSSTransition, FocusTrap, OptionComp, Teleport};
4-
use thaw_utils::{mount_style, use_click_position, ComponentRef, Model};
3+
use thaw_components::{CSSTransition, FocusTrap, If, OptionComp, Teleport, Then};
4+
use thaw_utils::{class_list, mount_style, use_click_position, ComponentRef, Model, OptionalProp};
55

66
#[slot]
77
pub struct ModalFooter {
@@ -13,11 +13,13 @@ pub fn Modal(
1313
#[prop(into)] show: Model<bool>,
1414
#[prop(default = true.into(), into)] mask_closeable: MaybeSignal<bool>,
1515
#[prop(default = true, into)] close_on_esc: bool,
16+
#[prop(default = true, into)] closable: bool,
1617
#[prop(default = 2000.into(), into)] z_index: MaybeSignal<i16>,
1718
#[prop(default = MaybeSignal::Static("600px".to_string()), into)] width: MaybeSignal<String>,
1819
#[prop(optional, into)] title: MaybeSignal<String>,
1920
children: Children,
2021
#[prop(optional)] modal_footer: Option<ModalFooter>,
22+
#[prop(optional, into)] class: OptionalProp<MaybeSignal<String>>,
2123
) -> impl IntoView {
2224
mount_style("modal", include_str!("./modal.css"));
2325

@@ -80,6 +82,7 @@ pub fn Modal(
8082
String::from("display: none")
8183
}
8284
})
85+
8386
comp_ref=scrollbar_ref
8487
>
8588
<CSSTransition
@@ -106,7 +109,9 @@ pub fn Modal(
106109
let:display
107110
>
108111
<div
109-
class="thaw-modal-body"
112+
class=class_list![
113+
"thaw-modal-body", class.map(| c | move || c.get())
114+
]
110115
ref=modal_ref
111116
role="dialog"
112117
aria-modal="true"
@@ -117,12 +122,16 @@ pub fn Modal(
117122
<span class="thaw-model-title">{move || title.get()}</span>
118123
</CardHeader>
119124
<CardHeaderExtra slot>
120-
<span
121-
style="cursor: pointer;"
122-
on:click=move |_| show.set(false)
123-
>
124-
<Icon icon=icondata_ai::AiCloseOutlined/>
125-
</span>
125+
<If cond=closable>
126+
<Then slot>
127+
<span
128+
style="cursor: pointer;"
129+
on:click=move |_| show.set(false)
130+
>
131+
<Icon icon=icondata_ai::AiCloseOutlined/>
132+
</span>
133+
</Then>
134+
</If>
126135
</CardHeaderExtra>
127136
{children()}
128137
<CardFooter slot if_=modal_footer.is_some()>

0 commit comments

Comments
 (0)