Module Vz_doc.Input

User input.

This module provides simple user interface elements to input values from the user.

They are meant to be rendered in the document via Doc.input, but you also use them via Input.el.

TODO.

Inputs

type t

The type for inputs.

type content = [
  1. | `Txt of string
    (*

    Static text.

    *)
  2. | `Els of Brr.El.t list Note.signal
    (*

    Arbitrary dynamic content.

    *)
]

The type for content.

Triggers

val trigger : ?label:content -> ?enabled:bool Note.signal -> 'a -> content -> 'a Note.event * t

trigger ~label ~enabled o name is (e, i) with e an event, i an input button making o occur on e when triggered and:

  • name, the content rendered on the button.
  • enabled, indicates if the input button can be actuated, defaults to S.Bool.true'.
  • label, a label the input, if any.
val triggers : ?label:content -> ?enabled:bool Note.signal -> init:'a -> (('a -> 'a) * content) list -> 'a Note.signal * t

triggers ~label ~enabled ~init triggers is (s, i) with s a signal starting with init, i a list of input buttons changing s when triggered and:

  • triggers, for each button an accumulation function called when the button is triggered and the content rendered on it.
  • enabled, indicates if the input button can be actuated, defaults to S.Bool.true'.
  • label, a label for the input, if any.

Booleans

val bool : ?label:content -> ?enabled:bool Note.signal -> init:bool -> content -> bool Note.signal * t

bool ~label ~enabled ~init name is (s, i) with s a bool signal starting with init, i an input checkbox changing s and:

  • name, the content rendered on the right of the checkbox.
  • enabled, indicates whether the input can be actuated, defaults to S.Bool.true'.
  • label, a label for the input, if any.

Numbers

type number_affordance = [
  1. | `Slider
    (*

    Slider only.

    *)
  2. | `Text_and_slider
    (*

    Text field and slider.

    *)
  3. | `Text
    (*

    Text field only.

    *)
]

The type for specifying number input affordances.

val int : ?label:content -> ?enabled:bool Note.signal -> ?affordance:number_affordance -> ?min:int Note.signal -> ?max:int Note.signal -> ?step:int Note.signal -> int -> int Note.signal * t

int ~label ~enabled ~affordance ~min ~max ~step init is (s, i) with s an int signal starting with init, i an input changing s and:

  • min the minimal admissible value, defaults to S.const 0
  • max the maximal admissible value, defaults to S.const 100
  • step the slider step increment, if unspecified the slider is continuously updated.
  • affordance indicates which kind of inputs are available for specifying the number. By default this is `Text_and_slider, unless the initial value of min or max is respectively Int.min_int or Int.max_int.
  • enabled, indicates whether the input can be actuated, defaults to S.Bool.true'.
  • label, a label for the input, if any.
val float : ?label:content -> ?enabled:bool Note.signal -> ?affordance:number_affordance -> ?min:float Note.signal -> ?max:float Note.signal -> ?step:float Note.signal -> float -> float Note.signal * t

float ~label ~enabled ~affordance ~min ~max ~step init is (s, i) a float signal starting with init, i an input changing s and:

  • min the minimal admissible value, defaults to S.const 0.
  • max the maximal admissible value, defaults to S.const 1.
  • step the slider step increment, if unspecified the slider is continuously updated.
  • affordance indicates which kind of inputs are used for specifying the number. By default this is `Text_and_slider, unless the initial value of max or min is not Float.is_finite.
  • enabled, indicates whether the input can be actuated, defaults to S.Bool.true'.
  • label, a label for the input, if any.

Enumerations

type enum_affordance = [
  1. | `Buttons
    (*

    Checkboxes or radio buttons

    *)
  2. | `Menu
    (*

    Menu or cells.

    *)
]

The type for specifying value enumeration affordances.

val one_of : ?label:content -> ?enabled:bool Note.signal -> ?affordance:enum_affordance -> ?eq:('a -> 'a -> bool) -> 'a list -> init:'a -> ('a -> content) -> 'a Note.signal * t

one_of ~label ~enabled ~affordance ~eq enum ~init names is (s, i) with s a signal starting with init, i an input changing s to one of the values of enum and:

  • names e is the content rendered for an element e of enum.
  • eq is a comparison function for elements of the enumeration, defaults to Stdlib.(=).
  • affordance indicates which kind of inputs are used for specifying the value. `Button uses radio boxes and is the default if enum has up to five elements. `Menu uses a drop down menu and is the default if enum has more than five elements.
  • enabled, indicates whether the input can be actuated, defaults to S.Bool.true'.
  • label, a label for the input, if any.
val list : ?label:content -> ?enabled:bool Note.signal -> ?affordance:enum_affordance -> ?eq:('a -> 'a -> bool) -> 'a list -> init:'a list -> ('a -> content) -> 'a list Note.signal * t

list ~label ~enabled enum ~init name is (s, i) with s a signal starting with init, i an input changing s to a list of values from enum and:

  • names e is the content rendered for an element e of enum.
  • eq is a comparison function for values of the enumeration, Stdlib.(=).
  • affordance indicates which kind of inputs are used for specifying the value. `Button uses check boxes and is the default if enum has up to five elements. `Menu uses selectable cells and is the default if enum has more than five elements
  • enabled, indicates whether the input can be actuated, defaults to S.Bool.true'.
  • label, a label for the input, if any.

Files

type file_type = string

The type for specifying file types. This is either:

  • A file extension starting with a '.'.
  • A valid MIME type.
  • "audio/*" for any audio file.
  • "image/*" for any image file.
  • "video/*" for any video file.
val file : ?label:content -> ?enabled:bool Note.signal -> ?accept:file_type list -> content -> Brr.File.t Note.event * t

file ~label ~enabled ~accept name is (e, i) with e an event which occurs when a file is selected, i an input and:

  • name, the content rendered on the button.
  • accept, the list of accepted file types, any if unspecified.
  • enabled, indicates whether the input can be actuated, defaults to S.Bool.true'.
  • label, a label for the input, if any.
type files_select = [
  1. | `Files
    (*

    By selecting multiple files.

    *)
  2. | `Dir
    (*

    By selecting a single directory.

    *)
  3. | `Dirs
    (*

    By selecting multiple directories.

    *)
]

The type for specifying how multiple files should be selected.

val files : ?label:content -> ?enabled:bool Note.signal -> ?accept:file_type list -> select:files_select -> content -> Brr.File.t list Note.event * t

files ~label ~enabled ~accept ~select name is (e, i) with e an event which occurs when files are selected, i an input and:

  • name, the content rendered on the button.
  • select, the way multiple files are selected.
  • accept a list of accepted file types, any if unspecified. Warning this seems ignored by browsers for directory selection.
  • enabled, indicates whether the input can be actuated, defaults to S.Bool.true'.
  • label, a label for the input, if any.

Low-level interface

val make : ?label:content -> Brr.El.t list -> t

make ?label els wraps els and a possible label to an input div.

val el : t -> Brr.El.t

el i is the element for input i. In general you should rather use Doc.input. These elements are classified with vz_class.

val vz_class : Jstr.t

vz_class is Jstr.v "vz-input". All inputs are classified with this.