macro_rules! telegram_button {
($doc:expr, $text:expr $(, class = $class:expr)? $(, $attr:literal = $value:expr)* $(,)?) => { ... };
}Available on crate feature
macros only.Expand description
Create a <button> element.
Generates a web_sys::HtmlElement with the provided text, optional CSS
class and arbitrary attributes. The macro evaluates to
Result<web_sys::HtmlElement, wasm_bindgen::JsValue> so it can be used with
the ? operator inside functions returning Result.
§Examples
ⓘ
use telegram_webapp_sdk::telegram_button;
use wasm_bindgen::JsValue;
let document = web_sys::window()
.and_then(|w| w.document())
.ok_or_else(|| JsValue::from_str("no document"))?;
let button = telegram_button!(document, "Click", class = "primary", "type" = "button")?;
assert_eq!(button.tag_name(), "BUTTON");