dioxus/examples/custom_element.rs

41 lines
1.1 KiB
Rust
Raw Normal View History

2022-04-24 23:44:20 +00:00
//! This example shows to wrap a webcomponent / custom element with a component.
//!
//! Oftentimes, a third party library will provide a webcomponent that you want
//! to use in your application. This example shows how to create that custom element
//! directly with the raw_element method on NodeFactory.
use dioxus::prelude::*;
fn main() {
let mut dom = VirtualDom::new(app);
let _ = dom.rebuild();
2022-12-07 01:50:25 +00:00
let output = dioxus_ssr::render(&dom);
2022-04-24 23:44:20 +00:00
println!("{}", output);
}
fn app(cx: Scope) -> Element {
2022-12-13 02:31:30 +00:00
let g = cx.component(component, (), "component");
let c = cx.make_node(g);
cx.render(rsx! {
div { c }
})
// let nf = NodeFactory::new(cx);
2022-04-24 23:44:20 +00:00
2022-11-16 07:22:41 +00:00
// let mut attrs = dioxus::core::exports::bumpalo::collections::Vec::new_in(nf.bump());
2022-04-24 23:44:20 +00:00
2022-11-16 07:22:41 +00:00
// attrs.push(nf.attr("client-id", format_args!("abc123"), None, false));
2022-04-24 23:44:20 +00:00
2022-11-16 07:22:41 +00:00
// attrs.push(nf.attr("name", format_args!("bob"), None, false));
2022-04-24 23:44:20 +00:00
2022-11-16 07:22:41 +00:00
// attrs.push(nf.attr("age", format_args!("47"), None, false));
2022-04-24 23:44:20 +00:00
2022-11-16 07:22:41 +00:00
// Some(nf.raw_element("my-element", None, &[], attrs.into_bump_slice(), &[], None))
2022-12-13 02:31:30 +00:00
}
2022-11-16 07:22:41 +00:00
2022-12-13 02:31:30 +00:00
fn component(cx: Scope) -> Element {
2022-11-16 07:22:41 +00:00
todo!()
2022-04-24 23:44:20 +00:00
}