gadgetobrr/lib/slippery_slidy.mli

77 lines
2.2 KiB
OCaml
Raw Normal View History

2024-04-11 15:46:46 +02:00
open Brr
2024-04-16 02:15:55 +02:00
(** type for
{{:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist}
[datalist]} *)
2024-04-11 15:46:46 +02:00
type datalist =
{ datalist_id : string
; datalist_el : El.t
}
2024-04-16 02:15:55 +02:00
(* TODO can I hide this type completly? *)
type widget
type _ t =
| Text : widget -> string t
| Slider : widget -> float t
| Color : widget -> string t
2024-04-11 15:46:46 +02:00
2024-04-16 02:15:55 +02:00
(** type for the step parameter of [mk_slider] Any is for continuous slider *)
2024-04-11 15:46:46 +02:00
type step_kind =
| Any
| Step_value of float
2024-04-16 02:15:55 +02:00
(** [id t] the id of the input element of the widget *)
val id : 'a t -> string
(** [el t] the container element of the widget *)
val el : 'a t -> El.t
2024-04-11 15:46:46 +02:00
2024-04-16 02:15:55 +02:00
(** [input_el t] the input element; with id [id t]; contained in the container
element [el t] *)
val input_el : 'a t -> El.t
(* TODO better type constraint on this?
pitfall:
making it a float list, and using Jstr.of_float
gave me bugged float, it needs 0 at the end or smthing *)
2024-04-11 15:46:46 +02:00
val mk_datalist : Jstr.t list -> string -> datalist
2024-04-16 02:15:55 +02:00
(** make a div of class "brridget-container brridget-text-container" containing
a text input of class "brridget-text" with id [id]
2024-04-11 15:46:46 +02:00
don't forget to add your slider and datalist to your document *)
2024-04-16 02:15:55 +02:00
val mk_text :
min:int option
-> max:int option
-> size:int option
-> datalist_id:string option
-> value:string
-> id:string
-> label:string
-> string t
(** make a div of class "brridget-container brridget-slider-container"
containing a range input of class "brridget-slider" with id [id] *)
2024-04-11 15:46:46 +02:00
val mk_slider :
min:float
-> max:float
-> step:step_kind
-> value:float
-> id:string
-> label:string
-> datalist_id:string option
2024-04-16 02:15:55 +02:00
-> float t
(** make a div of class "brridget-container brridget-color-container" containing
a color input of class "brridget-color" with id [id] *)
val mk_color : value:string -> id:string -> label:string -> string t
2024-04-11 15:46:46 +02:00
2024-04-16 02:15:55 +02:00
(** setup listener on input *)
val add_input_listener : 'a t -> ('a -> unit) -> unit
2024-04-12 10:46:11 +02:00
2024-04-16 02:15:55 +02:00
(** setup listener to drag and move slider with mouse. Works by listening to
mousedown/mouseup/mousemove events and changing inline css style. use event
stop_propagation + css to not highlight the page while dragging *)
val mk_dragable : 'a t -> unit