sprocket/html/events

Types

pub type KeyEvent {
  KeyEvent(
    key: String,
    code: String,
    ctrl_key: Bool,
    shift_key: Bool,
    alt_key: Bool,
    meta_key: Bool,
  )
}

Constructors

  • KeyEvent(
      key: String,
      code: String,
      ctrl_key: Bool,
      shift_key: Bool,
      alt_key: Bool,
      meta_key: Bool,
    )
pub type MouseEvent {
  MouseEvent(
    x: Int,
    y: Int,
    ctrl_key: Bool,
    shift_key: Bool,
    alt_key: Bool,
    meta_key: Bool,
  )
}

Constructors

  • MouseEvent(
      x: Int,
      y: Int,
      ctrl_key: Bool,
      shift_key: Bool,
      alt_key: Bool,
      meta_key: Bool,
    )

Functions

pub fn decode_form_data(
  event: Dynamic,
) -> Result(Dict(String, String), List(DecodeError))

Decode the form data from a form submit event.

pub fn decode_key_event(
  event: Dynamic,
) -> Result(KeyEvent, List(DecodeError))
pub fn decode_keypress(
  event: Dynamic,
) -> Result(String, List(DecodeError))

Decode the key from a key press event.

pub fn decode_mouse_event(
  event: Dynamic,
) -> Result(MouseEvent, List(DecodeError))

Decode a mouse event that includes position clientX and clientY and modifier keys.

pub fn decode_target_checked(
  event: Dynamic,
) -> Result(Bool, List(DecodeError))
pub fn decode_target_value(
  event: Dynamic,
) -> Result(String, List(DecodeError))

Decode the value from an event event.target.value.

pub fn event(name: String, cb: fn(Dynamic) -> Nil) -> Attribute
pub fn event_dispatcher(
  dispatch: fn(a) -> Nil,
  cb: fn(fn(fn(Dynamic) -> a) -> fn(Dynamic) -> Nil) ->
    #(Context, Element),
) -> #(Context, Element)

Creates a helper function that allows us to directly dispatch a message from an event handler without needing to create a separate function for each event.

Example:

  use dispatch_event <- event_dispatcher(dispatch)
  ...

  button([events.on_click(dispatch_event(UserClickedButton))], [])
pub fn on_blur(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_change(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_check(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_click(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_dblclick(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_drag(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_dragend(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_dragenter(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_dragleave(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_dragover(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_dragstart(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_drop(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_focus(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_focusin(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_focusout(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_input(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_keydown(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_keyup(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_mousedown(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_mouseenter(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_mouseleave(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_mousemove(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_mouseout(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_mouseover(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_mouseup(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_scroll(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_submit(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_touchcancel(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_touchend(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_touchmove(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_touchstart(cb: fn(Dynamic) -> Nil) -> Attribute
pub fn on_wheel(cb: fn(Dynamic) -> Nil) -> Attribute
Search Document