mirror of
https://github.com/zaphar/wasm-web-components.git
synced 2025-07-23 19:59:48 -04:00
Add an attach shadow method
This commit is contained in:
parent
a63670b7d3
commit
f03d1641d9
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasm-web-component-macros"
|
name = "wasm-web-component-macros"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -224,6 +224,19 @@ fn expand_wasm_shim(struct_name: &Ident) -> syn::ItemImpl {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[::wasm_bindgen::prelude::wasm_bindgen]
|
||||||
|
#[doc = "Attach an open shadowroot to our element."]
|
||||||
|
pub fn attach_shadow(&self, element: &web_sys::HtmlElement, root: &str) {
|
||||||
|
self.attach_shadow_with_mode(element, root, web_sys::ShadowRootMode::Open);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[::wasm_bindgen::prelude::wasm_bindgen]
|
||||||
|
#[doc = "Attach a shadowroot with the given mode to our element."]
|
||||||
|
pub fn attach_shadow_with_mode(&self, element: &web_sys::HtmlElement, root: &str, mode: web_sys::ShadowRootMode) {
|
||||||
|
let shadow_root = element.attach_shadow(&web_sys::ShadowRootInit::new(mode)).unwrap();
|
||||||
|
shadow_root.set_inner_html(root);
|
||||||
|
}
|
||||||
|
|
||||||
#[::wasm_bindgen::prelude::wasm_bindgen]
|
#[::wasm_bindgen::prelude::wasm_bindgen]
|
||||||
pub fn init_impl(&mut self, element: &web_sys::HtmlElement) {
|
pub fn init_impl(&mut self, element: &web_sys::HtmlElement) {
|
||||||
use #trait_path;
|
use #trait_path;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasm-web-component"
|
name = "wasm-web-component"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user