lustre/attribute#

Constructing attributes#

Attribute#

erlangjavascript

pub opaque type Attribute(msg)

attribute#

erlangjavascript

pub fn attribute(name: String, value: String) -> Attribute(msg)

Attributes are the string key-value pairs that you see attached directly to HTML tags. These are always emitted when rendering a property to a string. There is a subtle difference between HTML attributes and DOM properties, see below.

property#

erlangjavascript

pub fn property(name: String, value: any) -> Attribute(msg)

Properties set the state of an element by manipulating the JavaScript properties on the DOM node. Non-string or non-boolean values will not be emitted when rendering a property to a string.

on#

erlangjavascript

pub fn on(
  name: String,
  handler: fn(Dynamic) -> Result(msg, error)
) -> Attribute(msg)

Mapping attributes#

map#

erlangjavascript

pub fn map(attr: Attribute(a), f: fn(a) -> b) -> Attribute(b)

Conversions#

to_string#

erlangjavascript

pub fn to_string(attr: Attribute(msg)) -> String

to_string_builder#

erlangjavascript

pub fn to_string_builder(attr: Attribute(msg)) -> StringBuilder

Common attributes#

style#

erlangjavascript

pub fn style(properties: List(#(String, String))) -> Attribute(msg)

class#

erlangjavascript

pub fn class(name: String) -> Attribute(msg)

classes#

erlangjavascript

pub fn classes(names: List(#(String, Bool))) -> Attribute(msg)

id#

erlangjavascript

pub fn id(name: String) -> Attribute(msg)

Input attributes#

type_#

erlangjavascript

pub fn type_(name: String) -> Attribute(msg)

value#

erlangjavascript

pub fn value(val: Dynamic) -> Attribute(msg)

Set the value property of an element. This attribute takes a Dynamic

checked#

erlangjavascript

pub fn checked(is_checked: Bool) -> Attribute(msg)

placeholder#

erlangjavascript

pub fn placeholder(text: String) -> Attribute(msg)

selected#

erlangjavascript

pub fn selected(is_selected: Bool) -> Attribute(msg

More input attributes#

accept#

erlangjavascript

pub fn accept(types: List(String)) -> Attribute(msg)

accept_charset#

erlangjavascript

pub fn accept_charset(types: List(String)) -> Attribute(msg)

msg#

erlangjavascript

pub fn msg(uri: String) -> Attribute(msg)

autocomplete#

erlangjavascript

pub fn autocomplete(name: String) -> Attribute(msg)

autofocus#

erlangjavascript

pub fn autofocus(should_autofocus: Bool) -> Attribute(msg)

disabled#

erlangjavascript

pub fn disabled(is_disabled: Bool) -> Attribute(msg)

name#

erlangjavascript

pub fn name(name: String) -> Attribute(msg)

pattern#

erlangjavascript

pub fn pattern(regex: String) -> Attribute(msg)

readonly#

erlangjavascript

pub fn readonly(is_readonly: Bool) -> Attribute(msg)

required#

erlangjavascript

pub fn required(is_required: Bool) -> Attribute(msg)

for#

erlangjavascript

pub fn for(id: String) -> Attribute(msg)

Range attributes#

max#

erlangjavascript

pub fn max(val: String) -> Attribute(msg)

min#

erlangjavascript

pub fn min(val: String) -> Attribute(msg)

step#

erlangjavascript

pub fn step(val: String) -> Attribute(msg)

Textarea attributes#

cols#

erlangjavascript

pub fn cols(val: Int) -> Attribute(msg)

rows#

erlangjavascript

pub fn rows(val: Int) -> Attribute(msg)

wrap#

erlangjavascript

pub fn wrap(mode: String) -> Attribute(msg)

href#

erlangjavascript

pub fn href(uri: String) -> Attribute(msg)

target#

erlangjavascript

pub fn target(target: String) -> Attribute(msg)

download#

erlangjavascript

pub fn download(filename: String) -> Attribute(msg)

rel#

erlangjavascript

pub fn rel(relationship: String) -> Attribute(msg)

Embedded content#

src#

erlangjavascript

pub fn src(uri: String) -> Attribute(msg)

height#

erlangjavascript

pub fn height(val: Int) -> Attribute(msg)

width#

erlangjavascript

pub fn width(val: Int) -> Attribute(msg)

alt#

erlangjavascript

pub fn alt(text: String) -> Attribute(msg)

Audio and video attributes#

autoplay#

erlangjavascript

pub fn autoplay(should_autoplay: Bool) -> Attribute(msg)

controls#

erlangjavascript

pub fn controls(visible: Bool) -> Attribute(msg)

loop#

erlangjavascript

pub fn loop(should_loop: Bool) -> Attribute(msg)