diff --git a/src/modules/modal.rs b/src/modules/modal.rs index 165f770..f8a415c 100644 --- a/src/modules/modal.rs +++ b/src/modules/modal.rs @@ -44,6 +44,15 @@ extern "C" { #[wasm_bindgen(js_name = "$", catch)] fn new_modal_from_selector(selector: &JsValue) -> Result; + /// Internal function to create the modal alert template. + #[wasm_bindgen(js_namespace=["$"], js_name="modal")] + fn new_modal_alert( + props: &JsValue, + title: String, + content: String, + handler: &Closure, + ) -> Modal; + #[wasm_bindgen(method, js_name = "modal")] pub fn modal(this: &Modal, behavior: &JsValue); @@ -59,6 +68,17 @@ impl Modal { Ok(new_modal(&modal_config_js)) } + /// Creates an `Alert` modal. + pub fn new_alert(title: String, content: String, handler: H) -> anyhow::Result + where + H: Fn(), + { + let handler = Closure::new(handler); + let result = new_modal_alert(&JsValue::from("alert"), title, content, &handler); + handler.forget(); + Ok(result) + } + /// Queries the modal by the given selector. pub fn query_from_selector(selector: &str) -> anyhow::Result { Ok(new_modal_from_selector(&JsValue::from(selector))