View Source FranklinWeb.CoreComponents (Franklin v0.1.0)

Provides core UI components.

At the first glance, this module may seem daunting, but its goal is to provide some core building blocks in your application, such modals, tables, and forms. The components are mostly markup and well documented with doc strings and declarative assigns. You may customize and style them in any way you want, based on your application growth and needs.

The default components use Tailwind CSS, a utility-first CSS framework. See the Tailwind CSS documentation to learn how to customize them or feel free to swap in another framework altogether.

Icons are provided by heroicons. See icon/1 for usage.

Link to this section Summary

Functions

Renders a back navigation link.

Renders a button.

Generates a generic error message.

Renders flash notices.

Shows the flash group with standard titles and content.

Renders a header with title.

Renders an input with label and error messages.

Renders a label.

Renders a data list.

Renders a modal.

Renders a simple form.

Renders a table with generic styling.

Translates an error message using gettext.

Translates the errors for a field from a keyword list of errors.

Link to this section Functions

Renders a back navigation link.

examples

Examples

<.back navigate={~p"/posts"}>Back to posts</.back>

attributes

Attributes

  • navigate (:any) (required)

slots

Slots

  • inner_block (required)

Renders a button.

examples

Examples

<.button>Send!</.button>
<.button phx-click="go" class="ml-2">Send!</.button>

attributes

Attributes

  • type (:string) - Defaults to nil.
  • class (:string) - Defaults to nil. Global attributes are accepted.

slots

Slots

  • inner_block (required)

Generates a generic error message.

slots

Slots

  • inner_block (required)

Renders flash notices.

examples

Examples

<.flash kind={:info} flash={@flash} />
<.flash kind={:info} phx-mounted={show("#flash")}>Welcome Back!</.flash>

attributes

Attributes

  • id (:string) - the optional id of flash container. Defaults to "flash".
  • flash (:map) - the map of flash messages to display. Defaults to %{}.
  • title (:string) - Defaults to nil.
  • kind (:atom) - used for styling and flash lookup.Must be one of :info, or :error. Global attributes are accepted.

slots

Slots

  • inner_block - the optional inner block that renders the flash message.

Shows the flash group with standard titles and content.

examples

Examples

<.flash_group flash={@flash} />

attributes

Attributes

  • flash (:map) (required) - the map of flash messages.

Renders a header with title.

attributes

Attributes

  • class (:string) - Defaults to nil.

slots

Slots

  • inner_block (required)
  • subtitle
  • actions
Link to this function

hide(js \\ %JS{}, selector)

View Source
Link to this function

hide_modal(js \\ %JS{}, id)

View Source

Renders a Hero Icon.

Hero icons come in three styles – outline, solid, and mini. By default, the outline style is used, but solid an mini may be applied by using the -solid and -mini suffix.

You can customize the size and colors of the icons by setting width, height, and background color classes.

Icons are extracted from your assets/vendor/heroicons directory and bundled within your compiled app.css by the plugin in your assets/tailwind.config.js.

examples

Examples

<.icon name="hero-x-mark-solid" />
<.icon name="hero-arrow-path" class="ml-1 w-3 h-3 animate-spin" />

attributes

Attributes

  • name (:string) (required)
  • class (:string) - Defaults to nil.

Renders an input with label and error messages.

A %Phoenix.HTML.Form{} and field name may be passed to the input to build input names and error messages, or all the attributes and errors may be passed explicitly.

examples

Examples

<.input field={@form[:email]} type="email" />
<.input name="my-input" errors={["oh no!"]} />

attributes

Attributes

  • id (:any) - Defaults to nil.
  • name (:any)
  • label (:string) - Defaults to nil.
  • value (:any)
  • type (:string) - Defaults to "text".
  • field (Phoenix.HTML.FormField) - a form field struct retrieved from the form, for example: @form[:email].
  • errors (:list) - Defaults to [].
  • checked (:boolean) - the checked flag for checkbox inputs.
  • prompt (:string) - the prompt for select inputs. Defaults to nil.
  • options (:list) - the options to pass to Phoenix.HTML.Form.options_for_select/2.
  • multiple (:boolean) - the multiple flag for select inputs. Defaults to false. Global attributes are accepted.

slots

Slots

  • inner_block

Renders a label.

attributes

Attributes

  • for (:string) - Defaults to nil.

slots

Slots

  • inner_block (required)

Renders a data list.

examples

Examples

<.list>
  <:item title="Title"><%= @post.title %></:item>
  <:item title="Views"><%= @post.views %></:item>
</.list>

slots

Slots

  • item (required) - Accepts attributes:
    • title (:string) (required)

Renders a modal.

examples

Examples

<.modal id="confirm-modal">
  This is a modal.
</.modal>

JS commands may be passed to the :on_cancel to configure the closing/cancel event, for example:

<.modal id="confirm" on_cancel={JS.navigate(~p"/posts")}>
  This is another modal.
</.modal>

attributes

Attributes

  • id (:string) (required)
  • show (:boolean) - Defaults to false.
  • on_cancel (Phoenix.LiveView.JS) - Defaults to %Phoenix.LiveView.JS{ops: []}.

slots

Slots

  • inner_block (required)
Link to this function

show(js \\ %JS{}, selector)

View Source
Link to this function

show_modal(js \\ %JS{}, id)

View Source

Renders a simple form.

examples

Examples

<.simple_form for={@form} phx-change="validate" phx-submit="save">
  <.input field={@form[:email]} label="Email"/>
  <.input field={@form[:username]} label="Username" />
  <:actions>
    <.button>Save</.button>
  </:actions>
</.simple_form>

attributes

Attributes

  • for (:any) (required) - the datastructure for the form.
  • as (:any) - the server side parameter to collect all input under. Defaults to nil. Global attributes are accepted.

slots

Slots

  • inner_block (required)
  • actions - the slot for form actions, such as a submit button.

Renders a table with generic styling.

examples

Examples

<.table id="users" rows={@users}>
  <:col :let={user} label="id"><%= user.id %></:col>
  <:col :let={user} label="username"><%= user.username %></:col>
</.table>

attributes

Attributes

  • id (:string) (required)
  • rows (:list) (required)
  • row_id (:any) - the function for generating the row id. Defaults to nil.
  • row_click (:any) - the function for handling phx-click on each row. Defaults to nil.
  • row_item (:any) - the function for mapping each row before calling the :col and :action slots. Defaults to &Function.identity/1.

slots

Slots

  • col (required) - Accepts attributes:
    • label (:string)
  • action - the slot for showing user actions in the last table column.

Translates an error message using gettext.

Link to this function

translate_errors(errors, field)

View Source

Translates the errors for a field from a keyword list of errors.