@gravionlabs/helix-ui 22.9.1 → 22.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -59,7 +59,8 @@
59
59
  },
60
60
  "./styles.css": "./styles.css",
61
61
  "./core.css": "./core.css",
62
- "./tokens.css": "./tokens.css"
62
+ "./tokens.css": "./tokens.css",
63
+ "./styleguide/*": "./styleguide/*"
63
64
  },
64
- "version": "22.9.1"
65
+ "version": "22.10.1"
65
66
  }
@@ -0,0 +1,99 @@
1
+ # UX style guide
2
+
3
+ The base guide for apps on Helix ([ADR 0008](https://github.com/GravionLabs/helix/blob/main/docs/adr/0008-ux-style-guide-a-helix-base-guide-that-app-guides-extend.md)).
4
+ Binding for every UI change. Read this whole file first; read a deep dive only when its condition applies.
5
+ A deviation needs a reason in the PR. Names are those of `@gravionlabs/helix-ui` unless said otherwise.
6
+
7
+ ## Tokens
8
+
9
+ - Load `@gravionlabs/helix-ui/tokens.css`; it holds the values ([Theming](https://gravionlabs.github.io/helix/THEMING)). This guide names roles.
10
+ - Colors, font sizes, spacing, radii and shadows are `var(--h-…)` tokens, never literals in app CSS.
11
+ - Spacing is a `--h-space-*` step, a radius a `--h-border-radius-*` step, an overlay shadow a `--h-overlay-*-shadow`.
12
+ - Change a look by overriding a token (`--h-*`), never the CSS of a Helix component.
13
+ - Light, dark and the primary color are set through `provideHxTheme` and `HxTheme`.
14
+
15
+ ## Color
16
+
17
+ | Role | Token or carrier |
18
+ | ---------------------- | ----------------------------------------------------------------------------------- |
19
+ | Background | `--h-surface-frame`, `--h-surface-panel`, `--h-surface-card`, `--h-surface-overlay` |
20
+ | Hovered row or item | `--h-surface-hover` |
21
+ | Border | `--h-border-panel` around, `--h-border-divider` inside |
22
+ | Text, muted text | `--h-text-color`, `--h-text-muted-color` |
23
+ | Primary action, danger | `hx-button` (default severity), `severity="danger"` |
24
+ | Focus | `--h-focus-ring-*` |
25
+
26
+ - Text on a surface role is `--h-text-color` or `--h-text-muted-color` (at least 4.5:1 on each of them).
27
+ - A view or dialog has at most one filled primary `hx-button`; `danger` is for destructive actions, never for Cancel.
28
+ - The focus ring tokens mark focus only.
29
+ - A status is never color alone: an `hx-tag` has a text, an `hx-message` keeps its icon and a text.
30
+ - Read [color.md](color.md) when you set a color in app CSS, show a status or pick a `severity`.
31
+
32
+ ## Typography and spacing
33
+
34
+ - UI text is `--helix-font-sans`, code `--helix-font-mono` (apps with the `helix-shell` stylesheet).
35
+ - Every `font-size` is a `--h-font-size-*` step; a screen uses at most four of them.
36
+ - Body text is `--h-font-size-sm` or larger; `--h-font-size-xs` is for secondary text such as row meta.
37
+ - Gaps, padding and margins are `--h-space-*` steps.
38
+ - Toolbar actions sit in [`hx-toolbar`](https://gravionlabs.github.io/helix/components/toolbar), list rows are
39
+ [`hx-list-row`](https://gravionlabs.github.io/helix/components/list-row) in an `hx-list`. Their gap, padding and font size stay those of the
40
+ `--h-toolbar-*` and `--h-list-row-*` tokens on every screen.
41
+ - A denser app sets the [density option](https://gravionlabs.github.io/helix/THEMING#density) (`density: 'compact'`, `HxTheme.setDensity`) for the
42
+ whole app; no screen shrinks its own text or padding.
43
+
44
+ ## Components
45
+
46
+ - Use the [Helix component](https://gravionlabs.github.io/helix/components/) before you build one.
47
+ - No raw `<button>`, `<input>`, `<select>`, `<textarea>` or `<progress>` without its Helix directive or component.
48
+ - A text input, checkbox, radio, switch or `hx-select` of a form sits in an [`hx-field`](https://gravionlabs.github.io/helix/components/form-field)
49
+ with a `label`.
50
+ - Read [forms.md](forms.md) when you add or change a form.
51
+ - Read [components.md](components.md) when you add or change a button, a list or any other control, or before you
52
+ build a component.
53
+ - A modal decision is an [`hx-dialog`](https://gravionlabs.github.io/helix/components/dialog) with its actions in `hxDialogFooter`.
54
+ - Read [dialogs.md](dialogs.md) when you add or change a dialog or a confirmation.
55
+ - Read [form-patterns.md](form-patterns.md) when you build a dialog with a form: a complete example.
56
+ - An icon-only `hx-button` (`iconOnly`) has an `aria-label` and an `hx-tooltip`.
57
+ - Hover, focus, active and disabled states are the component's; the app sets `disabled`, it draws no state itself.
58
+
59
+ ## UX rules
60
+
61
+ - A started action disables its control at once (`[disabled]`, or `[loading]` on `hx-button`); from 1 s it shows
62
+ `[loading]` or an `hx-progress-spinner`, from 3 s named steps or an `hx-progress-bar`.
63
+ - An irreversible action asks through `HxConfirmationService`; a reversible one runs and offers Undo in an `hx-toast`.
64
+ - Every data view has an empty state that names the next action, a loading state (`hx-skeleton`, or `loading` of
65
+ `hx-data-table`) and an error state (`hx-message severity="error"` with a retry `hx-button`).
66
+ - Texts of `hx-button`, `hx-field` and `hx-message` are in sentence case, without "please", "simply" or "just".
67
+ - Read [ux-rules.md](ux-rules.md) when you add or change a flow, a dialog, a tooltip, a message, an empty or error
68
+ state, or an animation.
69
+
70
+ ## Cross-platform
71
+
72
+ - Targets: desktop (macOS, Windows, Linux), mobile and web. A desktop app picks `hx-app-shell` or `hx-mobile-shell`
73
+ by [`getHxPlatform()`](https://gravionlabs.github.io/helix/HELIX-DESKTOP#hxmobileshell-and-hxbottombar), never by window width.
74
+ - Every action is a native control (`hx-button`, `[hx-list-row]`, an `hx-menu` item), so it works from the keyboard.
75
+ - A shown shortcut is implemented: `hxTooltipShortcut` or [`hx-kbd`](https://gravionlabs.github.io/helix/components/kbd) with the keys of the
76
+ user's platform, and `aria-keyshortcuts` on the control.
77
+ - Read [platform.md](platform.md) when you show or handle a shortcut, write CSS for a desktop app, or change a Tauri
78
+ app on Linux (WebKitGTK) or Windows (WebView2).
79
+
80
+ ## Enforcement
81
+
82
+ - [`@gravionlabs/helix-lint`](https://gravionlabs.github.io/helix/LINT) blocks in CI: Stylelint (no hex, no raw color functions, font sizes from
83
+ the scale) and the template rule `helix/no-raw-control`.
84
+ - Every exception is a `helixAllow` entry with a reason.
85
+ - What lint cannot check is reviewed; a review finding blocks only when an acceptance criterion names it.
86
+ - Read [ux-review-rubric.md](ux-review-rubric.md) when you review a UI change: its questions and fixed output.
87
+
88
+ ## How app guides extend this guide
89
+
90
+ - An app has its own `docs/STYLEGUIDE.md`, linked from its `AGENTS.md`.
91
+ - It names this guide as its base: `node_modules/@gravionlabs/helix-ui/styleguide/STYLEGUIDE.md`.
92
+ - It lists only the app's own rules and deviations, each deviation with a reason. It copies no base rule.
93
+ - It may tighten a base rule freely; it relaxes one only as a named deviation.
94
+
95
+ ## When this guide is silent
96
+
97
+ 1. Follow the nearest existing component or screen that solves the same problem.
98
+ 2. If none exists, choose the simplest option made of Helix components and tokens only.
99
+ 3. Write the choice and the reason in the PR. If it will recur, file a Helix issue: a rule needs a carrier here.
@@ -0,0 +1,122 @@
1
+ # Color
2
+
3
+ Deep dive of the [UX style guide](STYLEGUIDE.md): read it when you set a color in app CSS, show a status, or pick the
4
+ `severity` of a control. It names color roles; the values are in [Theming](https://gravionlabs.github.io/helix/THEMING), the roles in
5
+ [ADR 0004](https://github.com/GravionLabs/helix/blob/main/docs/adr/0004-surface-roles-dark-elevation-density-and-named-theme-presets.md). The rules are for app CSS and
6
+ templates: a Helix component colors itself.
7
+
8
+ ## Surfaces and their foregrounds
9
+
10
+ A background and the text on it are picked together, from one row. App CSS that sets a background of this table also
11
+ sets, or inherits, the foreground of the same row.
12
+
13
+ | Role | Background | Foreground |
14
+ | ------------------------------ | ------------------------------------------------------ | ------------------------------------------- |
15
+ | Chrome: ground behind panels | `--h-surface-frame` | `--h-text-color`, `--h-text-muted-color` |
16
+ | Content: panel or page | `--h-content-background` (`--h-surface-panel`) | `--h-content-color`, `--h-text-muted-color` |
17
+ | Content: card, table head | `--h-surface-card` | `--h-text-color`, `--h-text-muted-color` |
18
+ | Hovered row or item | `--h-content-hover-background` (`--h-surface-hover`) | `--h-content-hover-color` |
19
+ | Overlay: dialog | `--h-overlay-modal-background` (`--h-surface-overlay`) | `--h-overlay-modal-color` |
20
+ | Overlay: popover | `--h-overlay-popover-background` | `--h-overlay-popover-color` |
21
+ | Overlay: list of a select | `--h-overlay-select-background` | `--h-overlay-select-color` |
22
+ | Selected item of an app's list | `--h-highlight-background` | `--h-highlight-color` |
23
+
24
+ - Text and muted text keep at least 4.5:1 on `frame`, `panel`, `card`, `overlay` and `hover`.
25
+ - An overlay is an [`hx-dialog`](https://gravionlabs.github.io/helix/components/dialog), [`hx-popover`](https://gravionlabs.github.io/helix/components/popover) or
26
+ [`hx-menu`](https://gravionlabs.github.io/helix/components/menu), which paint their own row. The app sets overlay tokens only on content it puts
27
+ into an overlay of its own.
28
+ - A row of [`hx-list`](https://gravionlabs.github.io/helix/components/list-row) or a table paints its own hover and selection.
29
+ - A line around a panel or card is `--h-border-panel` (`--h-content-border-color`), a line inside one
30
+ `--h-border-divider`.
31
+ - App CSS reads a role, not a scale step: no `--h-surface-0` to `--h-surface-950`. A step does not follow the role
32
+ in the other color scheme.
33
+ - New app CSS reads the `--h-*` names above. The `--helix-surface-*`, `--helix-border` and `--surface-*`
34
+ [aliases](https://gravionlabs.github.io/helix/THEMING#surface-roles) of `helix-shell` are for existing CSS.
35
+ - `--h-mask-*` belongs to the mask of `hx-dialog` and `hx-drawer`; app CSS does not read it.
36
+
37
+ ```css
38
+ .summary {
39
+ background: var(--h-surface-card);
40
+ color: var(--h-text-color);
41
+ border: 1px solid var(--h-border-panel);
42
+ }
43
+
44
+ .summary-meta {
45
+ color: var(--h-text-muted-color);
46
+ }
47
+ ```
48
+
49
+ ## Primary
50
+
51
+ - Primary marks the one affirmative action of a view or dialog: at most one filled
52
+ [`hx-button`](https://gravionlabs.github.io/helix/components/button) with the default `severity`. Every other action follows the
53
+ [button hierarchy](components.md#button-hierarchy).
54
+ - In app CSS, `--h-primary-color` colors the text of a link and nothing else: no background, border, heading, icon or
55
+ decoration of the app reads a `--h-primary-*` token.
56
+ - `--h-primary-contrast-color` is the foreground of a primary fill, which the component paints.
57
+ - The primary color is changed with `provideHxTheme` or `HxTheme.setPrimary`, never by CSS on a component.
58
+
59
+ ## Focus
60
+
61
+ - The `--h-focus-ring-*` tokens appear only in `:focus-visible` rules: not on hover, selection, errors or highlights.
62
+ - Helix components draw their own focus. An element the app makes focusable draws it with all the tokens, and no
63
+ app rule removes an outline without this replacement.
64
+
65
+ ```css
66
+ .canvas:focus-visible {
67
+ outline: var(--h-focus-ring-width) var(--h-focus-ring-style) var(--h-focus-ring-color);
68
+ outline-offset: var(--h-focus-ring-offset);
69
+ box-shadow: var(--h-focus-ring-shadow);
70
+ }
71
+ ```
72
+
73
+ ## Danger
74
+
75
+ - `danger` is for an action that destroys or loses data: `severity="danger"` on `hx-button`, `acceptSeverity: 'danger'`
76
+ in [`HxConfirmationService`](https://gravionlabs.github.io/helix/components/confirm).
77
+ - Cancel, close and dismiss are never `danger`: they are `severity="secondary"`. The reject button of
78
+ `HxConfirmationService` already is.
79
+
80
+ ## Status
81
+
82
+ A status is never color alone. It is shown by a Helix component, with its text or icon:
83
+
84
+ | Status shown as | Carrier | Next to the color |
85
+ | ------------------------- | -------------------------------------------------------- | ------------------------------------------------------- |
86
+ | Label of an item | [`hx-tag`](https://gravionlabs.github.io/helix/components/tag) with `severity` | `value` or content text; `icon` is optional |
87
+ | Message next to its cause | [`hx-message`](https://gravionlabs.github.io/helix/components/message) with `severity` | its icon (built in, or `icon`) and a text |
88
+ | Passing result | [`hx-toast`](https://gravionlabs.github.io/helix/components/toast), `HxMessageService` | its built-in icon and a `summary` or `detail` |
89
+ | Count | [`hx-badge`](https://gravionlabs.github.io/helix/components/badge) with `value` | the value, and what it counts in the name or text by it |
90
+ | Dot | `hx-badge` without `value` | the status as text next to it or in the element's name |
91
+
92
+ - A destructive or failed state is `severity="danger"` on `hx-tag` and `hx-badge`, `severity="error"` on
93
+ `hx-message` and toasts.
94
+ - The status severities (`success`, `info`, `warn`, `danger`, `error`) report a state. They rank no action
95
+ ([button hierarchy](components.md#button-hierarchy)).
96
+ - App CSS reads no palette step (`--h-red-*`, `--h-green-*`, `--h-orange-*`, `--h-sky-*` and the other hues) to show
97
+ a status.
98
+
99
+ ## Literals and tints
100
+
101
+ - App CSS has no hex color and no `rgb()`, `rgba()`, `hsl()` or `hsla()`. The Stylelint config of
102
+ [`@gravionlabs/helix-lint`](https://gravionlabs.github.io/helix/LINT) blocks them (`color-no-hex`, `function-disallowed-list`); an exception is a
103
+ `helixAllow` entry with a reason.
104
+ - A color in app CSS is a `var(--h-…)` token, `transparent`, `currentColor`, `inherit`, or a `color-mix()` of these.
105
+ - A tint or shade is a `color-mix()` on a token, mixed with `transparent` or another token. It follows the primary
106
+ color and the color scheme; a second literal does not.
107
+ - Text on a tint is `--h-text-color`, and keeps at least 4.5:1 on it in light and dark.
108
+
109
+ ```css
110
+ .skipped-row {
111
+ background: color-mix(in srgb, var(--h-text-muted-color), transparent 90%);
112
+ color: var(--h-text-color);
113
+ }
114
+ ```
115
+
116
+ ## Not carried yet
117
+
118
+ These have no Helix carrier and are therefore no rule yet:
119
+
120
+ - A status color for markup the app draws itself: there is no semantic status token.
121
+ - A lint check for named colors, other color functions (`hwb()`, `lab()`, `lch()`, `oklab()`, `oklch()`, `color()`),
122
+ literals inside `color-mix()`, and styles in `.ts` or `.html` files. Review covers them.
@@ -0,0 +1,150 @@
1
+ # Components
2
+
3
+ Deep dive of the [UX style guide](STYLEGUIDE.md): read it when you add or change a button, a list or any other
4
+ control, or before you build a component. It says which Helix part does which job. Inputs and accessibility of each
5
+ part are on its [component page](https://gravionlabs.github.io/helix/components/).
6
+
7
+ ## Reuse before building
8
+
9
+ Take the first step that solves the job:
10
+
11
+ 1. A Helix component or directive of the [component reference](https://gravionlabs.github.io/helix/components/), with its inputs.
12
+ 2. A composition of Helix components, laid out by an element of the app with `--h-space-*` gaps.
13
+ 3. A Helix component with other values of its `--h-*` tokens ([Theming](https://gravionlabs.github.io/helix/THEMING)).
14
+ 4. An app component built from Helix parts and `--h-*` tokens. The PR names what Helix lacks and links a Helix issue
15
+ for it.
16
+
17
+ An app has no component that redraws a Helix one, and no CSS rule on an `.hx-*` class that changes its look.
18
+
19
+ ## Which primitive replaces which raw element
20
+
21
+ `helix/no-raw-control` of the [lint preset](https://gravionlabs.github.io/helix/LINT) reports these elements in `.html` templates. The same rules
22
+ hold for inline templates, which the lint run does not check.
23
+
24
+ | Instead of | Use |
25
+ | ------------------------------ | -------------------------------------------------------------------------------------------------- |
26
+ | `<button>` for an action | `button[hx-button]` |
27
+ | `<button>` that is a row | `button[hx-list-row]` in an `hx-list` |
28
+ | `<button>` that stays pressed | [`hx-toggle-button`](https://gravionlabs.github.io/helix/components/toggle-button) |
29
+ | `<input>` for text | `input[hx-input]` |
30
+ | `<input type="checkbox">` | `input[hx-checkbox]`, or `input[hx-switch]` for a setting in effect at once |
31
+ | `<input type="radio">` | `input[hx-radio]` |
32
+ | `<input type="number">` | [`hx-input-number`](https://gravionlabs.github.io/helix/components/input-number) |
33
+ | `<input type="password">` | [`hx-password`](https://gravionlabs.github.io/helix/components/password) |
34
+ | `<input type="range">` | [`hx-slider`](https://gravionlabs.github.io/helix/components/slider) |
35
+ | `<input>` for a date or a time | [`hx-date-picker`](https://gravionlabs.github.io/helix/components/date-picker), [`hx-time-picker`](https://gravionlabs.github.io/helix/components/time-picker) |
36
+ | `<input type="file">` | [`hx-file-upload`](https://gravionlabs.github.io/helix/components/file-upload) |
37
+ | `<textarea>` | `textarea[hx-input]` |
38
+ | `<select>` | [`hx-select`](https://gravionlabs.github.io/helix/components/select) |
39
+ | `<select multiple>` | [`hx-multi-select`](https://gravionlabs.github.io/helix/components/multi-select) |
40
+ | `<progress>` | [`hx-progress-bar`](https://gravionlabs.github.io/helix/components/progress) |
41
+
42
+ `<input type="hidden">` stays raw. For the control of a form value see
43
+ [Which control for which value](forms.md#which-control-for-which-value).
44
+
45
+ ## Button hierarchy
46
+
47
+ `variant` says how loud an [`hx-button`](https://gravionlabs.github.io/helix/components/button) is, `severity` what it means. The job picks both;
48
+ `size` follows [the row](#button-size).
49
+
50
+ | Job | Element | `variant` | `severity` |
51
+ | --------------------------------- | ----------------------------------- | ------------------ | -------------------------- |
52
+ | Primary action of a view | `button[hx-button]` | `filled` (default) | `primary` (default) |
53
+ | Secondary action | `button[hx-button]` | `filled` | `secondary` |
54
+ | Cancel, close, dismiss | `button[hx-button]` | `text` | `secondary` |
55
+ | Toolbar action | `button[hx-button]` | `text` | `secondary` |
56
+ | Row trigger (open, choose a row) | `button[hx-list-row]` | none | none |
57
+ | Action in a table cell | `button[hx-button]` | `text` | `secondary` |
58
+ | Link that looks like a button | `a[hx-button]` | by its job above | by its job above |
59
+ | Link-styled action or destination | `button[hx-button]`, `a[hx-button]` | `link` | `primary` (default) |
60
+ | Starts a destructive action | `button[hx-button]` | `outlined` | `danger` |
61
+ | The same in a toolbar or a cell | `button[hx-button]` | `text` | `danger` |
62
+ | Confirms a destructive action | `HxConfirmationService` | `filled` | `acceptSeverity: 'danger'` |
63
+
64
+ - A view or dialog has at most one filled primary `hx-button`; a primary action in its toolbar is that one.
65
+ - An action takes `primary`, `secondary` or `danger`. `success`, `info`, `warn`, `help` and `contrast` rank no
66
+ action.
67
+ - A control with a URL (`href` or `routerLink`) is an `a`; every other action is a `button`. A link inside a
68
+ sentence is a plain `<a>`.
69
+ - A disabled button has `disabled`, a disabled `a[hx-button]` has `aria-disabled="true"`.
70
+ - A `button` in a `<form>` that does not submit it has `type="button"`.
71
+
72
+ ```html
73
+ <button hx-button (click)="create()">Create branch</button>
74
+ <button hx-button severity="secondary" (click)="fetch()">Fetch</button>
75
+ <button hx-button variant="outlined" severity="danger" (click)="confirmDelete()">Delete branch</button>
76
+ <a hx-button variant="link" routerLink="/settings">Open settings</a>
77
+ ```
78
+
79
+ ### Icon-only buttons
80
+
81
+ - It is an `hx-button` with `iconOnly`, with the `variant` and `severity` of its job.
82
+ - It has an `aria-label` and an `hx-tooltip` with the same text.
83
+ - Its icon is an inline `<svg>` or an element with the class `hx-button-icon`, with `aria-hidden="true"`.
84
+
85
+ ```html
86
+ <button hx-button iconOnly variant="text" severity="secondary" aria-label="Refresh" hx-tooltip="Refresh">
87
+ <span class="hx-button-icon pi pi-refresh" aria-hidden="true"></span>
88
+ </button>
89
+ ```
90
+
91
+ ### Several actions together
92
+
93
+ | Need | Use |
94
+ | ------------------------------------------ | ----------------------------------------------------------------------- |
95
+ | One default action and related ones | [`hx-split-button`](https://gravionlabs.github.io/helix/components/split-button) |
96
+ | Several actions behind one trigger | an `hx-button` that opens an [`hx-menu`](https://gravionlabs.github.io/helix/components/menu) `popup` |
97
+ | Buttons that read as one control | [`hx-button-group`](https://gravionlabs.github.io/helix/components/button-group) |
98
+ | On or off that stays visible | [`hx-toggle-button`](https://gravionlabs.github.io/helix/components/toggle-button) |
99
+ | One or several of a few, applied as chosen | [`hx-select-button`](https://gravionlabs.github.io/helix/components/select-button) |
100
+ | The actions of a view | [`hx-toolbar`](https://gravionlabs.github.io/helix/components/toolbar) with its start, center and end |
101
+
102
+ ## Button size
103
+
104
+ Controls of the same `size` have the same height: `hx-button`, `hx-input` and `hx-select` read the same form field
105
+ tokens. So a row has one size.
106
+
107
+ | Row | `size` of its controls |
108
+ | -------------------------------- | ------------------------------------------------------- |
109
+ | Form, with its buttons | default (`medium`) |
110
+ | `hx-toolbar` | `small`, on every control in it that has a `size` input |
111
+ | List row | none: the row is the control, sized by `--h-list-row-*` |
112
+ | Header or footer of an `hx-list` | `small` |
113
+ | Table cell | `small` |
114
+
115
+ - `size="large"` is not used in any of these rows.
116
+ - The [density option](https://gravionlabs.github.io/helix/THEMING#density) (`density: 'compact'`, `HxTheme.setDensity`) scales all rows alike. No
117
+ screen picks another `size` to look denser, and the app sets no height, padding or font size on a control.
118
+
119
+ ```html
120
+ <hx-toolbar>
121
+ <button hxToolbarStart hx-button size="small" variant="text" severity="secondary">Fetch</button>
122
+ <input hxToolbarEnd hx-input size="small" aria-label="Filter branches" />
123
+ </hx-toolbar>
124
+ ```
125
+
126
+ ## Lists
127
+
128
+ - A list of things to open or choose (sidebar, search results, outline, picker) is an `hx-list` of
129
+ [`hx-list-row`](https://gravionlabs.github.io/helix/components/list-row)s, not a column of `hx-button`s or clickable `div`s.
130
+ - The list has an `aria-label` or `aria-labelledby`.
131
+ - A row is a `button type="button"` for an action or an `a` for a destination. It holds no other button, link or
132
+ field.
133
+ - Its content sits in `.hx-list-row-icon`, `.hx-list-row-label` and `.hx-list-row-meta`.
134
+ - The chosen row has `selected`, the open page or item has `current`. The app draws neither state itself.
135
+ - `role="listbox"` is for a list whose rows are the options of a choice.
136
+
137
+ | Need | Use |
138
+ | ----------------------------------------- | ----------------------------------------------------------------------------------------------- |
139
+ | A form value chosen from an inline list | [`hx-listbox`](https://gravionlabs.github.io/helix/components/listbox) |
140
+ | A popup of commands | [`hx-menu`](https://gravionlabs.github.io/helix/components/menu) |
141
+ | Rows with columns, small and static | [`table[hx-table]`](https://gravionlabs.github.io/helix/components/table) |
142
+ | Columns with sorting, paging or selection | [`hx-data-table`](https://gravionlabs.github.io/helix/components/data-table), or AG Grid through `@gravionlabs/helix-ag-grid` |
143
+ | A hierarchy | [`hx-tree`](https://gravionlabs.github.io/helix/components/tree) |
144
+
145
+ ## Not carried yet
146
+
147
+ These have no Helix carrier and are therefore no rule yet:
148
+
149
+ - A second action on a list row, such as a trailing remove button:
150
+ [#1256](https://github.com/GravionLabs/helix/issues/1256).
@@ -0,0 +1,120 @@
1
+ # Dialogs
2
+
3
+ Deep dive of the [UX style guide](STYLEGUIDE.md): read it when you add or change a dialog or a confirmation. It says
4
+ how a dialog is built from Helix parts. The fields inside it follow [forms.md](forms.md).
5
+
6
+ ## Dialog or popover
7
+
8
+ [Which element for what](ux-rules.md#which-element-for-what) decides. A dialog is an
9
+ [`hx-dialog`](https://gravionlabs.github.io/helix/components/dialog), a question with two answers is a [confirmation](#confirmations).
10
+
11
+ ## Header and size
12
+
13
+ - A dialog has a `header`. One without a visible title has an `ariaLabel`.
14
+ - The width is the `size` input (`sm`, `md`, `lg`), picked by [what the dialog holds](https://gravionlabs.github.io/helix/components/dialog#sizes).
15
+ `width` is only for content that fits no class, and the PR says why.
16
+ - No app CSS sets the width of a dialog. A class that is wrong for the whole app is changed by its
17
+ `--h-dialog-<size>-width` token.
18
+
19
+ ## Footer
20
+
21
+ The actions of a dialog are `hx-button`s in the footer.
22
+
23
+ - Each button has the `hxDialogFooter` attribute itself. No wrapper element holds them: `--h-dialog-footer-gap` spaces
24
+ only the direct children of the footer.
25
+ - A footer has exactly one primary action: the one `hx-button` with the filled `variant` and the `primary` severity
26
+ (both the defaults). Every other button takes the `variant` and `severity` of its job in the
27
+ [button hierarchy](components.md#button-hierarchy), so none of them is `primary` and filled.
28
+ - Order in the template, which is the order on screen: secondary actions first, the primary action last.
29
+ - Cancel is `variant="text"` and `severity="secondary"`, never `danger`.
30
+ - A destructive action is `severity="danger"` and names what it does ("Delete"). Next to a primary action it is
31
+ `variant="outlined"` and the first button of the footer, so Cancel stands between it and the primary action. A
32
+ dialog whose main action is destructive is a [confirmation](#confirmations).
33
+ - Every button but a submit button is `type="button"`.
34
+ - The gap above the footer is the bottom of `--h-dialog-content-padding`. The app adds no margin, padding or spacer
35
+ between content and footer.
36
+
37
+ ```html
38
+ <hx-dialog [(visible)]="open" header="Edit profile" size="md">
39
+ <form id="profile-form" [formGroup]="form" (ngSubmit)="save()">
40
+ <hx-field label="Name" required>
41
+ <input hx-input formControlName="name" />
42
+ </hx-field>
43
+ </form>
44
+
45
+ <button hxDialogFooter hx-button type="button" variant="text" severity="secondary" (click)="cancel()">Cancel</button>
46
+ <button hxDialogFooter hx-button type="submit" form="profile-form" [loading]="saving()">Save</button>
47
+ </hx-dialog>
48
+ ```
49
+
50
+ ## Default focus
51
+
52
+ `hx-dialog` focuses the element with `cdkFocusInitial`; without one, the first element in the dialog that can be
53
+ tabbed to, in DOM order: header, content, footer, close button. It focuses the dialog itself when there is none, and
54
+ gives the focus back when it closes.
55
+
56
+ - A dialog with a form starts on its first field: the field is the first tabbable element of the content, so the app
57
+ does nothing. If a link or button comes before it, the field has `cdkFocusInitial`.
58
+ - A dialog without a field starts on its primary action: that button has `cdkFocusInitial`. Without it the focus
59
+ lands on the first link or button, often Cancel.
60
+ - The app calls no `focus()` of its own when a dialog opens.
61
+
62
+ ## Enter
63
+
64
+ - The fields of a dialog sit in a `<form>` with an `id`. The primary button is `type="submit"` and names that id in
65
+ its `form` attribute, because the footer is outside the form. Enter in a field then submits.
66
+ - The app binds no Enter key handler. Submit and validation follow [forms.md](forms.md#validation).
67
+
68
+ ## Escape and unsaved changes
69
+
70
+ - Escape and the close button close the dialog (`closeOnEscape` and `closable`, both on by default). The app switches
71
+ them off only while closing would lose something.
72
+ - `dismissableMask` stays off for a dialog with a form.
73
+ - While the dialog has unsaved changes, `closeOnEscape` and `closable` are `false`, and Cancel asks through
74
+ `HxConfirmationService` before it closes. Once nothing is unsaved, both are on again.
75
+
76
+ ```html
77
+ <hx-dialog [(visible)]="open" header="Edit profile" [closable]="!form.dirty" [closeOnEscape]="!form.dirty">
78
+ ```
79
+
80
+ ```ts
81
+ async cancel(): Promise<void> {
82
+ const discard =
83
+ !this.form.dirty ||
84
+ (await this.confirmation.confirmAsync({
85
+ header: 'Discard changes',
86
+ message: 'Your changes are not saved.',
87
+ acceptLabel: 'Discard',
88
+ rejectLabel: 'Keep editing',
89
+ acceptSeverity: 'danger',
90
+ }));
91
+ if (!discard) return;
92
+ this.form.reset();
93
+ this.open.set(false);
94
+ }
95
+ ```
96
+
97
+ ## Confirmations
98
+
99
+ - A question before an action is asked with [`HxConfirmationService`](https://gravionlabs.github.io/helix/components/confirm), never with an
100
+ `hx-dialog` the app builds. [Confirm or undo](ux-rules.md#confirm-or-undo) says when to ask.
101
+ - The app has one `<hx-confirm-dialog />` (and one `<hx-confirm-popup />` if it passes a `target`).
102
+ - Every question sets `acceptLabel` to the verb of the action and `rejectLabel` to "Cancel" or to what rejecting
103
+ does ("Keep editing"). The defaults "Yes" and "No" are not used.
104
+ - A destructive question sets `acceptSeverity: 'danger'`.
105
+
106
+ ## Service dialogs
107
+
108
+ `HxDialogService` opens a component in a dialog. It has no `size`, its component cannot fill the footer, and its
109
+ `closeOnEscape` and `closable` are fixed when it opens. A dialog with actions, a form or a size class is therefore an
110
+ `hx-dialog` in a template.
111
+
112
+ ## Not carried yet
113
+
114
+ ADR 0008, decision 3: what Helix does not carry is no rule here.
115
+
116
+ - `hx-dialog` does not ask before Escape or the close button discard changes; they are off instead:
117
+ [#1253](https://github.com/GravionLabs/helix/issues/1253).
118
+ - The footer has no separate place at its start for a destructive action:
119
+ [#1255](https://github.com/GravionLabs/helix/issues/1255).
120
+ - `HxDialogService` has no footer and no `size`: [#1254](https://github.com/GravionLabs/helix/issues/1254).