#![allow(non_upper_case_globals)] #![allow(deprecated)] use dioxus_core::HasAttributes; use dioxus_core::IntoAttributeValue; use dioxus_html_internal_macro::impl_extension_attributes; use crate::AttributeDescription; #[cfg(feature = "hot-reload-context")] macro_rules! mod_method_mapping { ( $matching:ident; $(#[$attr:meta])* $name:ident; ) => { if $matching == stringify!($name) { return Some((stringify!($name), None)); } }; ( $matching:ident; $(#[$attr:meta])* $name:ident: $lit:literal; ) => { if $matching == stringify!($name) { return Some(($lit, None)); } }; ( $matching:ident; $(#[$attr:meta])* $name:ident: $lit:literal in $ns:literal; ) => { if $matching == stringify!($name) { return Some(($lit, Some($ns))); } }; ( $matching:ident; $(#[$attr:meta])* $name:ident in $ns:literal; ) => { if $matching == stringify!($name) { return Some((stringify!($name), Some($ns))); } }; } #[cfg(feature = "html-to-rsx")] macro_rules! html_to_rsx_attribute_mapping { ( $matching:ident; $(#[$attr:meta])* $name:ident; ) => { if $matching == stringify!($name) { return Some(stringify!($name)); } }; ( $matching:ident; $(#[$attr:meta])* $name:ident: $lit:literal; ) => { if $matching == $lit { return Some(stringify!($name)); } }; ( $matching:ident; $(#[$attr:meta])* $name:ident: $lit:literal in $ns:literal; ) => { if $matching == $lit { return Some(stringify!($name)); } }; ( $matching:ident; $(#[$attr:meta])* $name:ident in $ns:literal; ) => { if $matching == stringify!($name) { return Some(stringify!($name)); } }; } macro_rules! mod_methods { ( @base $(#[$mod_attr:meta])* $mod:ident; $fn:ident; $fn_html_to_rsx:ident; $( $(#[$attr:meta])* $name:ident $(: $(no-$alias:ident)? $js_name:literal)? $(in $ns:literal)?; )+ ) => { $(#[$mod_attr])* pub mod $mod { use super::*; $( mod_methods! { @attr $(#[$attr])* $name $(: $(no-$alias)? $js_name)? $(in $ns)?; } )+ } #[cfg(feature = "hot-reload-context")] pub(crate) fn $fn(attr: &str) -> Option<(&'static str, Option<&'static str>)> { $( mod_method_mapping! { attr; $name $(: $js_name)? $(in $ns)?; } )* None } #[cfg(feature = "html-to-rsx")] #[doc = "Converts an HTML attribute to an RSX attribute"] pub(crate) fn $fn_html_to_rsx(html: &str) -> Option<&'static str> { $( html_to_rsx_attribute_mapping! { html; $name $(: $js_name)? $(in $ns)?; } )* None } impl_extension_attributes![$mod { $($name,)* }]; }; ( @attr $(#[$attr:meta])* $name:ident $(: no-alias $js_name:literal)? $(in $ns:literal)?; ) => { $(#[$attr])* /// /// ## Usage in rsx /// /// ```rust, ignore /// # use dioxus::prelude::*; #[doc = concat!("let ", stringify!($name), " = \"value\";")] /// /// rsx! { /// // Attributes need to be under the element they modify /// div { /// // Attributes are followed by a colon and then the value of the attribute #[doc = concat!(" ", stringify!($name), ": \"value\"")] /// } /// div { /// // Or you can use the shorthand syntax if you have a variable in scope that has the same name as the attribute #[doc = concat!(" ", stringify!($name), ",")] /// } /// }; /// ``` pub const $name: AttributeDescription = mod_methods! { $name $(: $js_name)? $(in $ns)?; }; }; ( @attr $(#[$attr:meta])* $name:ident $(: $js_name:literal)? $(in $ns:literal)?; ) => { $(#[$attr])* /// /// ## Usage in rsx /// /// ```rust, ignore /// # use dioxus::prelude::*; #[doc = concat!("let ", stringify!($name), " = \"value\";")] /// /// rsx! { /// // Attributes need to be under the element they modify /// div { /// // Attributes are followed by a colon and then the value of the attribute #[doc = concat!(" ", stringify!($name), ": \"value\"")] /// } /// div { /// // Or you can use the shorthand syntax if you have a variable in scope that has the same name as the attribute #[doc = concat!(" ", stringify!($name), ",")] /// } /// }; /// ``` $( #[doc(alias = $js_name)] )? pub const $name: AttributeDescription = mod_methods! { $name $(: $js_name)? $(in $ns)?; }; }; // Rename the incoming ident and apply a custom namespace ( $name:ident: $lit:literal in $ns:literal; ) => { ($lit, Some($ns), false) }; // Custom namespace ( $name:ident in $ns:literal; ) => { (stringify!($name), Some($ns), false) }; // Rename the incoming ident ( $name:ident: $lit:literal; ) => { ($lit, None, false ) }; // Don't rename the incoming ident ( $name:ident; ) => { (stringify!($name), None, false) }; } mod_methods! { @base global_attributes; map_global_attributes; map_html_global_attributes_to_rsx; #[deprecated(note = "This attribute does nothing. For most renderers, you should prefer calling [`dioxus_core::Event::prevent_default`] on the event instead. For liveview, you can use `\"onclick\": (evt) => evt.prevent_default()` to prevent the default action for this element.")] /// This attribute has been deprecated in favor of [`dioxus_core::Event::prevent_default`] prevent_default: "dioxus-prevent-default"; /// accesskey; /// autocapitalize; /// autofocus; /// The HTML class attribute is used to specify a class for an HTML element. /// /// ## Details /// Multiple HTML elements can share the same class. /// /// The class global attribute is a space-separated list of the case-sensitive classes of the element. /// Classes allow CSS and Javascript to select and access specific elements via the class selectors or /// functions like the DOM method document.getElementsByClassName. /// /// ## Multiple Classes /// /// If you include multiple classes in a single element dioxus will automatically join them with a space. /// /// ```rust /// # use dioxus::prelude::*; /// rsx! { /// div { /// class: "my-class", /// class: "my-other-class" /// } /// }; /// ``` /// /// ## Optional Classes /// /// You can include optional attributes with an unterminated if statement as the value of the attribute. This is very useful for conditionally applying css classes: /// /// ```rust /// # use dioxus::prelude::*; /// rsx! { /// div { /// class: if true { /// "my-class" /// }, /// class: if false { /// "my-other-class" /// } /// } /// }; /// ``` /// /// class; /// contenteditable; /// dir; /// draggable; /// enterkeyhint; /// exportparts; ///