defmodule Liliform.Input do use Liliform.Component import Liliform.Label @doc """ Renders an input with label and error messages. A `Phoenix.HTML.FormField` may be passed as argument, which is used to retrieve the input name, id, and values. Otherwise all attributes may be passed explicitly. ## Types This function accepts all HTML input types, considering that: * You may also set `type="select"` to render a ` <%= @label %> <.error :for={msg <- @errors}><%= msg %> """ end def input(%{type: "select"} = assigns) do ~H"""
<.label for={@id}><%= @label %> <.error :for={msg <- @errors}><%= msg %>
""" end def input(%{type: "textarea"} = assigns) do ~H"""
<.label for={@id}><%= @label %> <.error :for={msg <- @errors}><%= msg %>
""" end # All other inputs text, datetime-local, url, password, etc. are handled here... def input(assigns) do ~H"""
<.label for={@id}><%= @label %> <.error :for={msg <- @errors}><%= msg %>
""" end @doc """ Generates a generic error message. """ slot :inner_block, required: true def error(assigns) do ~H"""

<%= render_slot(@inner_block) %>

""" end end