package bonsai

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
  • alert private_bonsai_view_library This library is private, for use by Bonsai developers in [lib/bonsai/web_ui/view] and [lib/bonsai/web_ui/form]. If that doesn't apply to you, then you should use the public [Bonsai_web_ui_form] library, which re-exports this functionality as part of its [View] module.
type editable = [
  1. | `Yes_always
  2. | `Currently_yes
  3. | `Currently_no
]
type button_location = [
  1. | `Before
  2. | `After
]
type submission_options = {
  1. on_submit : unit Ui_effect.t option;
  2. handle_enter : bool;
  3. button_text : string option;
  4. button_attr : Virtual_dom.Vdom.Attr.t;
  5. button_location : button_location;
}
type context = {
  1. tooltip : Virtual_dom.Vdom.Node.t option;
  2. error : Core.Error.t option;
  3. label : Virtual_dom.Vdom.Node.t option;
}
val sexp_of_context : context -> Sexplib0.Sexp.t
type append_item =
  1. | Append_info of {
    1. append : unit Virtual_dom.Vdom.Effect.t;
    2. text : string option;
    }
  2. | Append_view of Virtual_dom.Vdom.Node.t
val sexp_of_append_item : append_item -> Sexplib0.Sexp.t
type remove_item =
  1. | Remove_info of {
    1. remove : unit Virtual_dom.Vdom.Effect.t;
    2. element_label : (delete_button:Virtual_dom.Vdom.Node.t -> int -> Virtual_dom.Vdom.Node.t) option;
    }
  2. | Remove_view of Virtual_dom.Vdom.Node.t
val sexp_of_remove_item : remove_item -> Sexplib0.Sexp.t
type t = {
  1. context : context;
  2. view : view;
}
and view =
  1. | Empty
  2. | Collapsible of collapsible
  3. | Raw of raw
  4. | Record of field list
  5. | Variant of variant
  6. | List of list_view
  7. | Tuple of t list
  8. | Option of option_view
and raw = {
  1. id : string;
  2. raw_view : context -> editable:editable -> Virtual_dom.Vdom.Node.t;
}
and collapsible = {
  1. collapse_label : Virtual_dom.Vdom.Node.t;
  2. state : collapsed_state;
}
and collapsed_state =
  1. | Collapsed of t option
  2. | Expanded of t
and option_view = {
  1. toggle : Virtual_dom.Vdom.Node.t;
  2. status : option_status;
}
and option_status =
  1. | Currently_some of t
  2. | Currently_none of t option
and list_view = {
  1. list_items : list_item list;
  2. append_item : append_item;
  3. legacy_button_position : [ `Inline | `Indented ];
}
and list_item = {
  1. item_view : t;
  2. remove_item : remove_item;
}
and variant = {
  1. clause_selector : Virtual_dom.Vdom.Node.t;
  2. selected_clause : clause option;
}
and clause = {
  1. clause_name : string;
  2. clause_view : t;
}
and field = {
  1. field_name : string;
  2. field_view : t;
}
val sexp_of_t : t -> Sexplib0.Sexp.t
val sexp_of_view : view -> Sexplib0.Sexp.t
val sexp_of_raw : raw -> Sexplib0.Sexp.t
val sexp_of_collapsible : collapsible -> Sexplib0.Sexp.t
val sexp_of_collapsed_state : collapsed_state -> Sexplib0.Sexp.t
val sexp_of_option_view : option_view -> Sexplib0.Sexp.t
val sexp_of_option_status : option_status -> Sexplib0.Sexp.t
val sexp_of_list_view : list_view -> Sexplib0.Sexp.t
val sexp_of_list_item : list_item -> Sexplib0.Sexp.t
val sexp_of_variant : variant -> Sexplib0.Sexp.t
val sexp_of_clause : clause -> Sexplib0.Sexp.t
val sexp_of_field : field -> Sexplib0.Sexp.t
val of_vdom : id:string -> Virtual_dom.Vdom.Node.t -> t

of_vdom creates a Form's view from a raw Vdom.Node.t. id is used to disambiguate different input fields during Vdom diffing and patching, as well as linking a label to the input. That is, if you attach the supplied id to a text input, then users who click on the label will focus the textbox.

Because ids are required to be unique, you should ~always use Bonsai.path_id to generate the id that you pass.

val of_vdom' : id:string -> (context -> editable:editable -> Virtual_dom.Vdom.Node.t) -> t

of_vdom' is like of_vdom, but allows access to some extra metadata that is stored in the form's view.

val empty : t

An empty form view.

val tuple : t list -> t

tuple combines a list of t into a single one.

val record : field list -> t

record combines a list of fields (field names and their corresponding views) into a view representing a record with those fields.

val variant : clause_selector:Virtual_dom.Vdom.Node.t -> selected_clause:clause option -> t

variant takes a selector for selecting which variant case, as well as an optional selected_clause which contains the name of the currently selected clause and the t representing that clause's arguments.

val option : toggle:Virtual_dom.Vdom.Node.t -> status:option_status -> t

option takes a toggle for switching between None and Some _, as well as a status for the form. status can be:

  • Currently_some view if toggle is set to Some _ and view represents the form for the type in the option.
  • Currently_none None if the toggle is set to None and we shouldn't show any view for the None case
  • Currently_none (Some view) if the toggle is set to None and we want to display view when the toggle is set to None (e.g. displaying a greyed out textbox)
val collapsible : label:Virtual_dom.Vdom.Node.t -> state:collapsed_state -> t

collapsible represents a collapsible subform. The supplied label can be used to toggle open/closed the collapsible t.

collapsible_state can be:

  • Collapsed None if the view is collapsed and we shouldn't render any subform
  • Collapsed (Some view) if the view is collapsed but we want to render a subform in this case (e.g. displaying ... in a code editor when folded)
  • Expanded view if the view is expanded and view is the subform to show
val list_item : view:t -> remove_item:remove_item -> list_item

list_item represents a single form in an extendable list.

remove_item can either be:

  • Remove_info { remove; element_label } in which case the rendering function will decide how to render a remove button for this item with remove being scheduled on click and element_label being called to generate the label for this element.
  • Remove_view view in which case view will be used as the remove button
val list : append_item:append_item -> legacy_button_position:[ `Inline | `Indented ] -> list_item list -> t

list represents a form for an extendable list.

append_item can either be:

  • Append_info { append; text } in which case the rendering function will decide how to render an append button with append being scheduled on click and text being the text for the button
  • Append_view view in which case view will be used as the append button
val suggest_error : Core.Error.t -> t -> t
val suggest_label' : Virtual_dom.Vdom.Node.t -> t -> t
val suggest_label : string -> t -> t
val set_label : Virtual_dom.Vdom.Node.t -> t -> t
val set_tooltip : Virtual_dom.Vdom.Node.t -> t -> t
val with_fieldset : currently_editable:bool -> Virtual_dom.Vdom.Node.t -> Virtual_dom.Vdom.Node.t
OCaml

Innovation. Community. Security.