sauron_core/
svg.rs

1//! Provides functions and macros to build svg elements
2use crate::vdom;
3
4pub use crate::vdom::{element, element_ns};
5pub use tags::commons;
6pub use tags::commons::*;
7pub use tags::special;
8pub use tags::special::*;
9
10pub mod attributes;
11pub mod tags;
12
13/// SVG namespace const, use this when creating an svg element dynamically in the DOM
14pub const SVG_NAMESPACE: &str = "http://www.w3.org/2000/svg";
15
16/// creates an svg element with the tag, attributes and children.
17/// Example:
18/// ```rust
19/// use sauron::{*, svg::*, svg::attributes::*};
20///
21/// let circle: Node<()> = svg_element("circle", vec![cx(1.0), cy(1.0), r(1.0)], vec![]);
22/// assert_eq!(node!{<circle cx=1.0 cy=1.0 r=1.0></circle>}, circle);
23/// ```
24///
25pub fn svg_element<MSG>(
26    tag: &'static str,
27    attrs: impl IntoIterator<Item = vdom::Attribute<MSG>>,
28    children: impl IntoIterator<Item = vdom::Node<MSG>>,
29) -> vdom::Node<MSG> {
30    crate::html::html_element(Some(SVG_NAMESPACE), tag, attrs, children, false)
31}