pream/vnode

Types

vnode property — either an attribute (any gleam value, serialized downstream in ffi) or an event handler. handlers are camelCased and prefixed with on_ in ffi

pub type Prop {
  Attr(key: String, value: dom.Native)
  Handler(
    event: String,
    handle: fn(event.Event(dynamic.Dynamic)) -> Nil,
  )
}

Constructors

  • Attr(key: String, value: dom.Native)

    NOTE: a prop can be any gleam value we’re swallowing the type here and handle it downstram in ffi. this is done to make the render API simple

  • Handler(
      event: String,
      handle: fn(event.Event(dynamic.Dynamic)) -> Nil,
    )

child of a vnode — one of four variants: static element, static text, reactive element, or reactive text. use the constructors below (e.g. text, element, reactive, reactive_text) to build values of this type.

pub type VChild {
  Element(VNode)
  Text(String)
  Reactive(signal.Signal(VNode))
  ReactiveText(signal.Signal(String))
}

Constructors

virtual dom node — same shape as the output of preact’s h(). built up via small composable helpers below, then handed to pream.to_preact

pub opaque type VNode

Values

pub fn a() -> VNode

Creates an <a> vnode.

pub fn alt(vnode: VNode, text: String) -> VNode

Sets the alt attribute on the vnode.

pub fn article() -> VNode

Creates an <article> vnode.

pub fn br() -> VNode

Creates a <br> vnode.

pub fn button() -> VNode

Creates a <button> vnode.

pub fn checked(vnode: VNode) -> VNode

Sets the checked attribute on the vnode to True.

pub fn child(vnode: VNode, child: VChild) -> VNode

appends a single child

pub fn children(vnode: VNode, children: List(VChild)) -> VNode

appends a list of children

pub fn class(vnode: VNode, name: String) -> VNode

Sets the class attribute on the vnode.

pub fn disabled(vnode: VNode) -> VNode

Sets the disabled attribute on the vnode to True.

pub fn div() -> VNode

Creates a <div> vnode.

pub fn element(node: VNode) -> VChild

wraps a vnode as a child element

pub fn empty() -> VNode

renders nothing — mapped to preact’s null in ffi

pub fn footer() -> VNode

Creates a <footer> vnode.

pub fn form() -> VNode

Creates a <form> vnode.

pub fn fragment() -> VNode

https://npmx.dev/package-docs/preact/v/10.29.2#function-fragment a fragment vnode — used to return multiple sibling children without a wrapper element

pub fn h1() -> VNode

Creates an <h1> vnode.

pub fn h2() -> VNode

Creates an <h2> vnode.

pub fn h3() -> VNode

Creates an <h3> vnode.

pub fn h4() -> VNode

Creates an <h4> vnode.

pub fn h5() -> VNode

Creates an <h5> vnode.

pub fn h6() -> VNode

Creates an <h6> vnode.

pub fn header() -> VNode

Creates a <header> vnode.

pub fn hr() -> VNode

Creates an <hr> vnode.

pub fn href(vnode: VNode, url: String) -> VNode

Sets the href attribute on the vnode.

pub fn id(vnode: VNode, name: String) -> VNode

Sets the id attribute on the vnode.

pub fn img() -> VNode

Creates an <img> vnode.

pub fn input() -> VNode

Creates an <input> vnode.

pub fn label() -> VNode

Creates a <label> vnode.

pub fn li() -> VNode

Creates an <li> vnode.

pub fn main() -> VNode

Creates a <main> vnode.

pub fn map_signal(
  s: signal.Signal(a),
  render: fn(a) -> VChild,
) -> VChild

maps a signal through render — each value is wrapped as a VChild inside a fragment. the result is itself a reactive VChild.

pub fn name(vnode: VNode, name: String) -> VNode

Sets the name attribute on the vnode.

pub fn nav() -> VNode

Creates a <nav> vnode.

pub fn new(tag: String) -> VNode

https://npmx.dev/package-docs/preact/v/10.29.2#function-h creates an empty vnode with the given tag and no props or children — equivalent to <tag />

pub fn ol() -> VNode

Creates an <ol> vnode.

pub fn on(
  vnode: VNode,
  event: String,
  handle: fn(event.Event(dynamic.Dynamic)) -> Nil,
) -> VNode

attaches an event handler. the event name is camelCased and prefixed with on_ in ffi (e.g. click becomes onClick)

pub fn option_tag() -> VNode

Creates an <option> vnode.

pub fn p() -> VNode

Creates a <p> vnode.

pub fn placeholder(vnode: VNode, text: String) -> VNode

Sets the placeholder attribute on the vnode.

pub fn prop(vnode: VNode, key: String, value: a) -> VNode

sets an attribute on the vnode. any gleam value is accepted — stringification/serialization is deferred to the ffi at render time

pub fn reactive(s: signal.Signal(VNode)) -> VChild

creates a reactive element child from a signal

pub fn reactive_text(s: signal.Signal(String)) -> VChild

creates a reactive text child from a signal

pub fn required(vnode: VNode) -> VNode

Sets the required attribute on the vnode to True.

pub fn role(vnode: VNode, name: String) -> VNode

Sets the role attribute on the vnode.

pub fn section() -> VNode

Creates a <section> vnode.

pub fn select() -> VNode

Creates a <select> vnode.

pub fn span() -> VNode

Creates a <span> vnode.

pub fn src(vnode: VNode, url: String) -> VNode

Sets the src attribute on the vnode.

pub fn table() -> VNode

Creates a <table> vnode.

pub fn td() -> VNode

Creates a <td> vnode.

pub fn text(content: String) -> VChild

creates a static text child

pub fn text_with(content: String, args: List(String)) -> VChild

creates a static text child with positional formatting — each {} is replaced with the next value from the list

pub fn textarea() -> VNode

Creates a <textarea> vnode.

pub fn th() -> VNode

Creates a <th> vnode.

pub fn title(vnode: VNode, text: String) -> VNode

Sets the title attribute on the vnode.

pub fn tr() -> VNode

Creates a <tr> vnode.

pub fn type_(vnode: VNode, name: String) -> VNode

Sets the type attribute on the vnode.

pub fn ul() -> VNode

Creates a <ul> vnode.

pub fn unless(condition: Bool, render: fn() -> VChild) -> VChild

renders render when condition is False, otherwise returns an empty text node

pub fn value_int(vnode: VNode, val: Int) -> VNode

Sets the value attribute on the vnode as an integer.

pub fn value_string(vnode: VNode, val: String) -> VNode

Sets the value attribute on the vnode as a string.

pub fn when(condition: Bool, render: fn() -> VChild) -> VChild

renders render when condition is True, otherwise returns an empty text node

pub fn when_signal(
  s: signal.Signal(Bool),
  render: fn() -> VChild,
) -> VChild

renders render when the signal value is True, otherwise returns an empty fragment. the result is itself a reactive VChild.

pub fn when_some(
  option: option.Option(a),
  render: fn(a) -> VChild,
) -> VChild

renders render when the option is Some, otherwise returns an empty text node

Search Document