defmodule Corex.DataList do @moduledoc ~S''' Phoenix component for rendering semantic data lists. ## Examples ### Basic Pass items directly as slots. The `:item` slot requires a `title` attribute; the inner block renders as the value. ```heex <.data_list> <:item title="Name">Marie Curie <:item title="Field">Physics <:item title="Born">1867 ``` ### Items List Pass a list of `%Corex.Item{}` structs. The component renders title and value using the default `dt`/`dd` structure. ```heex <.data_list items={Corex.Item.new([ %{title: "Name", value: "Marie Curie"}, %{title: "Field", value: "Physics"}, %{title: "Born", value: "1867"} ])} /> ``` ### Custom Items Combine both slots for full control over the content, while the component still owns the `dt`/`dd` structure and `data-scope` attributes. ```heex <.data_list items={Corex.Item.new([ %{title: "Status", value: "Active", meta: %{color: "green", icon: "hero-check"}}, %{title: "Role", value: "Admin", meta: %{color: "blue", icon: "hero-shield-check"}} ])}> <:title :let={item}> <.icon name={item.meta.icon} />{item.title} <:value :let={item}> <.badge color={item.meta.color}>{item.value} ``` ## Styling ```css [data-scope="data-list"][data-part="root"] {} [data-scope="data-list"][data-part="item"] {} [data-scope="data-list"][data-part="title"] {} [data-scope="data-list"][data-part="value"] {} ``` ''' @doc type: :component use Phoenix.Component @doc """ Renders a semantic data list. ## Examples ### Basic Pass items directly as slots. The `:item` slot requires a `title` attribute; the inner block renders as the value. ```heex <.data_list> <:item title="Name">Marie Curie <:item title="Field">Physics <:item title="Born">1867 ``` ### Items List Pass a list of `%Corex.Item{}` structs. The component renders title and value using the default `dt`/`dd` structure. ```heex <.data_list items={Corex.Item.new([ %{title: "Name", value: "Marie Curie"}, %{title: "Field", value: "Physics"}, %{title: "Born", value: "1867"} ])} /> ``` ### Custom Items Combine both slots for full control over the content, while the component still owns the `dt`/`dd` structure and `data-scope` attributes. ```heex <.data_list items={Corex.Item.new([ %{title: "Status", value: "Active", meta: %{color: "green", icon: "hero-check"}}, %{title: "Role", value: "Admin", meta: %{color: "blue", icon: "hero-shield-check"}} ])}> <:title :let={item}> <.icon name={item.meta.icon} />{item.title} <:value :let={item}> <.badge color={item.meta.color}>{item.value} ``` """ attr(:items, :list, default: nil, doc: "List of %Corex.Item{} structs for the items API") attr(:rest, :global, doc: "Additional HTML attributes for the root element") attr(:orientation, :string, default: "vertical", values: ["vertical", "horizontal"], doc: "Layout orientation of items" ) attr(:dir, :string, default: "ltr", values: ["ltr", "rtl"], doc: "Text direction" ) slot :item, required: false, doc: "Slot API: each item with a required title attr and inner block as value" do attr(:title, :string, required: true) attr(:class, :string) end slot(:title, required: false, doc: "Items API: customize the title content. Use :let={item} to access the %Corex.Item{} struct." ) slot(:value, required: false, doc: "Items API: customize the value content. Use :let={item} to access the %Corex.Item{} struct." ) def data_list(assigns) do ~H"""