defmodule Mix.Tasks.Phx.Install.Components do
@shortdoc "Adds data display components for Phoenix generators"
@moduledoc """
Adds data display components required by Phoenix generators.
This task adds the following components to CoreComponents:
- `header/1` — page header with title, subtitle, and actions
- `table/1` — data table with streaming support
- `list/1` — data list with title/content pairs
These components are required by `phx.gen.html` and `phx.gen.live`.
## Usage
mix phx.install.components
## Prerequisites
This task requires LiveView to be installed (table/1 references
`Phoenix.LiveView.LiveStream`). It is typically called by
`mix phx.install` with the `--live` flag (default: true).
This task is typically called by `mix phx.install` rather than directly.
"""
use Igniter.Mix.Task
@impl Igniter.Mix.Task
def info(_argv, _composing_task) do
%Igniter.Mix.Task.Info{
group: :phoenix,
example: "mix phx.install.components"
}
end
@impl Igniter.Mix.Task
def igniter(igniter) do
web_module = Igniter.Libs.Phoenix.web_module(igniter)
core_components_module = Module.concat(web_module, CoreComponents)
igniter
|> add_header_component(core_components_module)
|> add_table_component(core_components_module)
|> add_list_component(core_components_module)
end
defp add_header_component(igniter, core_components_module) do
header_code = """
@doc \"\"\"
Renders a header with title.
\"\"\"
slot :inner_block, required: true
slot :subtitle
slot :actions
def header(assigns) do
~H\"\"\"
{render_slot(@subtitle)}
{render_slot(@inner_block)}
| {col[:label]} | Actions |
|---|---|
| {render_slot(col, @row_item.(row))} |
<%= for action <- @action do %>
{render_slot(action, @row_item.(row))}
<% end %>
|