TIL you can provide attribute examples and allowed values to your Phoenix Components
January 16, 2024
1 min read
Elixir
Phoenix LiveView
When defining your attr
you have the following options (among others):
:examples
- a non-exhaustive list of values accepted by the attribute, used for documentation purposes.:values
- an exhaustive list of values accepted by the attributes. If a caller passes a literal not contained in this list, a compile warning is issued.
attr :attr1, :atom, values: [:foo, :bar, :baz]
attr :attr2, :atom, examples: [:foo, :bar, :baz]
attr :attr3, :list, values: [[60, 40]]
attr :attr4, :list, examples: [[60, 40]]
def fun_attr_values_examples(assigns), do: ~H[]