defmodule BitstylesPhoenix.Component.Heading do use BitstylesPhoenix.Component @moduledoc """ Components for building headings. """ @doc ~s""" Render a page header with a `

` title and an optional `title_extra` and some `action` slots for that page (usually combined with buttons and dropdowns). ## Attributes - `class` - Set CSS classes on the outer div. - All other attributes are passed to the outer `div` tag. ## Attributes - `title_extra` slot - `class` - Set CSS classes on the surrounding div. - All other attributes are passed to the outer `div` tag. ## Attributes - `action` slots - `class` - Set CSS classes on the surrounding `li`. - `show` - If the action should be rendered. Defaults to `true`. - All other attributes are passed to the outer `li` tag. See [the page header docs](https://bitcrowd.github.io/bitstyles/?path=/docs/ui-content-page-header--page-header) for more examples and details. """ story( "Page title", ''' iex> assigns = %{} ...> render ~H""" ...> <.ui_page_title> ...> Title ...> ...> """ ''', ''' """

Title

""" ''', width: "100%" ) story( "Page title with actions and title extra", ''' iex> assigns = %{} ...> render ~H""" ...> <.ui_page_title> ...> Title ...> <:title_extra> ...> <.ui_badge>Published ...> ...> <:action> ...> <.ui_button>Edit ...> ...> <:action> ...> <.ui_button color="danger">Delete ...> ...> <:action show={false}> ...> <.ui_button color="danger">Hide me ...> ...> ...> """ ''', ''' """

Title

Published
""" ''', width: "100%", extra_html: """ """ ) def ui_page_title(assigns) do class = classnames(["u-flex u-justify-between u-flex-wrap u-items-center", assigns[:class]]) extra = assigns_to_attributes(assigns, [:class, :action, :title_extra]) assigns = assign(assigns, class: class, extra: extra) ~H"""

<%= render_slot(@inner_block) %>

<%= if assigns[:title_extra] do %>
<%= render_slot(@title_extra) %>
<% end %>
<%= if assigns[:action] do %> <.ui_action_buttons action={@action}/> <% end %>
""" end @section_default_border_color "gray-light" @doc ~s""" Render a section header with optional `action`s and `title_extra`. ## Attributes - `class` - Set CSS classes on the outer div. - `border` - Controls the bottom border and padding (default: true, boolean) - `border_color` - The border color, defaults to `gray-light` resulting in `u-border-gray-light-bottom`. - `tag` - the heading tag (defaults to h3) - `heading_class` - Extra classes on the heading - All other attributes are passed to the outer `div` tag. ## Attributes - `title_extra` slot - `class` - Set CSS classes on the surrounding div. - All other attributes are passed to the outer `div` tag. ## Attributes - `action` slots - `class` - Set CSS classes on the surrounding `li`. - `show` - If the action should be rendered. Defaults to `true`. - All other attributes are passed to the outer `li` tag. """ story( "Section title with default border", ''' iex> assigns = %{} ...> render ~H""" ...> <.ui_section_title> ...> Section title ...> ...> """ ''', ''' """

Section title

""" ''', width: "100%" ) story( "Section title without border and h2", ''' iex> assigns = %{} ...> render ~H""" ...> <.ui_section_title border={false} tag={:h2}> ...> Section title ...> ...> """ ''', ''' """

Section title

""" ''', width: "100%" ) story( "Section title with actions and title extra and different border", ''' iex> assigns = %{} ...> render ~H""" ...> <.ui_section_title border_color="gray-light" heading_class="extra"> ...> Section title ...> <:title_extra> ...> <.ui_badge>Published ...> ...> <:action> ...> <.ui_button>Edit ...> ...> <:action> ...> <.ui_button color="danger">Delete ...> ...> <:action show={false}> ...> <.ui_button color="danger">Hide me ...> ...> ...> """ ''', ''' """

Section title

Published
""" ''', width: "100%" ) def ui_section_title(assigns) do border_color = Map.get(assigns, :border_color, @section_default_border_color) border = Map.get(assigns, :border, true) class = classnames([ "u-flex u-flex-wrap u-items-center u-justify-between", {"u-padding-m-bottom u-border-#{border_color}-bottom", border}, assigns[:class] ]) extra = assigns_to_attributes(assigns, [ :class, :action, :title_extra, :tag, :border, :border_color, :heading_class ]) assigns = assigns |> assign(class: class, extra: extra) |> assign_new(:tag, fn -> :h3 end) ~H"""
<.dynamic_tag name={@tag} class={classnames(["u-margin-0 u-margin-m-right u-break-text", assigns[:heading_class]])}> <%= render_slot(@inner_block) %> <%= assigns[:title_extra] && render_slot(@title_extra) %>
<%= if assigns[:action] do %> <.ui_action_buttons action={@action}/> <% end %>
""" end defp ui_action_buttons(assigns) do ~H""" """ end end