gbr/ui/core/el

Gleam UI super element

Motivation

The lustre elements contains the generic event type that difficult to work with element in stateless mode.

So, the gbr/ui/core/el module has types and functions to work with attributes and properties without needs to trait genenric event type.

Types

Attributes of element with key

Attributes to avoid generic event type with tuple of two strings

  • part.1: Attribute name
  • part.2: Attribute value

Will be convert to lustre/attribute.attribute(name,value)

pub type UIAtt =
  dict.Dict(String, List(#(String, String)))

Attribute lustre/attribute.class with key

pub type UIClass =
  dict.Dict(String, String)

Attribute lustre/attribute.classes with key

Perfect to toggle (on, off) one or more class into element.

pub type UIClasses =
  dict.Dict(String, List(#(String, Bool)))

Element super ui.

  • id: Equals lustre/attribute.classes
  • classes: lustre/attribute.classes
  • style: lustre/attribute.style
  • att: lustre/attribute.attribute
pub opaque type UIEl

Attribute lustre/attribute.style with key

Perfect to toggle (on, off) one or more class into element.

pub type UIStyles =
  dict.Dict(String, List(#(String, String)))

Values

pub fn att(el: UIEl, att: List(#(String, String))) -> UIEl

Append list of custom attributes

  • el: Element info
  • att: Properties to set in key

Uses id like key to set custom attributes to element.

  • Equals att_key(el, el.id, value)
pub fn att_any(el: UIEl, name: String) -> Bool
pub fn att_any_key(el: UIEl, key: String, name: String) -> Bool
pub fn att_get_key(
  el: UIEl,
  key: String,
  name: String,
) -> option.Option(String)
pub fn att_key(
  el: UIEl,
  key: String,
  att: List(#(String, String)),
) -> UIEl

Append custom attributes

  • el: Element info
  • key: Key identification
  • att: Properties to set in key
pub fn attrs(el: UIEl) -> List(attribute.Attribute(a))

Convert to lustre/attributes attributes by identification.

  • in: Element info to convert

Precedence order attributes:

  • id
  • class
  • classes
  • style
  • others in att
pub fn attrs_key(
  el: UIEl,
  key: String,
) -> List(attribute.Attribute(a))
pub fn class(el: UIEl, class: String) -> UIEl

Replace class attribute element

Uses id like key to set class attribute

  • Equals class_key(el, el.id, value)
pub fn class_key(el: UIEl, key: String, class: String) -> UIEl
pub fn classes(el: UIEl, classes: List(#(String, Bool))) -> UIEl

Append classes attribute element

Uses id like key to set classes attribute

  • Equals classes_key(el, el.id, value)
pub fn classes_key(
  el: UIEl,
  key: String,
  classes: List(#(String, Bool)),
) -> UIEl

Append classes attribute element

  • el: Element info
  • key: Key identification
  • classes: Properties lustre.attribute.classes
pub fn get_classes(el: UIEl, name: String) -> option.Option(Bool)
pub fn get_classes_key(
  el: UIEl,
  key: String,
  name: String,
) -> option.Option(Bool)
pub fn get_id(el: UIEl) -> String
pub fn id(el: UIEl, id: String) -> UIEl

Replace id element

  • el: Element info
  • id: lustre.attribute.id
pub fn new(id: String) -> UIEl

New super element with initial class styled

  • id: lustre/attribute.id

Create dictonary and insert item with id element to represent default custom attributes, classes, styles, etc of element.

pub fn style(el: UIEl, styles: List(#(String, String))) -> UIEl

Replace style attribute element

Uses id like key to set style attribute

  • Equals style_key(el, el.id, value)
pub fn style_key(
  el: UIEl,
  key: String,
  styles: List(#(String, String)),
) -> UIEl

Append style attribute element

  • el: Element info
  • key: Key identification
  • styles: Properties lustre.attribute.style
Search Document