Module Incr_dom_interactive.Primitives
type 'a primitive= ?attrs:Incr_dom_interactive__.Import.Vdom.Attr.t list -> ?id:string -> unit -> 'a tidlets you specify a value for the "id" attribute of the DOM node. It doesn't affect the behavior of this library (unless you accidentally create two nodes with the same id), but it might be useful if you want to refer to the node elsewhere.
module Button_state : sig ... endval button : text:string -> Button_state.t primitiveval disabled_button : text:string -> unit primitiveval dropdown_exn : options:(string * 'a) list -> ?init:int -> 'a primitiveoptionsis a list of tuples (label, value).labelis what will be displayed to the user in the dropdown.valueis what will be produced by theInteractive.twhen that option is selected by the user.initis the 0-based index of the option which is initially selected. It defaults to 0.Raises when
optionsis empty orinit >= List.length options.
val dropdown_with_blank_exn : options:(string * 'a) list -> ?init:int -> 'a option primitivedropdown_with_blank_exnis a wrapper arounddropdown_exnwhich adds a blank option to the dropdown that producesNone. It is otherwise the same asdropdown_exn.If you don't provide a value for
init, the initial value for the dropdown will be the blank option which producesNone.Raises when
init >= List.length options.
val checkbox : ?init:bool -> bool primitiveval nodes : Incr_dom_interactive__.Import.Vdom.Node.t list -> unit tval message : string -> unit tval line_break : unit tval create : init:'a -> render:(inject:('a -> Incr_dom_interactive__.Import.Vdom.Event.t) -> value:'a Incr_dom_interactive__.Import.Incr.t -> Incr_dom_interactive__.Import.Vdom.Node.t list Incr_dom_interactive__.Import.Incr.t) -> 'a tcreateallows you to create your own primitives.initis the initial value of theInteractive.t.injectis how the users of your primitive tell it what to do with new values. In your event handler, you should call it and supply the new value of the primitive.You should use
valueto determine the value of your primitive. For example, if your primitive is a checkbox, you should do this:let render ~inject ~value = let open Incr.Let_syntax in let%map is_checked = value in let node = if is_checked then (* ... create a [Node.t] representing a checked checkbox ... *) else (* ... create a [Node.t] representing an unchecked checkbox ... *) in ...You should not use
initto determine the value.valuewill initially be the same asinit, but it might be different if the field is modified, then stops being rendered, then is rendered again. In this case, we want the user's input to be preserved. But if you useinitto fill in the initial value, the user's input will be discarded in this case.For an example, check the implementation of
Primitives.text.
val default_text_attrs : Incr_dom_interactive__.Import.Vdom.Attr.t listval default_text_area_attrs : Incr_dom_interactive__.Import.Vdom.Attr.t listval default_button_attrs : Incr_dom_interactive__.Import.Vdom.Attr.t listval default_dropdown_attrs : Incr_dom_interactive__.Import.Vdom.Attr.t listval bootstrap_text_attrs : Incr_dom_interactive__.Import.Vdom.Attr.t listval bootstrap_text_area_attrs : Incr_dom_interactive__.Import.Vdom.Attr.t listval bootstrap_button_attrs : Incr_dom_interactive__.Import.Vdom.Attr.t listval bootstrap_dropdown_attrs : Incr_dom_interactive__.Import.Vdom.Attr.t list