brazier/attribute
Types
Values
pub fn attribute(name: String, value: String) -> Attribute(msg)
An attribute with any name.
These are programming errors and crash:
- an inline event attribute such as
onclick: usebrazier/event; srcdoc: useunsafe_srcdoc;- a
data-brazier-*name, which Brazier’s client reads and only the render sets (data-brazier-keyforelement.keyed,data-brazier-streamforbrazier/stream.render,data-brazier-on-*forbrazier/event, and the others the client uses). Four are app API and allowed:data-brazier-hook(hook),data-brazier-hook-watch(watch),data-brazier-preserve-children(ignore_updates) anddata-brazier-external(a link the client does not navigate); attributeNamewith a value containinghref(href,xlink:href): an SVG<animate>or<set>targeting a link’s URL would change it after the URL policy has checked it;- a name with characters outside
a-z A-Z 0-9 - _ : ..
Names match case-insensitively, as HTML attribute names do.
URL attributes (href, src, action, formaction, poster, cite,
xlink:href) go through the URL policy. A refused value produces no
attribute and logs a warning.
pub fn boolean(name: String, on: Bool) -> Attribute(msg)
A boolean attribute: present with an empty value when on is true,
absent otherwise. A name attribute refuses crashes either way.
pub fn classes(names: List(#(String, Bool))) -> Attribute(msg)
Several classes, each included when its flag is true.
pub fn data(name: String, value: String) -> Attribute(msg)
A data-<name> attribute. data("brazier-key", ..) and the other
reserved data-brazier-* names crash, as in attribute.
pub fn formaction(url: String) -> Attribute(msg)
pub fn hook(name: String) -> Attribute(msg)
Attach a client hook registered with Brazier.hooks in JavaScript.
LiveView’s phx-hook.
pub fn ignore_updates() -> Attribute(msg)
Leave this element’s children to client code: the client morph does not
touch them after the first render. LiveView’s phx-update="ignore".
pub fn map(
attribute: Attribute(a),
f: fn(a) -> b,
) -> Attribute(b)
Map the message of an event listener. Plain attributes are unchanged.
pub fn placeholder(text: String) -> Attribute(msg)
pub fn style(property: String, value: String) -> Attribute(msg)
One inline style declaration. Several style attributes on the same
element are joined with ;.
pub fn styles(
properties: List(#(String, String)),
) -> Attribute(msg)
Several inline style declarations as one style attribute, in order.
An empty list adds no attribute. Like style, it joins with any other
style attributes on the same element.
pub fn unsafe_srcdoc(html: String) -> Attribute(msg)
An <iframe> srcdoc attribute: html is the whole document the
iframe shows. Its markup is not escaped or checked, and unless the
iframe has a sandbox attribute without allow-scripts and
allow-same-origin together, its scripts run with the page’s origin.
Like element.unsafe_raw_html, never pass it text that a user controls.
The value is attribute-escaped, as every value is; the browser decodes
it back to html.