flexui-runtime 2.0.0-alpha.2 → 2.0.0-alpha.3
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/README.md +73 -37
- package/dist/command.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,52 +1,79 @@
|
|
|
1
|
-
#
|
|
1
|
+
# flexui-runtime
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The optional browser runtime for FlexUI components. It adds keyboard
|
|
4
|
+
behaviour, focus management, ARIA state and DOM events on top of native
|
|
5
|
+
`<dialog>`, the popover API and your existing markup. The CSS works on its own;
|
|
6
|
+
this package is what makes the interactive components feel finished.
|
|
7
|
+
|
|
8
|
+
Zero dependencies, ESM, about as small as a runtime can be.
|
|
4
9
|
|
|
5
10
|
```bash
|
|
6
|
-
npm install
|
|
11
|
+
npm install flexui-runtime
|
|
7
12
|
```
|
|
8
13
|
|
|
9
|
-
```
|
|
10
|
-
import { init } from "
|
|
14
|
+
```js
|
|
15
|
+
import { init } from "flexui-runtime";
|
|
11
16
|
|
|
12
|
-
const
|
|
17
|
+
const cleanup = init();
|
|
13
18
|
```
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
Call `init()` once per page. It scans the document for the data attributes below
|
|
21
|
+
and returns a cleanup function that unbinds everything it attached.
|
|
22
|
+
|
|
23
|
+
## What it handles
|
|
24
|
+
|
|
25
|
+
- **Dialogs and drawers** — backdrop dismissal, Escape, scroll locking, focus
|
|
26
|
+
trap and focus restoration to the element that opened them.
|
|
27
|
+
- **Dropdown menus** — arrow, Home and End navigation, roving focus, dismissal
|
|
28
|
+
on outside click.
|
|
29
|
+
- **Popovers** — native popover API with viewport-aware positioning.
|
|
30
|
+
- **Tabs** — roving tabindex, automatic activation, horizontal and vertical
|
|
31
|
+
orientation.
|
|
32
|
+
- **Toasts** — polite live region, a four-toast cap, pause on hover or focus, and
|
|
33
|
+
a sticky option.
|
|
34
|
+
- **Command palette** — Ctrl/Cmd+K, multi-term filtering, active descendant and
|
|
35
|
+
events.
|
|
36
|
+
- **Theme switching** — light, dark and system, with `localStorage` and
|
|
37
|
+
`prefers-color-scheme`.
|
|
38
|
+
- **Focus helpers** — `focusable`, `focusFirst` and `trapFocus` for your own
|
|
39
|
+
widgets.
|
|
40
|
+
|
|
41
|
+
## Markup
|
|
27
42
|
|
|
28
43
|
| Feature | Markup |
|
|
29
44
|
| --- | --- |
|
|
30
|
-
| Dialog | `<dialog class="fui-dialog" data-fui-dialog
|
|
45
|
+
| Dialog | `<dialog class="fui-dialog" data-fui-dialog>`, opened with `data-fui-open="#id"` and closed with `data-fui-close` |
|
|
31
46
|
| Drawer | `<dialog class="fui-drawer" data-fui-drawer data-fui-side="right">` |
|
|
32
|
-
| Dropdown | `data-fui-dropdown="#menu"`
|
|
33
|
-
| Popover | `data-fui-popover="#panel"`
|
|
34
|
-
| Tabs | `data-fui-tabs`
|
|
47
|
+
| Dropdown | `data-fui-dropdown="#menu"` on the trigger, `role="menu"` on the items |
|
|
48
|
+
| Popover | `data-fui-popover="#panel"` on the trigger, `popover` on the panel |
|
|
49
|
+
| Tabs | `data-fui-tabs` with `role="tablist"`, `role="tab"` and `role="tabpanel"` |
|
|
35
50
|
| Toast | `toast({ title, description, variant, duration })` |
|
|
36
|
-
| Command palette | `data-fui-command`
|
|
51
|
+
| Command palette | `data-fui-command` plus the input, list and item attributes |
|
|
37
52
|
| Theme | `data-fui-theme-set="light\|dark\|system"` or `data-fui-theme-toggle` |
|
|
38
53
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
## Per-feature entry points
|
|
55
|
+
|
|
56
|
+
Importing the whole runtime is convenient; importing one module keeps the rest
|
|
57
|
+
out of your bundle. Every feature has its own entry:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { initDialogs } from "flexui-runtime/dialog";
|
|
61
|
+
import { initDrawers } from "flexui-runtime/drawer";
|
|
62
|
+
import { initDropdowns } from "flexui-runtime/dropdown";
|
|
63
|
+
import { initPopovers } from "flexui-runtime/popover";
|
|
64
|
+
import { initTabs } from "flexui-runtime/tabs";
|
|
65
|
+
import { toast } from "flexui-runtime/toast";
|
|
66
|
+
import { initCommand } from "flexui-runtime/command";
|
|
67
|
+
import { setTheme, getTheme, initTheme } from "flexui-runtime/theme";
|
|
68
|
+
import { focusFirst, trapFocus } from "flexui-runtime/focus";
|
|
45
69
|
```
|
|
46
70
|
|
|
71
|
+
`flexui-runtime/auto` is a side-effect entry that initialises everything as soon
|
|
72
|
+
as the DOM is ready.
|
|
73
|
+
|
|
47
74
|
## Events
|
|
48
75
|
|
|
49
|
-
|
|
76
|
+
Every event bubbles and is cancelable.
|
|
50
77
|
|
|
51
78
|
| Event | Detail |
|
|
52
79
|
| --- | --- |
|
|
@@ -58,14 +85,23 @@ All events bubble and are cancelable.
|
|
|
58
85
|
| `fui:command` | `{ value, label, item, palette }` |
|
|
59
86
|
| `fui:themechange` | `{ mode, resolved }` |
|
|
60
87
|
|
|
61
|
-
##
|
|
62
|
-
|
|
63
|
-
The full guide lives in [docs/runtime.md](https://github.com/Ahaduzzamankhan/flexui/blob/main/docs/runtime.md).
|
|
88
|
+
## Theming
|
|
64
89
|
|
|
65
|
-
|
|
90
|
+
```js
|
|
91
|
+
import { setTheme, getTheme } from "flexui-runtime/theme";
|
|
66
92
|
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
setTheme("dark"); // "light" | "dark" | "system"
|
|
94
|
+
getTheme(); // { mode: "dark", resolved: "dark" }
|
|
69
95
|
```
|
|
70
96
|
|
|
71
|
-
|
|
97
|
+
Theme state is stored under a configurable key, so several sites on one origin
|
|
98
|
+
can keep independent preferences.
|
|
99
|
+
|
|
100
|
+
## Documentation
|
|
101
|
+
|
|
102
|
+
The full guide, including every option and the complete event list, lives in
|
|
103
|
+
[docs/runtime.md](https://github.com/Ahaduzzamankhan/flexui/blob/main/docs/runtime.md).
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
package/dist/command.js
CHANGED
|
@@ -26,7 +26,7 @@ export class CommandPalette {
|
|
|
26
26
|
const input = element.querySelector("[data-fui-command-input], input[role='combobox'], input");
|
|
27
27
|
const list = element.querySelector("[data-fui-command-list], [role='listbox']");
|
|
28
28
|
if (!input || !list) {
|
|
29
|
-
throw new Error("
|
|
29
|
+
throw new Error("flexui-runtime: command palette needs an input and a list");
|
|
30
30
|
}
|
|
31
31
|
this.input = input;
|
|
32
32
|
this.list = list;
|