KantoorWeb.CoreComponents (Kantoor v1.0.0)

The interface's building blocks, named as in the other apps of the suite (Karta, Salt DNS): header, panel, table, badge, button, input, flash, empty_state, copyable, list and icon. Colours are tokens (see assets/css/app.css and guides/contributing/design-system.md); a page adds layout utilities only.

Summary

Functions

A short label with a tone: ok, warn, bad, info, neutral or violet (brand marks a count or a role in Kantoor's own green, never a state). The words carry the meaning; the tone only helps.

A button, or a link when it navigates. variant: "primary" (once per form or page), "plain" (the default), "ghost" (in tables and toolbars), "danger" and "danger_ghost" (what removes), "ok" and "warn" (an answer with a tone). size: "md", "sm" or "xs". join sets buttons side by side as one segmented control; active marks the chosen one.

A notice in the page: a failure to read something, a held-mail warning, a secret shown once. The tone sets the colours; put the words (and an icon) inside.

A value to copy (a token, an address, an id): monospace, broken anywhere, selectable in one click. Copying needs a secure context; the value stays selectable by hand without it.

What an empty list says: what is missing and what to do about it.

Renders flash notices at the top right. Errors are role="alert", the rest role="status".

The page's title, one line of context under it, and the page's own actions on the right.

Renders a Heroicon.

Renders an input with label and error messages.

An id that is unique to the layer a <.table> slot is rendering in: the table keeps id, the phone card gets card-id.

Facts about one record: a term and its value per row.

A titled section on the canvas. flush lets a table or list fill it edge to edge; :actions sit in its header.

A number to take in at a glance, with its label.

A list of records: a table from 768 px, a card per row below it.

Translates an error message using gettext.

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

Functions

badge(assigns)

A short label with a tone: ok, warn, bad, info, neutral or violet (brand marks a count or a role in Kantoor's own green, never a state). The words carry the meaning; the tone only helps.

Attributes

  • tone (:string) - Defaults to "neutral". Must be one of "ok", "warn", "bad", "info", "neutral", "violet", or "brand".
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

button(assigns)

A button, or a link when it navigates. variant: "primary" (once per form or page), "plain" (the default), "ghost" (in tables and toolbars), "danger" and "danger_ghost" (what removes), "ok" and "warn" (an answer with a tone). size: "md", "sm" or "xs". join sets buttons side by side as one segmented control; active marks the chosen one.

Examples

<.button phx-click="go" variant="primary">Send</.button>
<.button navigate={~p"/"} size="sm">Home</.button>

Attributes

  • class (:any) - Defaults to nil.
  • variant (:string) - Defaults to "plain". Must be one of "primary", "plain", "ghost", "danger", "danger_ghost", "ok", or "warn".
  • size (:string) - Defaults to "md". Must be one of "md", "sm", or "xs".
  • join (:boolean) - Defaults to false.
  • active (:boolean) - Defaults to false.
  • Global attributes are accepted. Supports all globals plus: ["href", "navigate", "patch", "method", "download", "name", "value", "disabled", "type"].

Slots

  • inner_block (required)

callout(assigns)

A notice in the page: a failure to read something, a held-mail warning, a secret shown once. The tone sets the colours; put the words (and an icon) inside.

Attributes

  • tone (:string) - Defaults to "neutral". Must be one of "ok", "warn", "bad", "info", or "neutral".
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

copyable(assigns)

A value to copy (a token, an address, an id): monospace, broken anywhere, selectable in one click. Copying needs a secure context; the value stays selectable by hand without it.

Attributes

  • value (:string) (required)
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

empty_state(assigns)

What an empty list says: what is missing and what to do about it.

Attributes

  • icon (:string) - Defaults to "hero-inbox".
  • title (:string) (required)
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block

flash(assigns)

Renders flash notices at the top right. Errors are role="alert", the rest role="status".

Examples

<.flash kind={:info} flash={@flash} />

Attributes

  • id (:string) - the optional id of flash container.
  • 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. the arbitrary HTML attributes to add to the flash container.

Slots

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

header(assigns)

The page's title, one line of context under it, and the page's own actions on the right.

Slots

  • inner_block (required)
  • subtitle
  • actions

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

icon(assigns)

Renders a Heroicon.

Heroicons come in three styles – outline, solid, and mini. By default, the outline style is used, but solid and 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 the deps/heroicons directory and bundled within your compiled app.css by the plugin in assets/vendor/heroicons.js.

Examples

<.icon name="hero-x-mark" />
<.icon name="hero-arrow-path" class="ml-1 size-3 motion-safe:animate-spin" />

Attributes

  • name (:string) (required)
  • class (:any) - Defaults to "size-4".

input(assigns)

Renders an input with label and error messages.

A Phoenix.HTML.FormField may be passed as argument, which is used to retrieve the input name, id, and values. Otherwise all attributes may be passed explicitly.

Types

This function accepts all HTML input types, considering that:

  • You may also set type="select" to render a <select> tag

  • type="checkbox" is used exclusively to render boolean values

  • 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

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

Select type

When using type="select", you must pass the options and optionally a value to mark which option should be preselected.

<.input field={@form[:user_type]} type="select" options={["Admin": "admin", "User": "user"]} />

For more information on what kind of data can be passed to options see options_for_select.

Attributes

  • id (:any) - Defaults to nil.
  • name (:any)
  • label (:string) - Defaults to nil.
  • value (:any)
  • type (:string) - Defaults to "text". Must be one of "checkbox", "color", "date", "datetime-local", "email", "file", "month", "number", "password", "search", "select", "tel", "text", "textarea", "time", "url", "week", or "hidden".
  • 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.
  • class (:any) - the input class to use over defaults. Defaults to nil.
  • error_class (:any) - the input error class to use over defaults. Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["accept", "autocomplete", "capture", "cols", "disabled", "form", "list", "max", "maxlength", "min", "minlength", "multiple", "pattern", "placeholder", "readonly", "required", "rows", "size", "step"].

layer_id(id, arg2)

An id that is unique to the layer a <.table> slot is rendering in: the table keeps id, the phone card gets card-id.

list(assigns)

Facts about one record: a term and its value per row.

Examples

<.list>
  <:item title="Title">{@post.title}</:item>
</.list>

Slots

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

panel(assigns)

A titled section on the canvas. flush lets a table or list fill it edge to edge; :actions sit in its header.

Attributes

  • title (:string) - Defaults to nil.
  • flush (:boolean) - Defaults to false.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • actions
  • inner_block (required)

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

stat(assigns)

A number to take in at a glance, with its label.

Attributes

  • label (:string) (required)
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

table(assigns)

A list of records: a table from 768 px, a card per row below it.

Put it in <.panel flush>. Above 768 px it is a real <table> with th scope="col"; the first column never needs to be scrolled away and long values break rather than widen the page. Below 768 px each row is a compact card: the :title column is the heading (in full, wrapped), :badge columns sit beside it, the :summary slot holds the few key numbers on one line (for example a usage bar), :meta columns are inline label–value pairs (a <dl>, so a screen reader still hears the column name), and :detail columns sit behind a small "More details" text disclosure.

Row actions: the :primary_action slot is shown on the card; the :action slot goes behind a ⋯ button that opens a native popover menu (no script). Both are shown inline in the desktop table.

A row's content is rendered twice, once in the table and once in the card (CSS shows one of the two), so every slot receives {row, layer} where layer is :table or :card. Use layer_id/2 for any DOM id inside a slot, so the two copies do not share an id.

Examples

<.table id="users" rows={@users} row_id={&"user-#{&1.user.id}"}>
  <:col :let={{row, _layer}} label="User" mobile={:title}>{row.user.display_name}</:col>
  <:col :let={{row, _layer}} label="Status" mobile={:badge}>{status(row)}</:col>
  <:col :let={{row, _layer}} label="Last login">{fmt(row.user.last_login_at)}</:col>
  <:empty>No users yet.</:empty>
  <:primary_action :let={{row, layer}}>
    <.button id={layer_id("edit-#{row.id}", layer)}>Edit</.button>
  </:primary_action>
  <:action :let={{row, layer}}>
    <.button variant="danger" id={layer_id("delete-#{row.id}", layer)}>Delete</.button>
  </:action>
</.table>

Attributes

  • id (:string) (required)
  • rows (:list) (required)
  • caption (:string) - what the table is, read by screen readers. Defaults to nil.
  • 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

  • col (required) - Accepts attributes:
    • label (:string)
    • class (:string) - classes for the desktop cell (alignment, wrapping).
    • mobile (:atom) - how the column appears in a phone card; defaults to :meta. Must be one of :title, :badge, :meta, :detail, or :hidden.
  • primary_action - the row action shown directly on a phone card.
  • action - the row actions behind the ⋯ menu on a phone card.
  • summary - the key numbers on a phone card, under the heading.
  • empty - what to say when there are no rows.
  • row_details - extra content under one row (for example a confirmation); render nothing for other rows.

translate_error(arg)

Translates an error message using gettext.

translate_errors(errors, field)

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