lustre/ui

Types

pub type Size {
  Size(base: Value, ratio: Float)
}

Constructors

  • Size(base: Value, ratio: Float)

A theme is a collection of colour scales that define the look and feel of your application. You can consider the “primary” scale as your brand or accent colour. The “greyscale” scale can be used when you want suitable shading without any particular colour or meaning. The “error”, “warning”, “success”, and “info” scales are semantic colours that can be used to communicate meaning to the user.

pub type Theme {
  Theme(
    space: Size,
    text: Size,
    radius: Value,
    primary: Scale,
    greyscale: Scale,
    error: Scale,
    warning: Scale,
    success: Scale,
    info: Scale,
  )
}

Constructors

  • Theme(
      space: Size,
      text: Size,
      radius: Value,
      primary: Scale,
      greyscale: Scale,
      error: Scale,
      warning: Scale,
      success: Scale,
      info: Scale,
    )
pub type Value {
  Rem(Float)
  Px(Float)
  Var(String)
}

Constructors

  • Rem(Float)
  • Px(Float)
  • Var(String)

This type enumerates the different colour scales that are available in a theme. It is mostly used to set the variant of an element using the variant attribute, but you could also use it in your own custom elements.

pub type Variant {
  Primary
  Greyscale
  Error
  Warning
  Success
  Info
}

Constructors

  • Primary
  • Greyscale
  • Error
  • Warning
  • Success
  • Info

Constants

pub const alert: fn(List(Attribute(a)), List(Element(a))) ->
  Element(a) = alert.alert
pub const aside: fn(List(Attribute(a)), Element(a), Element(a)) ->
  Element(a) = aside.aside
pub const box: fn(List(Attribute(a)), List(Element(a))) ->
  Element(a) = box.box
pub const breadcrumbs: fn(
  List(Attribute(a)),
  Element(a),
  List(Element(a)),
) -> Element(a) = breadcrumbs.breadcrumbs
pub const button: fn(List(Attribute(a)), List(Element(a))) ->
  Element(a) = button.button
pub const centre: fn(List(Attribute(a)), Element(a)) ->
  Element(a) = centre.centre
pub const cluster: fn(List(Attribute(a)), List(Element(a))) ->
  Element(a) = cluster.cluster
pub const field: fn(
  List(Attribute(a)),
  List(Element(a)),
  Element(a),
  List(Element(a)),
) -> Element(a) = field.field
pub const group: fn(List(Attribute(a)), List(Element(a))) ->
  Element(a) = group.group
pub const input: fn(List(Attribute(a))) -> Element(a) = input.input
pub const prose: fn(List(Attribute(a)), List(Element(a))) ->
  Element(a) = prose.prose
pub const sequence: fn(List(Attribute(a)), List(Element(a))) ->
  Element(a) = sequence.sequence
pub const stack: fn(List(Attribute(a)), List(Element(a))) ->
  Element(a) = stack.stack
pub const tag: fn(List(Attribute(a)), List(Element(a))) ->
  Element(a) = tag.tag

Functions

pub fn encode_theme(theme: Theme) -> Json
pub fn theme_decoder(
  json: Dynamic,
) -> Result(Theme, List(DecodeError))
pub fn variant(variant: Variant) -> Attribute(a)

Use this attribute to set the colour scale of an element. Unless a child element sets its own variant, it will inherit the variant of its parent. You could, for example, set the variant on some custom alert element to be Warning. Then, any buttons or icons inside the alert will inherit the warning palette and be coloured accordingly.

Search Document