Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions installer/templates/phx_web/components/core_components.ex.eex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ defmodule <%= @web_namespace %>.CoreComponents do
"""
attr :id, :string, doc: "the optional id of flash container"
attr :flash, :map, default: %{}, doc: "the map of flash messages to display"
attr :title, :string, default: nil
attr :kind, :atom, values: [:info, :error], doc: "used for styling and flash lookup"
attr :rest, :global, doc: "the arbitrary HTML attributes to add to the flash container"

Expand All @@ -74,10 +73,7 @@ defmodule <%= @web_namespace %>.CoreComponents do
]}>
<.icon :if={@kind == :info} name="hero-information-circle" class="size-5 shrink-0" />
<.icon :if={@kind == :error} name="hero-exclamation-circle" class="size-5 shrink-0" />
<div>
<p :if={@title} class="font-semibold">{@title}</p>
<p>{msg}</p>
</div>
<div>{msg}</div>
<div class="flex-1" />
<button type="button" class="group self-start cursor-pointer" aria-label=<%= maybe_heex_attr_gettext.("close", @gettext) %>>
<.icon name="hero-x-mark" class="size-5 opacity-40 group-hover:opacity-70" />
Expand Down Expand Up @@ -141,10 +137,6 @@ defmodule <%= @web_namespace %>.CoreComponents do

* 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 radio, are best
written directly in your templates.

## Examples

```heex
Expand Down Expand Up @@ -178,8 +170,6 @@ defmodule <%= @web_namespace %>.CoreComponents do
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 :class, :any, default: nil, doc: "the input class to use over defaults"
Expand Down Expand Up @@ -207,11 +197,6 @@ defmodule <%= @web_namespace %>.CoreComponents do
end

def input(%{type: "checkbox"} = assigns) do
assigns =
assign_new(assigns, :checked, fn ->
Phoenix.HTML.Form.normalize_value("checkbox", assigns[:value])
end)

~H"""
<div class="fieldset mb-2">
<label for={@id}>
Expand All @@ -228,7 +213,7 @@ defmodule <%= @web_namespace %>.CoreComponents do
id={@id}
name={@name}
value="true"
checked={@checked}
checked={Phoenix.HTML.Form.normalize_value("checkbox", assigns[:value])}
class={@class || "checkbox checkbox-sm"}
{@rest}
/>{@label}
Expand All @@ -251,7 +236,6 @@ defmodule <%= @web_namespace %>.CoreComponents do
multiple={@multiple}
{@rest}
>
<option :if={@prompt} value="">{@prompt}</option>
{Phoenix.HTML.Form.options_for_select(@options, @value)}
</select>
</label>
Expand Down Expand Up @@ -480,15 +464,12 @@ defmodule <%= @web_namespace %>.CoreComponents do
Translates an error message using gettext.
"""<%= if @gettext do %>
def translate_error({msg, opts}) do
# When using gettext, we typically pass the strings we want
# to translate as a static argument:
# When using gettext, we pass the strings to translate as a static arguments:
#
# # Translate the number of files with plural rules
# dngettext("errors", "1 file", "%{count} files", count)
#
# However the error messages in our forms and APIs are generated
# dynamically, so we need to translate them by calling Gettext
# with our gettext backend as first argument. Translations are
# However, error messages are generated dynamically, so we translate them
# by calling Gettext with the backend as first argument. Translations are
# available in the errors.po file (as we use the "errors" domain).
if count = opts[:count] do
Gettext.dngettext(<%= @web_namespace %>.Gettext, "errors", msg, msg, count, opts)
Expand Down
15 changes: 10 additions & 5 deletions lib/mix/tasks/phx.gen.html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,14 @@ defmodule Mix.Tasks.Phx.Gen.Html do

[
{:eex, "controller.ex.eex", Path.join([controller_pre, "#{singular}_controller.ex"])},
{:eex, "edit.html.heex.eex", Path.join([controller_pre, "#{singular}_html", "edit.html.heex"])},
{:eex, "edit.html.heex.eex",
Path.join([controller_pre, "#{singular}_html", "edit.html.heex"])},
{:eex, "index.html.heex.eex",
Path.join([controller_pre, "#{singular}_html", "index.html.heex"])},
{:eex, "new.html.heex.eex", Path.join([controller_pre, "#{singular}_html", "new.html.heex"])},
{:eex, "show.html.heex.eex", Path.join([controller_pre, "#{singular}_html", "show.html.heex"])},
{:eex, "new.html.heex.eex",
Path.join([controller_pre, "#{singular}_html", "new.html.heex"])},
{:eex, "show.html.heex.eex",
Path.join([controller_pre, "#{singular}_html", "show.html.heex"])},
{:eex, "resource_form.html.heex.eex",
Path.join([controller_pre, "#{singular}_html", "#{singular}_form.html.heex"])},
{:eex, "html.ex.eex", Path.join([controller_pre, "#{singular}_html.ex"])},
Expand Down Expand Up @@ -305,8 +308,10 @@ defmodule Mix.Tasks.Phx.Gen.Html do
field={f[#{inspect(key)}]}
type="select"
label="#{label(key)}"
prompt="Choose a value"
options={Ecto.Enum.values(#{inspect(schema.module)}, #{inspect(key)})}
options={
[{"Choose a value", ""}] ++
Ecto.Enum.values(#{inspect(schema.module)}, #{inspect(key)})
}
/>
"""

Expand Down
6 changes: 4 additions & 2 deletions lib/mix/tasks/phx.gen.live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,10 @@ defmodule Mix.Tasks.Phx.Gen.Live do
field={@form[#{inspect(key)}]}
type="select"
label="#{label(key)}"
prompt="Choose a value"
options={Ecto.Enum.values(#{inspect(schema.module)}, #{inspect(key)})}
options={
[{"Choose a value", ""}] ++
Ecto.Enum.values(#{inspect(schema.module)}, #{inspect(key)})
}
/>
"""

Expand Down
Loading