View Source SaladUI.JS (SaladUI v1.0.0-beta.3)

Helper functions for integrating SaladUI with Phoenix LiveView using JavaScript commands.

Summary

Functions

Dispatch a command to a SaladUI component using JavaScript. This is useful for programmatically controlling components from client-side code.

Functions

Link to this function

dispatch_command(js \\ %Phoenix.LiveView.JS{}, command_name, opts \\ [])

View Source

Dispatch a command to a SaladUI component using JavaScript. This is useful for programmatically controlling components from client-side code.

Parameters

  • js: The JavaScript object.
  • command_name: The name of the command to dispatch.
  • opts: Options for the command, including :detail for additional parameters.

How it works

This function use JS.dispatch to send a command to the component similar to send_command/4.

Each component listens for the salad_ui:command event and executes the corresponding command similar to the way it handle send_command/4 from server side .

Example

<button
  phx-click={%JS{} |> SaladUI.JS.dispatch_command("open", to: "#dialog")}> Click me </button>