View Source PetalComponents.Helpers (petal_components v2.7.1)

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

Summary

Functions

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

Functions

Link to this function

uniq_id(input, prefix \\ "c")

View Source

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"