SaltDnsWeb.CoreComponents (Salt v1.0.0)

The components of the Salt web interface: on Tailwind utilities and the colour tokens of assets/css/app.css. The design system (tokens, the band, the logo and the components) is described in docs/design.md; a page is built from these and adds layout utilities only.

Every component renders under the browser pages' content security policy: no inline style, no inline script, no event handler attribute. The one piece of browser code in the console, copying to the clipboard, is a colocated hook in SaltDnsWeb.Console.Components.

Summary

Functions

A small label with a tone: neutral, ok, warn, bad, info, violet or brand.

A button, or a link that looks like one when it has href, navigate or patch. variant: plain (the default), primary (the one main action of a form or page) or danger (removes or stops something, with data-confirm). size: md or sm.

A notice inside the page, for a state the reader must know about. tone is one of the status tones.

What a list says when it is empty: what is missing, and what to do about it (inner_block, actions).

A flash notice, at the top right; a click dismisses it.

The heading of a page: its title, a line under it, and the page's own actions on the right.

A Heroicon: hero-<name> (outline, 24 px), -solid, -mini (20 px) or -micro (16 px). Size and colour come from class. Decorative: give the element around it a label when the icon alone carries meaning.

An input with its label, help and errors. A Phoenix.HTML.FormField gives the name, id, value and errors.

A section of a page: a titled surface. flush drops the inner padding, for a table that fills it.

A table: dense rows and a sticky header on a wide screen; below sm each row becomes a compact stacked card instead of a sideways-scrolling table. The card's title is the column marked mobile={:title} (the first column when none is marked); a column marked mobile={:badge} sits at its right. Every other column is a label and value pair, two to a line; a long value takes the whole width with mobile={:value} (no visible label) or mobile={:block} (its label above it). mobile={:hidden} keeps a secondary column for wide screens only; the more slot carries those fields behind a text disclosure on a phone.

Translates an error message using gettext.

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

Functions

badge(assigns)

A small label with a tone: neutral, ok, warn, bad, info, violet or brand.

Attributes

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

Slots

  • inner_block (required)

button(assigns)

A button, or a link that looks like one when it has href, navigate or patch. variant: plain (the default), primary (the one main action of a form or page) or danger (removes or stops something, with data-confirm). size: md or sm.

<.button variant="primary">Save</.button>
<.button navigate={~p"/"}>Organisations</.button>
<.button variant="danger" size="sm" data-confirm="Revoke it?">Revoke</.button>

Attributes

  • variant (:string) - Defaults to "plain". Must be one of "primary", "plain", or "danger".
  • size (:string) - Defaults to "md". Must be one of "sm", or "md".
  • class (:any) - Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["href", "navigate", "patch", "method", "download", "name", "value", "disabled", "form", "type", "rel", "phx-click", "phx-value-id", "phx-value-name", "phx-value-type", "phx-disable-with", "data-confirm"].

Slots

  • inner_block (required)

callout(assigns)

A notice inside the page, for a state the reader must know about. tone is one of the status tones.

<.callout id="frozen" tone="warn" icon="hero-pause-circle" title="Frozen">
  Changes are not accepted.
</.callout>

Attributes

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

Slots

  • inner_block
  • actions

empty_state(assigns)

What a list says when it is empty: what is missing, and what to do about it (inner_block, actions).

<.empty_state id="no-zones" icon="hero-globe-alt" title="No zones yet">
  Add the first domain the organisation manages.
</.empty_state>

Attributes

  • id (:string) - Defaults to nil.
  • icon (:string) - Defaults to "hero-inbox".
  • title (:string) (required)
  • class (:any) - Defaults to nil.

Slots

  • inner_block
  • actions

flash(assigns)

A flash notice, at the top right; a click dismisses it.

<.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 heading of a page: its title, a line under it, and the page's own actions on the right.

Attributes

  • id (:string) - Defaults to nil.

Slots

  • inner_block (required)
  • subtitle
  • actions

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

icon(assigns)

A Heroicon: hero-<name> (outline, 24 px), -solid, -mini (20 px) or -micro (16 px). Size and colour come from class. Decorative: give the element around it a label when the icon alone carries meaning.

<.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)

An input with its label, help and errors. A Phoenix.HTML.FormField gives the name, id, value and errors.

type="select" takes options (and prompt); type="checkbox" is for one boolean; help is a sentence under the field. class styles the wrapper, input_class the field itself.

<.input field={@form[:email]} type="email" label="Address" />
<.input field={@form[:role]} type="select" label="Role" options={@roles} />

Attributes

  • id (:any) - Defaults to nil.
  • name (:any)
  • label (:string) - Defaults to nil.
  • help (: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) - classes for the field's wrapper (its width, say). Defaults to nil.
  • input_class (:any) - classes for the input, select or textarea itself. Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["accept", "autocomplete", "autocapitalize", "capture", "cols", "disabled", "form", "inputmode", "list", "max", "maxlength", "min", "minlength", "multiple", "pattern", "placeholder", "readonly", "required", "rows", "size", "spellcheck", "step", "tabindex", "phx-mounted", "phx-debounce", "phx-blur", "phx-focus"].

panel(assigns)

A section of a page: a titled surface. flush drops the inner padding, for a table that fills it.

<.panel id="dkim" title="DKIM keys">
  <:actions><.button size="sm">Generate</.button></:actions>
  ...
</.panel>

Attributes

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

Slots

  • inner_block (required)
  • subtitle
  • actions

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

table(assigns)

A table: dense rows and a sticky header on a wide screen; below sm each row becomes a compact stacked card instead of a sideways-scrolling table. The card's title is the column marked mobile={:title} (the first column when none is marked); a column marked mobile={:badge} sits at its right. Every other column is a label and value pair, two to a line; a long value takes the whole width with mobile={:value} (no visible label) or mobile={:block} (its label above it). mobile={:hidden} keeps a secondary column for wide screens only; the more slot carries those fields behind a text disclosure on a phone.

The first column stays in view when the table scrolls sideways on a wide screen, and its text wraps rather than being cut off. rows may be a list or a stream (@streams.name); id is the tbody's. A column's class aligns it (text-right for numbers) or sets its font (font-mono for identifiers).

<.table id="zones" rows={@zones}>
  <:col :let={zone} label="Zone" mobile={:title}>{zone.name}</:col>
  <:col :let={zone} label="Status" mobile={:badge}>
    <.status_badge tone={zone.tone}>{zone.label}</.status_badge>
  </:col>
  <:col :let={zone} label="Added">{zone.added}</:col>
</.table>

A table that already sits inside a <.panel> passes plain so that it does not draw a second border.

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_class (:any) - the function giving a row's extra classes. Defaults to nil.
  • row_item (:any) - maps each row before the slots. Defaults to &Function.identity/1.
  • plain (:boolean) - draw no border or background around the table. Defaults to false.
  • class (:any) - Defaults to nil.
  • stack (:boolean) - below sm each row becomes a stacked card; false keeps a scrolling table. Defaults to true.

Slots

  • col (required) - Accepts attributes:
    • label (:string)
    • class (:any)
    • mobile (:atom) - the column's place in a phone's card (default :fact). Must be one of :title, :badge, :fact, :block, :value, or :hidden.
  • action - the slot for showing user actions in the last table column.
  • more - secondary fields for a phone, behind a More disclosure.

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.