PetalComponents.Helpers (petal_components v3.2.0)

Copy Markdown View Source

For any helper functions used across multiple components. Ideally we keep this empty - components should be copy-pastable.

Summary

Functions

Composes two Phoenix.LiveView.JS structs by concatenating their operations. User JS operations execute first, followed by component JS operations.

Generates a unique HTML ID based on the given string or iodata.

Functions

compose_js(user_js, component_js)

Composes two Phoenix.LiveView.JS structs by concatenating their operations. User JS operations execute first, followed by component JS operations.

uniq_id(input, prefix \\ "c")

Generates a unique HTML ID based on the given string or iodata.

Parameters

  • input: The input string or iodata (e.g., heading or label)
  • prefix: An optional prefix for the ID (default: "c")

Examples

iex> PetalComponents.Helpers.uniq_id("My Heading")
"c-my-heading-1234"

iex> PetalComponents.Helpers.uniq_id(["My ", {:safe, "<a>Link</a>"}, " Label"], "custom")
"custom-my-link-label-5678"