dioxus_document/elements/
meta.rs1use super::*;
2use crate::document;
3use dioxus_core::{use_hook, VNode};
4use dioxus_html as dioxus_elements;
5
6#[non_exhaustive]
7#[derive(Clone, Props, PartialEq)]
9pub struct MetaProps {
10 pub property: Option<String>,
11 pub name: Option<String>,
12 pub charset: Option<String>,
13 pub http_equiv: Option<String>,
14 pub content: Option<String>,
15 pub data: Option<String>,
16 #[props(extends = meta, extends = GlobalAttributes)]
17 pub additional_attributes: Vec<Attribute>,
18}
19
20impl MetaProps {
21 pub fn attributes(&self) -> Vec<(&'static str, String)> {
23 let mut attributes = Vec::new();
24 extend_attributes(&mut attributes, &self.additional_attributes);
25 if let Some(property) = &self.property {
26 attributes.push(("property", property.clone()));
27 }
28 if let Some(name) = &self.name {
29 attributes.push(("name", name.clone()));
30 }
31 if let Some(charset) = &self.charset {
32 attributes.push(("charset", charset.clone()));
33 }
34 if let Some(http_equiv) = &self.http_equiv {
35 attributes.push(("http-equiv", http_equiv.clone()));
36 }
37 if let Some(content) = &self.content {
38 attributes.push(("content", content.clone()));
39 }
40 if let Some(data) = &self.data {
41 attributes.push(("data", data.clone()));
42 }
43 attributes
44 }
45}
46
47#[component]
71#[doc(alias = "<meta>")]
72pub fn Meta(props: MetaProps) -> Element {
73 use_update_warning(&props, "Meta {}");
74
75 use_hook(|| {
76 let document = document();
77 let insert_link = document.create_head_component();
78
79 if !insert_link {
80 return;
81 }
82
83 document.create_meta(props);
84 });
85
86 VNode::empty()
87}