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