Remove unused CoreComponents
Generated by Phoenix with initial scaffolding, now unused or replaced by FluxonUI
This commit is contained in:
@@ -16,7 +16,6 @@ defmodule MusicLibraryWeb.CoreComponents do
|
|||||||
"""
|
"""
|
||||||
use Phoenix.Component
|
use Phoenix.Component
|
||||||
|
|
||||||
alias Phoenix.HTML.Form
|
|
||||||
alias Phoenix.LiveView.JS
|
alias Phoenix.LiveView.JS
|
||||||
use Gettext, backend: MusicLibraryWeb.Gettext
|
use Gettext, backend: MusicLibraryWeb.Gettext
|
||||||
|
|
||||||
@@ -249,179 +248,6 @@ defmodule MusicLibraryWeb.CoreComponents do
|
|||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
@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 `<select>` tag
|
|
||||||
|
|
||||||
* `type="checkbox"` is used exclusively to render boolean values
|
|
||||||
|
|
||||||
* For live file uploads, see `Phoenix.Component.live_file_input/1`
|
|
||||||
|
|
||||||
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
|
|
||||||
for more information. Unsupported types, such as hidden and radio,
|
|
||||||
are best written directly in your templates.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
<.input field={@form[:email]} type="email" />
|
|
||||||
<.input name="my-input" errors={["oh no!"]} />
|
|
||||||
"""
|
|
||||||
attr :id, :any, default: nil
|
|
||||||
attr :name, :any
|
|
||||||
attr :label, :string, default: nil
|
|
||||||
attr :value, :any
|
|
||||||
|
|
||||||
attr :type, :string,
|
|
||||||
default: "text",
|
|
||||||
values: ~w(checkbox color date datetime-local email file month number password
|
|
||||||
range search select tel text textarea time url week)
|
|
||||||
|
|
||||||
attr :field, Phoenix.HTML.FormField,
|
|
||||||
doc: "a form field struct retrieved from the form, for example: @form[:email]"
|
|
||||||
|
|
||||||
attr :errors, :list, default: []
|
|
||||||
attr :checked, :boolean, doc: "the checked flag for checkbox inputs"
|
|
||||||
attr :prompt, :string, default: nil, doc: "the prompt for select inputs"
|
|
||||||
attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"
|
|
||||||
attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs"
|
|
||||||
attr :input_class, :string, default: nil
|
|
||||||
|
|
||||||
attr :rest, :global,
|
|
||||||
include:
|
|
||||||
~w(accept autocomplete autocorrect capture cols disabled form list max maxlength min minlength
|
|
||||||
multiple pattern placeholder readonly required rows size step)
|
|
||||||
|
|
||||||
def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
|
|
||||||
errors = if Phoenix.Component.used_input?(field), do: field.errors, else: []
|
|
||||||
|
|
||||||
assigns
|
|
||||||
|> assign(field: nil, id: assigns.id || field.id)
|
|
||||||
|> assign(:errors, Enum.map(errors, &translate_error(&1)))
|
|
||||||
|> assign_new(:name, fn -> if assigns.multiple, do: field.name <> "[]", else: field.name end)
|
|
||||||
|> assign_new(:value, fn -> field.value end)
|
|
||||||
|> input()
|
|
||||||
end
|
|
||||||
|
|
||||||
def input(%{type: "checkbox"} = assigns) do
|
|
||||||
assigns =
|
|
||||||
assign_new(assigns, :checked, fn ->
|
|
||||||
Form.normalize_value("checkbox", assigns[:value])
|
|
||||||
end)
|
|
||||||
|
|
||||||
~H"""
|
|
||||||
<div>
|
|
||||||
<label class="flex items-center gap-4 text-xs sm:text-sm leading-6 text-zinc-600">
|
|
||||||
<input type="hidden" name={@name} value="false" disabled={@rest[:disabled]} />
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
id={@id}
|
|
||||||
name={@name}
|
|
||||||
value="true"
|
|
||||||
checked={@checked}
|
|
||||||
class="rounded-sm border-zinc-300 text-zinc-900 focus:ring-0"
|
|
||||||
{@rest}
|
|
||||||
/>
|
|
||||||
{@label}
|
|
||||||
</label>
|
|
||||||
<.error :for={msg <- @errors}>{msg}</.error>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
def input(%{type: "select"} = assigns) do
|
|
||||||
~H"""
|
|
||||||
<div>
|
|
||||||
<.label for={@id}>{@label}</.label>
|
|
||||||
<select
|
|
||||||
id={@id}
|
|
||||||
name={@name}
|
|
||||||
class={[
|
|
||||||
"mt-2 block w-full rounded-md",
|
|
||||||
"border-0 border-zinc-300",
|
|
||||||
"bg-white dark:bg-zinc-800",
|
|
||||||
"ring-1 ring-inset focus:z-10 focus:ring-2 focus:ring-inset",
|
|
||||||
"focus:border-zinc-400 focus:ring-zinc-400 dark:focus:ring-zinc-300 focus:ring-0",
|
|
||||||
"text-xs sm:text-sm",
|
|
||||||
"text-zinc-900 dark:text-zinc-200",
|
|
||||||
"ring-zinc-200 dark:ring-zinc-400",
|
|
||||||
"placeholder:text-zinc-400 dark:placeholder:text-zinc-400"
|
|
||||||
]}
|
|
||||||
multiple={@multiple}
|
|
||||||
{@rest}
|
|
||||||
>
|
|
||||||
<option :if={@prompt} value="">{@prompt}</option>
|
|
||||||
{Form.options_for_select(@options, @value)}
|
|
||||||
</select>
|
|
||||||
<.error :for={msg <- @errors}>{msg}</.error>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
def input(%{type: "textarea"} = assigns) do
|
|
||||||
~H"""
|
|
||||||
<div>
|
|
||||||
<.label for={@id}>{@label}</.label>
|
|
||||||
<textarea
|
|
||||||
id={@id}
|
|
||||||
name={@name}
|
|
||||||
class={[
|
|
||||||
"mt-2 block w-full rounded-lg text-zinc-900 focus:ring-0 text-xs sm:text-sm sm:leading-6 min-h-[6rem]",
|
|
||||||
@errors == [] && "border-zinc-300 focus:border-zinc-400",
|
|
||||||
@errors != [] && "border-rose-400 focus:border-rose-400"
|
|
||||||
]}
|
|
||||||
{@rest}
|
|
||||||
><%= Form.normalize_value("textarea", @value) %></textarea>
|
|
||||||
<.error :for={msg <- @errors}>{msg}</.error>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
# All other inputs text, datetime-local, url, password, etc. are handled here...
|
|
||||||
def input(assigns) do
|
|
||||||
~H"""
|
|
||||||
<div>
|
|
||||||
<.label for={@id}>{@label}</.label>
|
|
||||||
<input
|
|
||||||
type={@type}
|
|
||||||
name={@name}
|
|
||||||
id={@id}
|
|
||||||
value={Form.normalize_value(@type, @value)}
|
|
||||||
class={[
|
|
||||||
"mt-2 block w-full rounded-md",
|
|
||||||
"border-0 border-zinc-300",
|
|
||||||
"bg-white dark:bg-zinc-800",
|
|
||||||
"ring-1 ring-inset focus:z-10 focus:ring-2 focus:ring-inset",
|
|
||||||
"focus:border-zinc-400 focus:ring-zinc-400 dark:focus:ring-zinc-300 focus:ring-0",
|
|
||||||
"text-xs sm:text-sm",
|
|
||||||
"text-zinc-900 dark:text-zinc-200",
|
|
||||||
"ring-zinc-200 dark:ring-zinc-400",
|
|
||||||
"placeholder:text-zinc-400 dark:placeholder:text-zinc-400",
|
|
||||||
@errors == [] && "border-zinc-300 focus:border-zinc-400",
|
|
||||||
@errors != [] && "border-rose-400 focus:border-rose-400",
|
|
||||||
@input_class
|
|
||||||
]}
|
|
||||||
{@rest}
|
|
||||||
/>
|
|
||||||
<.error :for={msg <- @errors}>{msg}</.error>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Renders a label.
|
|
||||||
"""
|
|
||||||
attr :for, :string, default: nil
|
|
||||||
slot :inner_block, required: true
|
|
||||||
|
|
||||||
def label(assigns) do
|
def label(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<label for={@for} class="block text-sm font-semibold leading-6 text-zinc-800 dark:text-zinc-400">
|
<label for={@for} class="block text-sm font-semibold leading-6 text-zinc-800 dark:text-zinc-400">
|
||||||
@@ -444,34 +270,6 @@ defmodule MusicLibraryWeb.CoreComponents do
|
|||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
|
||||||
Renders a header with title.
|
|
||||||
"""
|
|
||||||
attr :class, :string, default: nil
|
|
||||||
|
|
||||||
slot :inner_block, required: true
|
|
||||||
slot :subtitle
|
|
||||||
slot :actions
|
|
||||||
|
|
||||||
def header(assigns) do
|
|
||||||
~H"""
|
|
||||||
<header class={[
|
|
||||||
@actions != [] && "sm:flex sm:items-center sm:justify-between sm:gap-6 mb-2",
|
|
||||||
@class
|
|
||||||
]}>
|
|
||||||
<div class="font-semibold">
|
|
||||||
<h1 class="text-sm md:text-base lg:text-2xl text-zinc-900">
|
|
||||||
{render_slot(@inner_block)}
|
|
||||||
</h1>
|
|
||||||
<h2 :if={@subtitle != []} class="mt-2 text-sm md:text-base text-zinc-600">
|
|
||||||
{render_slot(@subtitle)}
|
|
||||||
</h2>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-center gap-2 sm:flex-none mt-4 mb-4">{render_slot(@actions)}</div>
|
|
||||||
</header>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc ~S"""
|
@doc ~S"""
|
||||||
Renders a table with generic styling.
|
Renders a table with generic styling.
|
||||||
|
|
||||||
@@ -550,57 +348,6 @@ defmodule MusicLibraryWeb.CoreComponents do
|
|||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
|
||||||
Renders a data list.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
<.list>
|
|
||||||
<:item title="Title"><%= @post.title %></:item>
|
|
||||||
<:item title="Views"><%= @post.views %></:item>
|
|
||||||
</.list>
|
|
||||||
"""
|
|
||||||
slot :item, required: true do
|
|
||||||
attr :title, :string, required: true
|
|
||||||
end
|
|
||||||
|
|
||||||
def list(assigns) do
|
|
||||||
~H"""
|
|
||||||
<div class="mt-14">
|
|
||||||
<dl class="-my-4 divide-y divide-zinc-100">
|
|
||||||
<div :for={item <- @item} class="flex gap-4 py-4 text-sm leading-6 sm:gap-8">
|
|
||||||
<dt class="w-1/4 flex-none text-zinc-500">{item.title}</dt>
|
|
||||||
<dd class="text-zinc-700">{render_slot(item)}</dd>
|
|
||||||
</div>
|
|
||||||
</dl>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
|
||||||
Renders a back navigation link.
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
<.back navigate={~p"/posts"}>Back to posts</.back>
|
|
||||||
"""
|
|
||||||
attr :navigate, :any, required: true
|
|
||||||
slot :inner_block, required: true
|
|
||||||
|
|
||||||
def back(assigns) do
|
|
||||||
~H"""
|
|
||||||
<div class="mt-4 md:mt-8">
|
|
||||||
<.link
|
|
||||||
navigate={@navigate}
|
|
||||||
class="text-sm font-semibold leading-6 text-zinc-900 dark:text-zinc-400 hover:text-zinc-700 dark:hover:text-zinc-300"
|
|
||||||
>
|
|
||||||
<.icon name="hero-arrow-left-solid" class="h-3 w-3" />
|
|
||||||
{render_slot(@inner_block)}
|
|
||||||
</.link>
|
|
||||||
</div>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Renders a [Heroicon](https://heroicons.com).
|
Renders a [Heroicon](https://heroicons.com).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user