Skip to content

Commit

Permalink
feat: Added alert modal
Browse files Browse the repository at this point in the history
  • Loading branch information
emirror-de committed Mar 9, 2024
1 parent ccfde3e commit e47aa94
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/modules/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ extern "C" {
#[wasm_bindgen(js_name = "$", catch)]
fn new_modal_from_selector(selector: &JsValue) -> Result<Modal, JsValue>;

/// 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<dyn Fn()>,
) -> Modal;

#[wasm_bindgen(method, js_name = "modal")]
pub fn modal(this: &Modal, behavior: &JsValue);

Expand All @@ -59,6 +68,17 @@ impl Modal {
Ok(new_modal(&modal_config_js))
}

/// Creates an `Alert` modal.
pub fn new_alert<H: 'static>(title: String, content: String, handler: H) -> anyhow::Result<Self>
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<Self> {
Ok(new_modal_from_selector(&JsValue::from(selector))
Expand Down

0 comments on commit e47aa94

Please sign in to comment.