defmodule ClaperWeb.Component.TextInput do @moduledoc """ DaisyUI text input field for Claper forms. Wraps the daisyUI [`input`](https://daisyui.com/components/input/) component (pill-shaped and `!font-display` via `assets/css/app.css`) together with a bold field label and inline validation errors. The component is form-aware: pass a `Phoenix.HTML.Form` and the field `key` and it derives the name, id, value and errors — including for nested forms built with `inputs_for/3`. ## Sizes - `:sm` - 40px height - `:md` - 48px height (default) - `:lg` - 56px height ## Examples <.text_field form={f} key={:title} label={gettext("Poll's title")} required /> <.text_field form={f} key={:email} type="email" placeholder="you@example.com" /> <.text_field form={i} key={:content} label={gettext("Choice")} required> <:trailing> <.icon_button style={:ghost} shape={:circle} size={:sm}>… """ use ClaperWeb, :view_component attr :form, Phoenix.HTML.Form, required: true attr :key, :atom, required: true attr :type, :string, default: "text", values: ~w(text email url tel search password number) attr :label, :string, default: nil attr :placeholder, :string, default: nil attr :required, :boolean, default: false attr :autofocus, :boolean, default: false attr :autocomplete, :string, default: nil attr :size, :atom, default: :md, values: [:sm, :md, :lg] attr :minlength, :any, default: nil attr :maxlength, :any, default: nil attr :class, :string, default: nil attr :rest, :global, include: ~w(phx-debounce phx-blur inputmode pattern step readonly disabled) slot :trailing, doc: "content rendered to the right of the input, e.g. a remove button" def text_field(assigns) do assigns = assign_new(assigns, :errors, fn -> error_tag(assigns.form, assigns.key) end) ~H"""
{render_slot(@trailing)}

{@errors}

""" end defp size_class(:sm), do: "h-10" defp size_class(:md), do: "h-12" defp size_class(:lg), do: "h-14" end