View Source PetalComponents.Helpers (petal_components v2.0.4)

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

Summary

Functions

Builds a class string from a given input list by joining them together

Generates a unique HTML ID based on the given string.

Functions

Link to this function

build_class(list, joiner \\ " ")

View Source
This function is deprecated. Phoenix handles lists of strings for classes now. No need for this..

Builds a class string from a given input list by joining them together

This code was taken from Elixirs Enum.join/2 function and optimized for building class name (e.g removing empty strings and joining with " " by default)

Link to this function

uniq_id(string, prefix \\ "c")

View Source

Generates a unique HTML ID based on the given string.

Parameters

  • string: The input string (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 Label", "custom")
"custom-my-label-5678"