actual-css 0.16.1 → 0.17.0
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/CHANGELOG.md +64 -0
- package/README.md +8 -4
- package/components.json +19 -4
- package/dist/actual.full.css +393 -69
- package/dist/actual.full.js +2 -1
- package/dist/actual.full.min.css +1 -1
- package/docs/design-notes/app-ui.md +37 -3
- package/docs/design-notes/enhancement-contract.md +3 -1
- package/docs/navigation.json +14 -1
- package/docs/pages/components/alert.md +45 -17
- package/docs/pages/components/button.md +3 -0
- package/docs/pages/components/dialog.md +36 -0
- package/docs/pages/components/drawer.md +52 -8
- package/docs/pages/components/navbar.md +26 -2
- package/docs/pages/components/rating.md +111 -12
- package/docs/pages/components/segmented.md +36 -1
- package/docs/pages/components/spinner.md +2 -0
- package/docs/pages/components/table.md +77 -0
- package/docs/pages/components/timeline.md +3 -1
- package/docs/pages/enhancements/flyout.md +83 -14
- package/docs/pages/enhancements/tabs.md +5 -0
- package/docs/pages/examples/overview.md +5 -1
- package/docs/pages/forms/ajax.md +101 -0
- package/docs/pages/forms/color-swatches.md +31 -2
- package/docs/pages/forms/joined-controls.md +8 -3
- package/docs/pages/forms/overview.md +1 -1
- package/docs/pages/forms/unsaved-changes.md +198 -0
- package/docs/pages/foundations/philosophy.md +2 -1
- package/docs/pages/foundations/theming.md +2 -1
- package/docs/pages/foundations/tokens.md +1 -1
- package/docs/pages/guides/introduction.md +1 -1
- package/docs/pages/guides/progressive-enhancement.md +30 -49
- package/docs/pages/guides/upgrading.md +15 -2
- package/docs/pages/layout/choosing.md +5 -0
- package/docs/pages/layout/column-layout.md +22 -8
- package/docs/pages/layout/sidebar-shell.md +68 -0
- package/docs/pages/patterns/empty-state.md +74 -0
- package/docs/pages/patterns/hierarchical-nav.md +40 -19
- package/docs/pages/patterns/navigation-list.md +3 -60
- package/docs/pages/patterns/stat.md +61 -0
- package/docs/pages/utilities/accessibility.md +32 -10
- package/package.json +4 -1
- package/reserved-classes.json +2 -0
- package/src/css/components/busy.css +25 -0
- package/src/css/components/button.css +3 -0
- package/src/css/components/drawer.css +37 -3
- package/src/css/components/flyout.css +37 -0
- package/src/css/components/modal.css +3 -0
- package/src/css/components/navbar.css +99 -38
- package/src/css/components/rating.css +50 -5
- package/src/css/components/segmented.css +25 -2
- package/src/css/forms/color-swatch.css +38 -19
- package/src/css/forms/custom-select.css +5 -0
- package/src/css/layout/index.css +2 -0
- package/src/css/layout/sidebar-shell.css +67 -0
- package/src/js/ajax.js +148 -0
- package/src/js/dialog.js +59 -2
- package/src/js/dirty.js +140 -0
- package/src/js/dismiss.js +25 -0
- package/src/js/events.js +17 -0
- package/src/js/focus.js +12 -0
- package/src/js/form-submission.js +34 -0
- package/src/js/full.js +2 -0
- package/src/js/tab.js +16 -2
- package/src/js/validation.js +12 -4
- package/src/tooling/theme-contrast.js +3 -2
|
@@ -98,6 +98,75 @@ table width before the wrapper scrolls horizontally.
|
|
|
98
98
|
</div>
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
## Sticky headers
|
|
102
|
+
|
|
103
|
+
Frozen header row, fixed header, frozen first column. `.table-wrap` scrolls
|
|
104
|
+
horizontally, which makes it a scroll container on both axes: a sticky
|
|
105
|
+
`thead` sticks inside the wrap, never to the page. Pick the scroller first.
|
|
106
|
+
|
|
107
|
+
**Header stuck to the page.** `overflow: clip` keeps the wrap's rounded clip
|
|
108
|
+
without making it a scroll container, so the header sticks to the page. The
|
|
109
|
+
wrap no longer scrolls: use it for a table that fits its column.
|
|
110
|
+
|
|
111
|
+
```css
|
|
112
|
+
.members-table {
|
|
113
|
+
overflow: clip;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.members-table thead th {
|
|
117
|
+
position: sticky;
|
|
118
|
+
inset-block-start: 0; /* the height of a sticky page header, if any */
|
|
119
|
+
background: var(--table-header-bg, var(--surface-subtle));
|
|
120
|
+
box-shadow: inset 0 calc(var(--border-width) * -1) var(--border);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Header and first column stuck in a scroll box.** Give the wrap a block size;
|
|
125
|
+
the header row sticks to its top and the row headers to its inline start.
|
|
126
|
+
|
|
127
|
+
```css
|
|
128
|
+
.revenue-table {
|
|
129
|
+
max-block-size: 24rem;
|
|
130
|
+
overflow: auto;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.revenue-table thead th {
|
|
134
|
+
position: sticky;
|
|
135
|
+
inset-block-start: 0;
|
|
136
|
+
z-index: 1;
|
|
137
|
+
background: var(--table-header-bg, var(--surface-subtle));
|
|
138
|
+
box-shadow: inset 0 calc(var(--border-width) * -1) var(--border);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.revenue-table thead th:first-child {
|
|
142
|
+
inset-inline-start: 0;
|
|
143
|
+
z-index: 2;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.revenue-table tbody th {
|
|
147
|
+
position: sticky;
|
|
148
|
+
inset-inline-start: 0;
|
|
149
|
+
background: var(--surface-raised);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.revenue-table tbody tr:hover > th {
|
|
153
|
+
background-image: linear-gradient(var(--hover-overlay), var(--hover-overlay));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.revenue-table th[scope="rowgroup"] > span {
|
|
157
|
+
position: sticky;
|
|
158
|
+
inset-block-start: 3rem; /* below the header row */
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
- Sticky cells need an opaque fill, or the rows scroll through them. The fill
|
|
163
|
+
also hides the row's hover band, so the hover rule repaints it on the cell.
|
|
164
|
+
- A collapsed border stays with the table, not the cell: the header's rule is
|
|
165
|
+
an inset shadow so it travels with the row.
|
|
166
|
+
- A row-group label (`th scope="rowgroup"` with `rowspan`) cannot stick as a
|
|
167
|
+
cell; wrap its text, and the wrapper sticks inside the spanning cell.
|
|
168
|
+
- Keep `role="region"`, `aria-labelledby` and `tabindex="0"` on the scroll box.
|
|
169
|
+
|
|
101
170
|
## Compact tables
|
|
102
171
|
|
|
103
172
|
`.compact` lowers cell padding and establishes compact density for controls or
|
|
@@ -124,6 +193,14 @@ vocabulary as `.card.compact`.
|
|
|
124
193
|
</div>
|
|
125
194
|
```
|
|
126
195
|
|
|
196
|
+
## Sliding row hover
|
|
197
|
+
|
|
198
|
+
The core hover switches each row's background instantly. For a highlight that
|
|
199
|
+
slides from row to row (animated hover, moving indicator), a theme anchors one
|
|
200
|
+
layer to the hovered row with CSS anchor positioning; the `material` theme in
|
|
201
|
+
`src/css/themes/material.css` is a recipe to copy. Browsers without anchor
|
|
202
|
+
positioning keep the core hover.
|
|
203
|
+
|
|
127
204
|
## When a table stops reading as a table
|
|
128
205
|
|
|
129
206
|
Responsive strategy is horizontal overflow: the wrap scrolls, the table keeps
|
|
@@ -13,7 +13,9 @@ log, changelog, order tracking.
|
|
|
13
13
|
For progress through a process (checkout, onboarding), use
|
|
14
14
|
[Steps](steps.md): a timeline records what happened, steps show where you
|
|
15
15
|
are. For a horizontal, alternating or time-scaled chronology, or a Gantt
|
|
16
|
-
chart, render a diagram: see [Diagrams](diagrams.md).
|
|
16
|
+
chart, render a diagram: see [Diagrams](diagrams.md). For release notes with
|
|
17
|
+
the version beside the rail, see the
|
|
18
|
+
[Changelog template](../../demo/templates/changelog.html).
|
|
17
19
|
|
|
18
20
|
## Basic usage
|
|
19
21
|
|
|
@@ -2,25 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
> Positioned surface attached to a trigger, commonly used for action lists and small panels.
|
|
4
4
|
|
|
5
|
-
**Related terms:** popover, dropdown, dropdown menu, action menu, context menu, bottom sheet, action sheet, anchored panel.
|
|
5
|
+
**Related terms:** popover, dropdown, dropdown menu, action menu, context menu, bottom sheet, action sheet, anchored panel, filter panel, sticky footer, apply button.
|
|
6
6
|
|
|
7
7
|
## Class reference
|
|
8
8
|
|
|
9
|
-
| Class | Kind | Description
|
|
10
|
-
| ----------------- | ----------- |
|
|
11
|
-
| `.flyout-trigger` | Composition | Positioning wrapper for trigger and panel.
|
|
12
|
-
| `.stretch` | Modifier | Spans a `.flyout-trigger` to its container.
|
|
13
|
-
| `.flyout` | Component | Floating surface, positioned by JavaScript.
|
|
14
|
-
| `.
|
|
15
|
-
| `.menu
|
|
16
|
-
| `.menu-item
|
|
17
|
-
| `.menu-item-
|
|
18
|
-
| `.menu-item-
|
|
9
|
+
| Class | Kind | Description |
|
|
10
|
+
| ----------------- | ----------- | ---------------------------------------------- |
|
|
11
|
+
| `.flyout-trigger` | Composition | Positioning wrapper for trigger and panel. |
|
|
12
|
+
| `.stretch` | Modifier | Spans a `.flyout-trigger` to its container. |
|
|
13
|
+
| `.flyout` | Component | Floating surface, positioned by JavaScript. |
|
|
14
|
+
| `.scrollable` | Modifier | Header and footer stay while the body scrolls. |
|
|
15
|
+
| `.menu` | Component | Action-list primitive. |
|
|
16
|
+
| `.menu-item` | Component | One action row; joins roving focus. |
|
|
17
|
+
| `.menu-item-icon` | Slot | Fixed leading column for an icon. |
|
|
18
|
+
| `.menu-item-text` | Slot | Flexible label column; truncates. |
|
|
19
|
+
| `.menu-item-end` | Slot | Trailing shortcut, badge or status. |
|
|
20
|
+
| `.menu-label` | Variant | Muted, non-interactive group heading. |
|
|
21
|
+
| `.menu-separator` | Variant | Divider between menu groups (`<hr>`). |
|
|
22
|
+
| `.sm` / `.lg` | Size | Smaller or larger menu rows and type. |
|
|
19
23
|
|
|
20
24
|
`.menu` has a strict `.menu > li > .menu-item` anatomy.
|
|
21
|
-
| `.menu-label` | Variant | Muted section heading inside a menu; not interactive. |
|
|
22
|
-
| `.menu-separator` | Variant | Divider between menu groups (`<hr>`). |
|
|
23
|
-
| `.sm` / `.lg` | Size | Smaller or larger menu rows and type. |
|
|
24
25
|
|
|
25
26
|
## Usage
|
|
26
27
|
|
|
@@ -432,6 +433,74 @@ a separate `dialog.drawer` when the content needs a modal mobile presentation.
|
|
|
432
433
|
</nav>
|
|
433
434
|
```
|
|
434
435
|
|
|
436
|
+
## Panel with actions
|
|
437
|
+
|
|
438
|
+
A filter, picker or quick-edit panel with an Apply row: a `<form>` as the
|
|
439
|
+
flyout, named by its visible title. A named form is a landmark, which is the
|
|
440
|
+
name the panel needs; do not add `role="dialog"`, since the flyout runtime is
|
|
441
|
+
not a non-modal dialog manager. Use `data-flyout-auto-close="outside"` so
|
|
442
|
+
clicks inside the form keep it open.
|
|
443
|
+
|
|
444
|
+
Add `.scrollable` to keep the header and footer in view while the body
|
|
445
|
+
scrolls: a long option list, or a panel the positioner squeezes near the
|
|
446
|
+
viewport edge, keeps its Apply button on screen. The panel takes a `<header>`,
|
|
447
|
+
one body region and a `<footer>`; a menu or a multi-section nav panel has no
|
|
448
|
+
single body and stays without it. Columns go inside the body.
|
|
449
|
+
|
|
450
|
+
```html demo
|
|
451
|
+
<div class="flyout-trigger">
|
|
452
|
+
<button class="btn outline"
|
|
453
|
+
type="button"
|
|
454
|
+
data-enhance="flyout"
|
|
455
|
+
aria-expanded="false"
|
|
456
|
+
aria-controls="issue-filters">
|
|
457
|
+
<i class="ti ti-filter" aria-hidden="true"></i>
|
|
458
|
+
Filters
|
|
459
|
+
</button>
|
|
460
|
+
|
|
461
|
+
<form class="flyout scrollable"
|
|
462
|
+
id="issue-filters"
|
|
463
|
+
aria-labelledby="issue-filters-title"
|
|
464
|
+
data-flyout-auto-close="outside"
|
|
465
|
+
style="--flyout-pad: var(--space-30)"
|
|
466
|
+
hidden>
|
|
467
|
+
<header><strong id="issue-filters-title">Labels</strong></header>
|
|
468
|
+
<div class="stack">
|
|
469
|
+
<label><input type="checkbox" name="label" value="bug"> Bug</label>
|
|
470
|
+
<label><input type="checkbox" name="label" value="feature"> Feature</label>
|
|
471
|
+
<label><input type="checkbox" name="label" value="docs"> Docs</label>
|
|
472
|
+
<label><input type="checkbox" name="label" value="chore"> Chore</label>
|
|
473
|
+
<label><input type="checkbox" name="label" value="security"> Security</label>
|
|
474
|
+
<label><input type="checkbox" name="label" value="performance"> Performance</label>
|
|
475
|
+
<label><input type="checkbox" name="label" value="design"> Design</label>
|
|
476
|
+
<label><input type="checkbox" name="label" value="infra"> Infra</label>
|
|
477
|
+
<label><input type="checkbox" name="label" value="release"> Release</label>
|
|
478
|
+
<label><input type="checkbox" name="label" value="question"> Question</label>
|
|
479
|
+
<label><input type="checkbox" name="label" value="support"> Support</label>
|
|
480
|
+
<label><input type="checkbox" name="label" value="triage"> Needs triage</label>
|
|
481
|
+
</div>
|
|
482
|
+
<footer class="cluster justify-content-end">
|
|
483
|
+
<button class="btn ghost sm" type="reset">Reset</button>
|
|
484
|
+
<button class="btn primary sm" type="button" data-flyout-close>Apply</button>
|
|
485
|
+
</footer>
|
|
486
|
+
</form>
|
|
487
|
+
</div>
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
`data-flyout-close` closes on click, before the form validates or submits.
|
|
491
|
+
That suits a panel applying local values, as above. A form that validates or
|
|
492
|
+
saves keeps the control a plain submit button and closes from its success
|
|
493
|
+
path, so an invalid field or a failed save leaves the panel open:
|
|
494
|
+
|
|
495
|
+
```js
|
|
496
|
+
import { closeSurface } from "actual-css/js/surface";
|
|
497
|
+
|
|
498
|
+
form.addEventListener("submit", async (event) => {
|
|
499
|
+
event.preventDefault();
|
|
500
|
+
if (await save(new FormData(form))) closeSurface(form);
|
|
501
|
+
});
|
|
502
|
+
```
|
|
503
|
+
|
|
435
504
|
## Context menu
|
|
436
505
|
|
|
437
506
|
Context menus use the same `.menu > li > .menu-item` presentation primitive as
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
by the arrow keys. An application filtering a tab strip only has to set
|
|
34
34
|
`hidden`; deciding what to show when the selected tab is filtered out is the
|
|
35
35
|
application's call.
|
|
36
|
+
- `actual:tab-change` bubbles from the tablist after the user selects another
|
|
37
|
+
tab, with `{ tab, panel, previousTab }`. It cannot be canceled and does not
|
|
38
|
+
fire at connect: read `aria-selected` for the initial tab. Use it to sync
|
|
39
|
+
content outside the panels, such as a summary card that follows the selected
|
|
40
|
+
tab.
|
|
36
41
|
|
|
37
42
|
```html demo
|
|
38
43
|
<div class="tabs" data-enhance="tabs" role="tablist" aria-label="Settings">
|
|
@@ -7,6 +7,9 @@ and `actual.full.js` from `dist/`, plus the theme palettes bundle from
|
|
|
7
7
|
`demo/assets/`. Both are build output: in a clone, run `bun run build:dist`,
|
|
8
8
|
`bun run build:js` and `bun run build:themes` before opening a page.
|
|
9
9
|
|
|
10
|
+
For copy-paste blocks (marketing sections, application screens, navigation)
|
|
11
|
+
with their HTML and CSS, see [Actual Blocks](https://github.com/lekoala/actual-blocks).
|
|
12
|
+
|
|
10
13
|
## Templates
|
|
11
14
|
|
|
12
15
|
`demo/templates/` are standalone pages. The first three explain the system; the
|
|
@@ -28,7 +31,8 @@ Whole pages, composed the way a real product would.
|
|
|
28
31
|
- [Workspaces](../../demo/templates/workspaces.html) - sectioned sidebar, master/detail list with native current state, and workspace cards
|
|
29
32
|
- [Marketing](../../demo/templates/marketing.html) - landing page with typography and fluid type
|
|
30
33
|
- [Blog](../../demo/templates/blog.html) - article page with prose
|
|
31
|
-
- [
|
|
34
|
+
- [Changelog](../../demo/templates/changelog.html) - release notes on a `.timeline`: version and date beside the rail on wide containers, and a light on the rail that runs from the first release to the last as the page scrolls
|
|
35
|
+
- [Settings modal](../../demo/templates/settings-modal.html) - two-pane preferences dialog opening on load with `data-dialog-open`, with the local CSS it needs audited rule by rule
|
|
32
36
|
- [Modal patterns](../../demo/templates/modal-patterns.html) - eight application modals, each the modal surface plus the smallest application CSS it needs
|
|
33
37
|
- [Workspace settings](../../demo/templates/settings-pricing.html) - plans with visible native choices, preferences and segmented tabs
|
|
34
38
|
- [iOS-style settings](../../demo/templates/settings-ios.html) - iOS-like controls and grouped settings from unchanged framework markup, a local theme, and its findings listed rule by rule
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Ajax Submission
|
|
2
|
+
|
|
3
|
+
> Submit a form with `fetch` and show the server's HTML answer in place.
|
|
4
|
+
|
|
5
|
+
**Related terms:** ajax form, async submit, fetch form, submit without reload, remote form.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Opt in with `data-enhance="ajax"` on a form whose `action` and `method` work
|
|
10
|
+
without JavaScript. With `data-ajax-target`, the HTML answer replaces the
|
|
11
|
+
target's content.
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<form class="stack" action="/contact" method="post"
|
|
15
|
+
data-enhance="validation ajax" data-ajax-target="#contact-feedback">
|
|
16
|
+
<label class="field">
|
|
17
|
+
<span class="field-label">Email</span>
|
|
18
|
+
<input class="input" type="email" name="email" required />
|
|
19
|
+
</label>
|
|
20
|
+
<div class="cluster form-actions">
|
|
21
|
+
<button class="btn primary" type="submit">Send</button>
|
|
22
|
+
</div>
|
|
23
|
+
</form>
|
|
24
|
+
<div id="contact-feedback" role="status"></div>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The request carries what a native submission would: the submitter's name and
|
|
28
|
+
value, its `formaction`, `formmethod` and `formenctype`, files as multipart or
|
|
29
|
+
by name when URL-encoded, and `GET` data as the query string. It sends
|
|
30
|
+
`X-Requested-With: XMLHttpRequest`, so the server can answer with a fragment
|
|
31
|
+
instead of a page.
|
|
32
|
+
|
|
33
|
+
The browser keeps the submissions the module cannot reproduce:
|
|
34
|
+
`method="dialog"`, `enctype="text/plain"`, a `target`, `formtarget` or
|
|
35
|
+
`<base target>` other than `_self`, and an `action` on another origin.
|
|
36
|
+
`form.submit()` bypasses the module too; use `form.requestSubmit()`.
|
|
37
|
+
|
|
38
|
+
## Request state
|
|
39
|
+
|
|
40
|
+
While a request runs, the form and its submitter carry `aria-busy="true"`,
|
|
41
|
+
which picks up the [busy button](../components/button.md) styles. Add a
|
|
42
|
+
`.spinner` inside the button for a visible indicator, or as the form's last
|
|
43
|
+
child for a [busy overlay](../components/spinner.md#busy-state) that fades in
|
|
44
|
+
only when the request is slow; give the element `aria-busy="false"` so the
|
|
45
|
+
spinner stays hidden at rest, the module restores it after each request.
|
|
46
|
+
Further submissions are
|
|
47
|
+
ignored until the answer arrives; a submission left to the browser, such as a
|
|
48
|
+
dialog's cancel button, still goes through. Removing the form aborts its
|
|
49
|
+
request.
|
|
50
|
+
|
|
51
|
+
To cancel a submission, call `preventDefault()` on its `submit` event from a
|
|
52
|
+
listener on the form. The `validation` enhancer does so for an invalid form.
|
|
53
|
+
|
|
54
|
+
## Responses
|
|
55
|
+
|
|
56
|
+
The target is updated when the response is `text/html` with a 2xx or `422`
|
|
57
|
+
status, the usual status for server-rendered errors. Any other answer leaves
|
|
58
|
+
it alone. The answer is read as UTF-8. The target may contain the form: a
|
|
59
|
+
server that re-renders the whole form with its errors replaces it, and the new
|
|
60
|
+
form is enhanced again. A CSRF token in a hidden field is sent like any other
|
|
61
|
+
field; when the server issues a new token per submission, re-render the form
|
|
62
|
+
with the answer, or the next submission sends a spent token. A redirect, such as post/redirect/get, navigates the
|
|
63
|
+
page; `fetch` has already followed it, so the destination loads twice.
|
|
64
|
+
|
|
65
|
+
Every response reaches `actual:ajax-response` with
|
|
66
|
+
`{ form, submitter, response }`, after the target update or before a redirect
|
|
67
|
+
navigates; check `response.ok`. A network failure reaches `actual:ajax-error`
|
|
68
|
+
with `{ form, submitter, error }`. `actual:ajax-start` marks the beginning of
|
|
69
|
+
a request. The events bubble from the form, or from the document when the
|
|
70
|
+
update replaced it; listen on the document. None of them can be canceled.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
document.addEventListener("actual:ajax-response", ({ detail }) => {
|
|
74
|
+
if (detail.response.ok) detail.form.reset();
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## With unsaved changes
|
|
79
|
+
|
|
80
|
+
The module never decides that a response means "saved". With
|
|
81
|
+
[Unsaved Changes](unsaved-changes.md), clear the dirty state from the
|
|
82
|
+
application, using the data that was sent:
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
import { FormDirty } from "actual-css/js/dirty";
|
|
86
|
+
|
|
87
|
+
const sent = new WeakMap();
|
|
88
|
+
document.addEventListener("actual:ajax-start", ({ detail }) => {
|
|
89
|
+
sent.set(detail.form, FormDirty.capture(detail.form));
|
|
90
|
+
});
|
|
91
|
+
document.addEventListener("actual:ajax-response", ({ detail }) => {
|
|
92
|
+
if (detail.response.ok) FormDirty.markClean(detail.form, sent.get(detail.form));
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Edits made during the request stay dirty.
|
|
97
|
+
|
|
98
|
+
## Beyond one form
|
|
99
|
+
|
|
100
|
+
The module answers one submission with one target. Navigation, history, DOM
|
|
101
|
+
morphing and coordinated region updates belong to a dedicated library.
|
|
@@ -7,11 +7,24 @@
|
|
|
7
7
|
`.color-swatch` is a `<label>` wrapping a native radio, with the color in
|
|
8
8
|
`--color-swatch-value`. The radio stays the control: it submits, takes the
|
|
9
9
|
arrow keys and carries the name in `aria-label`. The checked swatch shows a
|
|
10
|
-
|
|
10
|
+
ring around the color, which reads on any color and any background. Use
|
|
11
|
+
checkboxes for several colors at once.
|
|
11
12
|
|
|
12
13
|
For a free color, use the native [`.color`](controls.md) picker; a custom
|
|
13
14
|
spectrum or RGB sliders are outside Actual.
|
|
14
15
|
|
|
16
|
+
## Anatomy
|
|
17
|
+
|
|
18
|
+
```text
|
|
19
|
+
fieldset.field-group.cluster the palette, or a .grid; spaced with --gap
|
|
20
|
+
├── legend
|
|
21
|
+
└── label.color-swatch ×N, --color-swatch-value
|
|
22
|
+
└── input[type="radio"] aria-label names the color; checkbox for several
|
|
23
|
+
|
|
24
|
+
button.color-swatch flyout trigger, --color-swatch-value
|
|
25
|
+
└── .sr-only the current color's name
|
|
26
|
+
```
|
|
27
|
+
|
|
15
28
|
## Palette
|
|
16
29
|
|
|
17
30
|
Lay the swatches out with `.cluster` or `.grid`, and space them with `--gap`
|
|
@@ -31,6 +44,21 @@ the column count with `--grid-columns: repeat(6, max-content)` on `.grid`.
|
|
|
31
44
|
</fieldset>
|
|
32
45
|
```
|
|
33
46
|
|
|
47
|
+
## Shape
|
|
48
|
+
|
|
49
|
+
Set `--color-swatch-radius` on the palette for square or rounded swatches; the
|
|
50
|
+
selection ring follows the corners.
|
|
51
|
+
|
|
52
|
+
```html demo
|
|
53
|
+
<fieldset class="field-group cluster" style="--color-swatch-radius: var(--radius-sm)">
|
|
54
|
+
<legend>Label color</legend>
|
|
55
|
+
<label class="color-swatch" style="--color-swatch-value: #7c3aed"><input type="radio" name="label" value="#7c3aed" aria-label="Violet" checked></label>
|
|
56
|
+
<label class="color-swatch" style="--color-swatch-value: #0891b2"><input type="radio" name="label" value="#0891b2" aria-label="Cyan"></label>
|
|
57
|
+
<label class="color-swatch" style="--color-swatch-value: #65a30d"><input type="radio" name="label" value="#65a30d" aria-label="Lime"></label>
|
|
58
|
+
<label class="color-swatch" style="--color-swatch-value: #111827"><input type="radio" name="label" value="#111827" aria-label="Black"></label>
|
|
59
|
+
</fieldset>
|
|
60
|
+
```
|
|
61
|
+
|
|
34
62
|
## Palette in a flyout
|
|
35
63
|
|
|
36
64
|
A `<button class="color-swatch">` shows the current color and opens the
|
|
@@ -128,4 +156,5 @@ The color dialog is the browser's own and looks different on each platform.
|
|
|
128
156
|
- `--color-swatch-value` — the color, set on each swatch.
|
|
129
157
|
- `--color-swatch-size` — visible swatch size, the height of a `.switch` track
|
|
130
158
|
by default. `.sm` and `.lg` scale it and the hit area.
|
|
131
|
-
- `--color-swatch-radius` — corner radius; round by default.
|
|
159
|
+
- `--color-swatch-radius` — corner radius; round by default. Inherited, so one
|
|
160
|
+
declaration on the palette shapes every swatch.
|
|
@@ -15,7 +15,12 @@ choice among a few on a shared track, use a
|
|
|
15
15
|
| `.join` | Composition | Joins adjacent controls into a single unit. |
|
|
16
16
|
| `.join-addon` | Composition | Static prefix or suffix content. |
|
|
17
17
|
|
|
18
|
-
Add `.join` to the wrapper that groups the controls. Use `.join-addon` for static prefix/suffix content such as currency symbols, units, or protocol text. Action buttons inside the group should use `.btn`.
|
|
18
|
+
Add `.join` to the wrapper that groups the controls. Use `.join-addon` for static prefix/suffix content such as currency symbols, units, or protocol text. Action buttons inside the group should use `.btn`.
|
|
19
|
+
|
|
20
|
+
Give the wrapper `role="group"` and a label when it holds several controls
|
|
21
|
+
that act as a set, such as a button group. A labelled input with an addon or
|
|
22
|
+
one attached button takes no group role: the field label already names the
|
|
23
|
+
input, and the group would repeat it.
|
|
19
24
|
|
|
20
25
|
Each child keeps its own variant. Use the same variant across the group, and
|
|
21
26
|
change it only to mark state, such as a solid pressed toggle among outlines.
|
|
@@ -25,8 +30,8 @@ controls it groups so joined corners take precedence.
|
|
|
25
30
|
|
|
26
31
|
```html demo
|
|
27
32
|
<div class="field">
|
|
28
|
-
<label class="field-label"
|
|
29
|
-
<div class="join"
|
|
33
|
+
<label class="field-label" for="amount">Amount</label>
|
|
34
|
+
<div class="join">
|
|
30
35
|
<span class="join-addon">$</span>
|
|
31
36
|
<input class="input" id="amount" name="amount" inputmode="decimal" />
|
|
32
37
|
<button class="btn outline" type="button">Clear</button>
|
|
@@ -197,7 +197,7 @@ root; keyboard focus and an open custom select keep it.
|
|
|
197
197
|
- For a switch, use `class="switch"` and `role="switch"`.
|
|
198
198
|
- `.range` skins the native range control (`appearance: none` track, thumb, and focus ring). Add `data-enhance="range"` for the fill share, named `datalist` values, and output sync.
|
|
199
199
|
- `.form-actions` is the role of a `.cluster` row (`class="cluster form-actions"`) and carries no outer margin: `.stack` on the form spaces it from the fields. It is class-only and may live inside or outside `<form>`. See Detached Actions below.
|
|
200
|
-
- `.join` visually joins adjacent controls into a single unit. Use `.join-addon` for static prefix/suffix content. The container
|
|
200
|
+
- `.join` visually joins adjacent controls into a single unit. Use `.join-addon` for static prefix/suffix content. The container carries `role="group"` and a label only when it holds several controls acting as a set.
|
|
201
201
|
|
|
202
202
|
## Optional automatic required marks
|
|
203
203
|
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Unsaved Changes
|
|
2
|
+
|
|
3
|
+
> Track whether a form holds data that differs from what was last saved.
|
|
4
|
+
|
|
5
|
+
**Related terms:** dirty form, modified form, unsaved edits, leave page warning, discard changes.
|
|
6
|
+
|
|
7
|
+
## Dirty state
|
|
8
|
+
|
|
9
|
+
Opt in with `data-enhance="dirty"` on the form. While the data it would submit
|
|
10
|
+
differs from its baseline, the form carries `data-dirty`. The baseline is the
|
|
11
|
+
data present when the form is enhanced.
|
|
12
|
+
|
|
13
|
+
```html demo
|
|
14
|
+
<form class="stack" data-enhance="dirty">
|
|
15
|
+
<label class="field">
|
|
16
|
+
<span class="field-label">Name</span>
|
|
17
|
+
<input class="input" name="name" value="Alice" />
|
|
18
|
+
</label>
|
|
19
|
+
<div class="cluster form-actions">
|
|
20
|
+
<button class="btn primary" type="submit">Save</button>
|
|
21
|
+
<button class="btn neutral outline" type="reset">Reset</button>
|
|
22
|
+
</div>
|
|
23
|
+
</form>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Style the state from application CSS, for example a hint shown only while there
|
|
27
|
+
is something to save:
|
|
28
|
+
|
|
29
|
+
```css
|
|
30
|
+
form:not([data-dirty]) .save-hint { visibility: hidden; }
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The comparison covers what a submission would send: disabled and unnamed
|
|
34
|
+
controls do not count, controls associated through `form="…"` and
|
|
35
|
+
form-associated custom elements do. Add `data-dirty-ignore` to a control to
|
|
36
|
+
leave its name out, such as a CSRF token. Files compare by name, size and
|
|
37
|
+
modification time.
|
|
38
|
+
|
|
39
|
+
Each comparison fires the form's `formdata` event. An entry a listener adds
|
|
40
|
+
there counts too, so a volatile one (a nonce) keeps the form dirty: give it the
|
|
41
|
+
name of a hidden `data-dirty-ignore` input.
|
|
42
|
+
|
|
43
|
+
`actual:dirty-change` bubbles from the form after each transition, with
|
|
44
|
+
`{ form, dirty }`. It reports the state and cannot be canceled.
|
|
45
|
+
|
|
46
|
+
The module is part of the full runtime and importable on its own as
|
|
47
|
+
`actual-css/js/dirty`. It works alongside `validation` and never submits the
|
|
48
|
+
form or blocks navigation.
|
|
49
|
+
|
|
50
|
+
## After saving
|
|
51
|
+
|
|
52
|
+
A native submission reloads the page and the new form starts clean. When the
|
|
53
|
+
form stays on the page, tell the module what was saved:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { FormDirty } from "actual-css/js/dirty";
|
|
57
|
+
|
|
58
|
+
const snapshot = FormDirty.capture(form); // when the request starts
|
|
59
|
+
// … request succeeds …
|
|
60
|
+
FormDirty.markClean(form, snapshot);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Passing the snapshot keeps edits made during the request dirty. Without one,
|
|
64
|
+
`markClean()` accepts the current data. A failed or rejected save should not
|
|
65
|
+
call it.
|
|
66
|
+
|
|
67
|
+
Edits through events update the state on their own. After setting values or
|
|
68
|
+
adding controls from code, call `FormDirty.refresh(form)`. A widget with no
|
|
69
|
+
form control of its own (a canvas, a sortable list) marks the form dirty by
|
|
70
|
+
writing its state to a hidden input, then calling `refresh()`.
|
|
71
|
+
|
|
72
|
+
Reset restores the HTML default values, which are the baseline only until the
|
|
73
|
+
first `markClean()`. A removed and reinserted form keeps its baseline. A form
|
|
74
|
+
replaced by new server markup starts a new one, even when the save failed.
|
|
75
|
+
|
|
76
|
+
With the [Ajax Submission](ajax.md) enhancer, wire the snapshot to its events
|
|
77
|
+
as shown there.
|
|
78
|
+
|
|
79
|
+
## Autosave
|
|
80
|
+
|
|
81
|
+
Save a `form[data-autosave]` after a pause in typing, without a submit
|
|
82
|
+
button. The form keeps its `action` and `method`, so it still saves without
|
|
83
|
+
JavaScript.
|
|
84
|
+
|
|
85
|
+
```html
|
|
86
|
+
<form class="stack" action="/notes" method="post" data-enhance="dirty" data-autosave>
|
|
87
|
+
<label class="field">
|
|
88
|
+
<span class="field-label">Notes</span>
|
|
89
|
+
<textarea class="input" name="notes" required></textarea>
|
|
90
|
+
</label>
|
|
91
|
+
<p class="muted" aria-hidden="true">
|
|
92
|
+
<span data-autosave-when="dirty">Saving…</span>
|
|
93
|
+
<span data-autosave-when="clean">All changes saved</span>
|
|
94
|
+
</p>
|
|
95
|
+
<noscript><button class="btn primary" type="submit">Save</button></noscript>
|
|
96
|
+
</form>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```css
|
|
100
|
+
form[data-dirty] [data-autosave-when="clean"],
|
|
101
|
+
form:not([data-dirty]) [data-autosave-when="dirty"] { display: none; }
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
import { FormDirty } from "actual-css/js/dirty";
|
|
106
|
+
import { status } from "actual-css/js/status";
|
|
107
|
+
|
|
108
|
+
const DELAY = 1500; // idle time before saving
|
|
109
|
+
const timers = new WeakMap();
|
|
110
|
+
|
|
111
|
+
const schedule = (form) => {
|
|
112
|
+
clearTimeout(timers.get(form));
|
|
113
|
+
timers.set(form, setTimeout(() => save(form), DELAY));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
async function save(form) {
|
|
117
|
+
if (!form.hasAttribute("data-dirty")) return;
|
|
118
|
+
if (form.getAttribute("aria-busy") === "true") return; // the running save reschedules
|
|
119
|
+
// checkValidity() stays silent; requestSubmit() would show errors mid-typing.
|
|
120
|
+
if (!form.checkValidity()) return;
|
|
121
|
+
|
|
122
|
+
const snapshot = FormDirty.capture(form);
|
|
123
|
+
form.setAttribute("aria-busy", "true");
|
|
124
|
+
try {
|
|
125
|
+
const response = await fetch(form.action, { method: form.method, body: new FormData(form) });
|
|
126
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
127
|
+
FormDirty.markClean(form, snapshot);
|
|
128
|
+
if (form.hasAttribute("data-dirty")) schedule(form); // typed during the request
|
|
129
|
+
} catch {
|
|
130
|
+
status("Changes not saved. Check your connection.", { intent: "danger" });
|
|
131
|
+
} finally {
|
|
132
|
+
form.removeAttribute("aria-busy");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
document.addEventListener("input", ({ target }) => {
|
|
137
|
+
if (target.form?.matches("[data-autosave]")) schedule(target.form);
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
- Edits made during a request stay dirty and trigger the next save.
|
|
142
|
+
- Invalid data is never saved. The form stays dirty until it becomes valid.
|
|
143
|
+
- A failed save is not retried in a loop. The next edit tries again, and the
|
|
144
|
+
warning below still protects the page.
|
|
145
|
+
- The status bar reports failures only. Announcing every successful save
|
|
146
|
+
would interrupt screen readers at each pause; the inline state is hidden
|
|
147
|
+
from them for the same reason.
|
|
148
|
+
|
|
149
|
+
## Warning before leaving
|
|
150
|
+
|
|
151
|
+
The module does not guard navigation. This recipe asks for confirmation when
|
|
152
|
+
the page unloads with a dirty form, except the one being submitted natively:
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
let lastSubmit = null;
|
|
156
|
+
// Read at unload time, once every submit listener has had its say: a
|
|
157
|
+
// canceled submission (validation, Ajax), a dialog close or a submission into
|
|
158
|
+
// another window or frame does not leave.
|
|
159
|
+
const leavesBySubmit = (form) => {
|
|
160
|
+
if (lastSubmit?.target !== form || lastSubmit.defaultPrevented) return false;
|
|
161
|
+
const { submitter } = lastSubmit;
|
|
162
|
+
// Attributes, not form.method / form.target: a control with that name
|
|
163
|
+
// shadows the property. An empty formtarget="" still means the page itself.
|
|
164
|
+
const method = submitter?.getAttribute("formmethod") ?? form.getAttribute("method") ?? "";
|
|
165
|
+
const target =
|
|
166
|
+
submitter?.getAttribute("formtarget") ??
|
|
167
|
+
form.getAttribute("target") ??
|
|
168
|
+
document.querySelector("base[target]")?.getAttribute("target") ??
|
|
169
|
+
"";
|
|
170
|
+
if (target && !["_self", "_top", "_parent"].includes(target.toLowerCase())) return false;
|
|
171
|
+
return method.toLowerCase() !== "dialog";
|
|
172
|
+
};
|
|
173
|
+
const guard = (event) => {
|
|
174
|
+
for (const form of document.querySelectorAll("form[data-dirty]")) {
|
|
175
|
+
if (leavesBySubmit(form)) continue;
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
event.returnValue = true; // Chromium before 119
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
document.addEventListener("submit", (event) => { lastSubmit = event; });
|
|
183
|
+
addEventListener("pageshow", () => { lastSubmit = null; });
|
|
184
|
+
|
|
185
|
+
// Register only while needed: some browsers skip the back/forward cache for
|
|
186
|
+
// pages that listen to beforeunload.
|
|
187
|
+
document.addEventListener("actual:dirty-change", () => {
|
|
188
|
+
if (document.querySelector("form[data-dirty]")) addEventListener("beforeunload", guard);
|
|
189
|
+
else removeEventListener("beforeunload", guard);
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`beforeunload` covers reloads, closing the tab and full-page navigation.
|
|
194
|
+
Navigation inside the page (a client router, a region swap) does not fire it:
|
|
195
|
+
guard it in that router. Mobile browsers may skip the prompt when the page is
|
|
196
|
+
discarded in the background. A submission answered with a download keeps the
|
|
197
|
+
page, but the recipe cannot tell in advance: that form stays unguarded until
|
|
198
|
+
the next submission.
|
|
@@ -166,7 +166,8 @@ inside them. `.sm` on a plain element has no effect.
|
|
|
166
166
|
|
|
167
167
|
Density affects controls and layout spacing. Badges, avatars, spinners,
|
|
168
168
|
ratings, keys, prose, and inline choices keep their own size. One density
|
|
169
|
-
class applies to the whole subtree
|
|
169
|
+
class applies to the whole subtree; for a product-wide density, put
|
|
170
|
+
`class="compact"` on `<html>`:
|
|
170
171
|
|
|
171
172
|
```html demo
|
|
172
173
|
<div class="compact stack">
|
|
@@ -273,6 +273,7 @@ lets the core derive everything else.
|
|
|
273
273
|
- `gradient`: outer focus halos on fields.
|
|
274
274
|
- `neo-brutalist`: hard shadows, pastel fills, and plus-shaped accordion
|
|
275
275
|
markers. Use it as a page skin: its rules cross nested theme boundaries.
|
|
276
|
-
- `material`: filled underline fields and
|
|
276
|
+
- `material`: filled underline fields, pill buttons, and a table hover that
|
|
277
|
+
slides between rows.
|
|
277
278
|
- `glass`: translucent surfaces over a backdrop. Keep `--surface-opaque` and
|
|
278
279
|
`--surface-solid-fg` opaque, and check soft fills against the actual backdrop.
|