Built-in types
v0.0.12
Gervaz resolves a type name in the DSL to a module. This page lists the built-in column, filter, action and field types, and the ui.extra keys each column type reads. A module that implements the matching behaviour also works as a column type or an action type, with no registration. A custom filter or field module is used only to parse, validate and query. Gervaz returns a name it does not know unchanged, so a misspelled ui do type :imagee end does not fail at compile time. The schema also accepts :currency, :percentage, :time, :image, :avatar, :progress, :json and :custom as column types. No module draws them, so they raise when the cell is drawn. To write your own, see Write a custom type.
Column types
Set a column type with ui do type :badge end. A column without a type takes one from its Ash attribute when the attribute type is in the last column of this table, and :text otherwise.
| Type | Draws | Inferred from |
|---|---|---|
:text | Plain text, with optional truncation. The default. | anything else |
:boolean | A check or a cross icon, or a text label. | Ash.Type.Boolean |
:number | A number with optional prefix, suffix and separators. | Ash.Type.Integer, Ash.Type.Float, Ash.Type.Decimal |
:date | A date in a format you choose. | Ash.Type.Date |
:datetime | A date and time in a format you choose, or a relative time. | Ash.Type.DateTime, Ash.Type.UtcDatetime, Ash.Type.UtcDatetimeUsec |
:uuid | A UUID cut to its first characters. | Ash.Type.UUID, Ash.Type.UUIDv7 |
:array | The items of a list, joined or drawn as badges. | array attributes |
:badge | A status badge whose color and label come from the value. | never inferred |
:bars | A small numeric value as filled bars beside the number. | never inferred |
:tags | A list value as chips, with a +N chip that expands the rest in place. | never inferred |
:avatars | Related people as an overlapping avatar stack, with a +N disc that expands the rest. | never inferred |
:link | A clickable link. | never inferred |
:site | The name of the site (tenant) a row belongs to, in a quiet monospace face. An empty cell for a row whose site was not read. | never inferred |
A :site column is drawn only while the table reads across tenants, as a master's read of every site does, unless the column sets its own visible function. Point its source at the site's name, such as source {:site, :name}, and preload the site for masters only, so other readers pay no read for it.
Options in ui.extra
Each type reads its options from the extra map of the column's ui block.
| Type | Key | Meaning |
|---|---|---|
:text | :max_length | Truncates the text after this many characters. Not set by default. |
:text | :truncate_suffix | The suffix of truncated text. Default "...". |
:text | :dir | "ltr", "rtl" or "auto". Without it, a value of printable ASCII with no space, such as an email, a URL or an ID, reads left to right, and any other value follows the page. |
:boolean | :true_icon, :false_icon | The icons. Defaults "hero-check" and "hero-x-mark". |
:boolean | :true_class, :false_class | The icon classes. The UI adapter supplies the defaults, which are "size-5 text-[#177a53]" and "size-5 text-[#c0473d]" in the Tailwind adapter. A value you set replaces the whole string, size-5 included. |
:boolean | :true_label, :false_label | Text labels, as an alternative to the icons. |
:number | :precision | Decimal precision. It applies to floats and decimals, and integers ignore it. Not set by default, so the number shows as it is. |
:number | :prefix, :suffix | Strings placed before and after the number, such as "$" or " kg". |
:number | :thousands_separator, :decimal_separator | Separators. Defaults "," and ".". |
:date | :format | A date format string. Default "%Y-%m-%d". |
:datetime | :format | A format string. Default "%Y-%m-%d %H:%M". |
:datetime | :relative | Shows a relative time such as "2 hours ago". Default false. |
:uuid | :show_full | Shows the whole UUID. Default false. |
:uuid | :prefix_length, :suffix_length | Characters shown at the start and the end. Defaults 8 and 0. |
:array | :separator | The separator between items. Default ", ". |
:array | :max_items | The most items to show. Not set by default, so all show. |
:array | :as_badges, :badge_class | Draws each item as a badge, and the badge class. Default false. |
:badge | :colors | A map of value to color class. Keys match the string form of the value first, then its existing atom. |
:badge | :labels | A map of value to label, translated in the reader's locale. A value without one falls back to its humanized form. |
:badge | :dots | A map of value to dot class, for the :pill variant. |
:badge | :variant | :tag (the default) or :pill, which has a leading dot. |
:badge | :default_color | The color class for a value that is not in :colors. |
:bars | :max | The number of bars. Default 4. |
:bars | :percent | Set true when the value is a 0 to 100 weight. The bars fill in proportion, and the color follows the percentage band. |
:bars | :ceiling | An explicit denominator for proportional fill. percent: true is shorthand for ceiling: 100. Without either, the lit count is min(max, value + 1). |
:bars | :scale | An ordered list of {max_value_inclusive, hex} tuples ending in {:default, hex}. The first entry whose threshold is at least the value wins. |
:tags | :max_items | Chips shown before the +N chip. Default 2. |
:tags | :badge_class, :empty | The chip class, and the text for an empty list. An item is a string, or %{label:, class:, title:} for a chip styled on its own. |
:avatars | :max_items | Faces shown before the +N disc. Default 3. |
:avatars | :image_field, :label_field | The fields of the related record that hold the image URL and the name. Defaults :avatar_url and :name. |
:avatars | :tints, :size, :empty | Disc classes cycled by position for entries with no image, the disc size class (default "size-[26px]"), and the text for an empty list. |
:link | :path_fn | A function of the record that returns the path. Needed for navigation. |
:link | :external | Opens the link in a new tab. Default false. |
:link | :class, :label_fn | The link class, and a function that returns the label. Without a label function the column value is the label. |
Filter types
Set a filter type as the second argument: filter :status, :select. A filter without a type is a :text filter.
| Type | Draws |
|---|---|
:text | A text input. It matches part of a value without regard to case. A % or _ in the term is that character. The fields option searches several fields at once. |
:select | A dropdown. Options come from options. |
:boolean | A checkbox. |
:number | The built-in table template draws it as a plain text input. Filter.Number.render_input/3 exists, and the template does not call it. |
:date | The built-in table template draws it as a plain text input. |
:date_range | Two date inputs. Use source when the field has another name. Either side alone filters from or up to its day, and a From after the To is taken the other way round. |
:relation | A select over related records. mode sets how the options load. With options and no resource, it is a searchable list the database does not hold as rows, and its values are strings. |
Action types
Set an action type with the type option of a row action. A bulk action accepts only :event, :destroy, :update, :unarchive and :permanent_destroy, and no custom module. :link, :edit, :row_click, :accordion and :drawer are for row actions only.
| Type | Draws or does |
|---|---|
:link | A navigation link to path, which is a string used as written or a function of the record. A path, string or function, always wins. An action named :show or :show_link with no path goes to {route}/{id}, and one named :edit or :edit_link to {route}/{id}/edit, built from the table's route with its :param segments filled in. A table with no route links to #. Any other :link action with no path is reported when you compile. |
:event | A button that fires an event. The default. The payload is %{id: record.id} unless you set payload. |
:edit | A button that sends the record to the form component, which reads it again even when it is already open. A js function runs first, so it can open a modal. |
:destroy | A delete button with confirmation. |
:update | A button that runs an Ash update action, named by action. |
:unarchive | A restore button for archived records. |
:permanent_destroy | A button that permanently deletes an archived record. |
:row_click | Declares a clickable row, by path or event. It draws nothing, and the built-in templates do not call its click handler. |
:drawer | A button that opens the row in the table's drawer: a record view you draw (open: fn record -> ~H"..." end) or the resource's own form editing the row (open: :form). The head of the drawer comes from the drawer option. An action of this type without open is reported when you compile. See Open a row in a drawer. |
:accordion | An expand and collapse toggle. It draws nothing unless the :expand feature is on, and only on rows where the action is visible and not restricted from the reader. It sends {:expand_row, id} to the parent LiveView, which answers with expanded_html. |
The schema also lists :modal as a row action type, but the built-in registry has no entry for it.
Field types
Set a field type as the second argument: field :body, :textarea. A field without a type takes one from its Ash attribute, as the table on Form fields DSL shows.
| Type | Draws |
|---|---|
:text | The default text input. It strips HTML tags and trims whitespace. The input follows what is typed. Set ui do extra %{dir: "ltr"} end for a value always written left to right. It draws the max_length constraint of its Ash attribute as the input's maxlength, or the field's own max_length. ui prefix and ui suffix put a unit at the start or the end of the input. The unit is only shown and is not saved. |
:password | A masked input. It trims only the surrounding whitespace. It takes ui prefix, ui suffix and max_length as :text does. |
:textarea | A multi-line input. It keeps newlines and markup. |
:number | A numeric input. It checks that the value is a number and within the field's min and max, which may be integers, floats or Decimals. A value outside them gets the error "is too small" or "is too large". The input carries min, max and ui step, and a Decimal value is drawn as plain digits. ui prefix and ui suffix put a unit at the start or the end of the input. |
:checkbox | A checkbox. ui note draws a sentence beside it, inside its label. |
:toggle | A boolean switch. ui note draws a sentence beside it, inside its label. |
:date | A date picker. It checks for an ISO 8601 date. The field's min and max grey out the days outside them, and a value outside them gets the error "is too early" or "is too late". ui first_day_of_week sets the day each week starts on, Monday when not set. |
:datetime | A date and time picker. It accepts ISO 8601 values, and the minutes-only value a browser sends. It takes min and max as :date does, and ui step sets the minutes between the times the picker offers. |
:range | A range slider from the field's min to its max, 0 to 100 when they are not set, in ui steps, 1 when not set. A value outside the bounds gets the error "is too small" or "is too large". |
:select | A single-select dropdown. An empty choice comes before the options, labeled with ui placeholder when you set one and "Select..." otherwise. A required field or one with a default has no empty choice. |
:multi_select | One checkbox per option. The save sends the ticked values as a list, and an empty list when none is ticked. An option may be a keyword list or map with a :description, a second line under its label. |
:choice_cards | One choice drawn as a card per option, each a radio input. An option is {label, value}, or a keyword list or map with :label, :value, :description (a second line), :icon and disabled: true (shown, but not pickable). options may be a function of no arguments or of the form state. |
:segmented | The same choice as :choice_cards, drawn as the segments of one bar with the chosen one raised. It suits two to four short options. |
:combobox | A text input with a list of suggestions. The reader can type any value. The options load once, when the form starts. |
:relation | A picker for related records, in the four modes of mode. |
:json | A JSON editor. It decodes JSON strings and checks that the value is valid JSON. |
:key_map | A map whose keys you declare, drawn as one control per key. |
:key_list | A list of maps whose keys you declare, with rows the reader adds and removes. |
:nested | An embedded form for an embedded resource or a constrained map attribute, built from nested_field entities. |
:array_of_maps | The schema accepts it, and the Standard form template draws it as a plain text input. Use :nested or :key_list for repeatable groups. |
:string_list | A list of text inputs with add and remove buttons, for {:array, :string} attributes. It drops empty strings. |
:file | A file input. |
:upload | A position for an upload declared in the uploads section. Gervaz marks such a field virtual. |
:hidden | A bare hidden input that carries the value, with no label and no text box. |