Expand description
§dioxus-html
: Html (and SVG) Namespace for Dioxus
Website | Guides | API Docs | Chat
§Overview
The Dioxus rsx!
macro can accept any compile-time correct namespace on top of NodeFactory. This crate provides the HTML (and SVG) namespaces which get imported in the Dioxus prelude.
However, this abstraction enables you to add any namespace of elements, provided they’re in scope when rsx! is called. For an example, a UI that is designed for Augmented Reality might use different primitives than HTML:
use ar_namespace::*;
rsx! {
magic_div {
magic_header {}
magic_paragraph {
on_magic_click: move |event| {
//
}
}
}
}
This is currently a not-very-explored part of Dioxus. However, the namespacing system does make it possible to provide syntax highlighting, documentation, “go to definition” and compile-time correctness, so it’s worth having it abstracted.
§How it works:
Elements for dioxus must implement the (simple) DioxusElement trait to be used in the rsx! macro.
struct div;
impl DioxusElement for div {
const TAG_NAME: &'static str = "div";
const NAME_SPACE: Option<&'static str> = None;
}
All elements should be defined as a zero-sized-struct (also known as unit struct). These structs are zero-cost and just provide the type-level trickery to Rust for compile-time correct templates.
Attributes would then be implemented as constants on these unit structs.
The HTML namespace is defined mostly with macros. However, the expanded form would look something like this:
struct base;
impl DioxusElement for base {
const TAG_NAME: &'static str = "base";
const NAME_SPACE: Option<&'static str> = None;
}
impl base {
const href: (&'static str, Option<'static str>, bool) = ("href", None, false);
const target: (&'static str, Option<'static str>, bool) = ("target", None, false);
}
Because attributes are defined as methods on the unit struct, they guard the attribute creation behind a compile-time correct interface.
§How to extend it:
Whenever the rsx! macro is called, it relies on a module dioxus_elements
to be in scope. When you enable the html
feature in dioxus, this module gets imported in the prelude. However, you can extend this with your own set of custom elements by making your own dioxus_elements
module and re-exporting the html namespace.
mod dioxus_elements {
use dioxus::prelude::dioxus_elements::*;
struct my_element;
impl DioxusElement for my_element {
const TAG_NAME: &'static str = "base";
const NAME_SPACE: Option<&'static str> = None;
}
}
§Contributing
- Report issues on our issue tracker.
- Join the discord and ask questions!
§License
This project is licensed under the MIT license.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Dioxus by you shall be licensed as MIT without any additional terms or conditions.
§Dioxus Namespace for HTML
This crate provides a set of compile-time correct HTML elements that can be used with the Rsx and Html macros. This system allows users to easily build new tags, new types, and customize the output of the Rsx and Html macros.
An added benefit of this approach is the ability to lend comprehensive documentation on how to use these elements inside of the Rsx and Html macros. Each element comes with a substantial amount of documentation on how to best use it, hopefully making the development cycle quick.
All elements are used as zero-sized unit structs with trait impls.
Currently, we don’t validate for structures, but do validate attributes.
Modules§
- elements
- events
- Event Handlers
- extensions
- geometry
- Geometry primitives for representing e.g. mouse events
- global_
attributes - input_
data - Data structures representing user input, such as modifier keys and mouse buttons
- point_
interaction - prelude
- svg_
attributes
Structs§
- Animation
Data - Clipboard
Data - Composition
Data - Drag
Data - The DragEvent interface is a DOM event that represents a drag and drop interaction. The user initiates a drag by placing a pointer device (such as a mouse) on the touch surface and then dragging the pointer to a new location (such as another DOM element). Applications are free to interpret a drag and drop interaction in an application-specific way.
- Focus
Data - Form
Data - Form
Value - A form value that may either be a list of values or a single value
- Image
Data - Keyboard
Data - Media
Data - Mounted
Data - An Element that has been rendered and allows reading and modifying information about it.
- Mouse
Data - A synthetic event that wraps a web-style
MouseEvent
Data associated with a mouse event - Platform
Event Data - A platform specific event.
- Pointer
Data - Resize
Data - Scroll
Data - Selection
Data - Toggle
Data - Touch
Data - Touch
Point - Transition
Data - Visible
Data - Wheel
Data - Data associated with a WheelEvent
Enums§
- KeyCode
- Mounted
Error - The error type for the MountedData
- Resize
Error - The error type for the MountedData
- Scroll
Behavior - The way that scrolling should be performed
- Visible
Error - The error type for the VisibleData
Traits§
- File
Engine - Global
Attributes Extension - HasAnimation
Data - A trait for any object that has the data for an animation event
- HasClipboard
Data - HasComposition
Data - A trait for any object that has the data for a composition event
- HasDrag
Data - A trait for any object that has the data for a drag event
- HasFile
Data - HasFocus
Data - HasForm
Data - An object that has all the data for a form event
- HasImage
Data - A trait for any object that has the data for an image event
- HasKeyboard
Data - HasMedia
Data - HasMouse
Data - A trait for any object that has the data for a mouse event
- HasPointer
Data - A trait for any object that has the data for a pointer event
- HasResize
Data - HasScroll
Data - HasSelection
Data - HasToggle
Data - HasTouch
Data - HasTouch
Point Data - A trait for touch point data
- HasTransition
Data - HasVisible
Data - HasWheel
Data - Html
Event Converter - A converter between a platform specific event and a general event. All code in a renderer that has a large binary size should be placed in this trait. Each of these functions should be snipped in high levels of optimization.
- Rendered
Element Backing - An Element that has been rendered and allows reading and modifying information about it.
- SvgAttributes
Extension
Functions§
- onabort
- abort
- onanimationend
- onanimationend
- onanimationiteration
- onanimationiteration
- onanimationstart
- onanimationstart
- onblur
- onblur
- oncanplay
- canplay
- oncanplaythrough
- canplaythrough
- onchange
- onchange
- onclick
- Execute a callback when a button is clicked.
- oncompositionend
- oncompositionend
- oncompositionstart
- oncompositionstart
- oncompositionupdate
- oncompositionupdate
- oncontextmenu
- oncontextmenu
- oncopy
- oncopy
- oncut
- oncut
- ondblclick
Deprecated General Event Handler Information
- ondoubleclick
General Event Handler Information
- ondrag
- ondrag
- ondragend
- ondragend
- ondragenter
- ondragenter
- ondragexit
- ondragexit
- ondragleave
- ondragleave
- ondragover
- ondragover
- ondragstart
- ondragstart
- ondrop
- ondrop
- ondurationchange
- durationchange
- onemptied
- emptied
- onencrypted
- encrypted
- onended
- ended
- onerror
- onerror
- onfocus
- onfocus
- onfocusin
General Event Handler Information
- onfocusout
General Event Handler Information
- ongotpointercapture
- gotpointercapture
- oninput
- The
oninput
event is fired when the value of a<input>
,<select>
, or<textarea>
element is changed. - oninvalid
- oninvalid
- onkeydown
- onkeydown
- onkeypress
- onkeypress
- onkeyup
- onkeyup
- onload
- onload
- onloadeddata
- loadeddata
- onloadedmetadata
- loadedmetadata
- onloadstart
- loadstart
- onlostpointercapture
- lostpointercapture
- onmounted
- The onmounted event is fired when the element is first added to the DOM. This event gives you a
MountedData
object and lets you interact with the raw DOM element. - onmousedown
- onmousedown
- onmouseenter
- onmouseenter
- onmouseleave
- onmouseleave
- onmousemove
- onmousemove
- onmouseout
- onmouseout
- onmouseover
- onmouseover
- onmouseup
- onmouseup
- onpaste
- onpaste
- onpause
- pause
- onplay
- play
- onplaying
- playing
- onpointercancel
- pointercancel
- onpointerdown
- pointerdown
- onpointerenter
- pointerenter
- onpointerleave
- pointerleave
- onpointermove
- pointermove
- onpointerout
- pointerout
- onpointerover
- pointerover
- onpointerup
- pointerup
- onprogress
- progress
- onratechange
- ratechange
- onreset
- onreset
- onresize
- onresize
- onscroll
- onscroll
- onseeked
- seeked
- onseeking
- seeking
- onselect
- select
- onselectionchange
- selectionchange
- onselectstart
- selectstart
- onstalled
- stalled
- onsubmit
- onsubmit
- onsuspend
- suspend
- ontimeupdate
- timeupdate
- ontoggle
- ontoggle
- ontouchcancel
- touchcancel
- ontouchend
- touchend
- ontouchmove
- touchmove
- ontouchstart
- touchstart
- ontransitionend
- transitionend
- onvisible
- onvisible
- onvolumechange
- volumechange
- onwaiting
- waiting
- onwheel
- Called when the mouse wheel is rotated over an element.
- render_
template_ to_ html - Render a template to an HTML string
- set_
event_ converter
Type Aliases§
- Animation
Event - Attribute
Description - Clipboard
Event - Composition
Event - Drag
Event - Focus
Event - Form
Event - Image
Event - Keyboard
Event - Media
Event - Mounted
Event - Mounted
Result - The MountedResult type for the MountedData
- Mouse
Event - Pointer
Event - A synthetic event that wraps a web-style
PointerEvent
- Resize
Event - Resize
Result - The ResizeResult type for the ResizeData
- Scroll
Event - Selection
Event - Toggle
Event - Touch
Event - Transition
Event - Visible
Event - Visible
Result - The VisibleResult type for the VisibleData
- Wheel
Event - A synthetic event that wraps a web-style
WheelEvent