flexui-react 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 +98 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +6 -6
- package/package.json +38 -37
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# flexui-react
|
|
2
|
+
|
|
3
|
+
React hooks for FlexUI's interactive components. They bind the
|
|
4
|
+
[flexui-runtime](https://www.npmjs.com/package/flexui-runtime) controllers to
|
|
5
|
+
your components, dispose them on unmount, and mirror state such as whether a
|
|
6
|
+
dialog is open into React so your UI re-renders when a dialog closes from the
|
|
7
|
+
keyboard or from a backdrop click.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install flexui-runtime flexui-react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react` (19 or newer) is a peer dependency.
|
|
14
|
+
|
|
15
|
+
## Dialog
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { useDialog } from "flexui-react";
|
|
19
|
+
|
|
20
|
+
export function Settings() {
|
|
21
|
+
const { ref, open, close, isOpen } = useDialog({ closeOnBackdrop: true });
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<button className="fui-btn" onClick={open}>Settings</button>
|
|
26
|
+
<dialog ref={ref} className="fui-dialog" data-fui-dialog>
|
|
27
|
+
<h2>Settings</h2>
|
|
28
|
+
<button className="fui-btn" onClick={close}>Done</button>
|
|
29
|
+
</dialog>
|
|
30
|
+
</>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`useDialog(options)` returns `ref`, `open()`, `close()`, `toggle()` and `isOpen`.
|
|
36
|
+
Options are read when the dialog is first bound.
|
|
37
|
+
|
|
38
|
+
## Dropdown
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
const { ref, isOpen, open, close } = useDropdown("#account-menu");
|
|
42
|
+
|
|
43
|
+
<button ref={ref} className="fui-btn" aria-haspopup="menu">Account</button>
|
|
44
|
+
<div id="account-menu" role="menu">…</div>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`useDropdown(target, options)` accepts a selector or the menu element itself and
|
|
48
|
+
returns the trigger `ref` plus the open state.
|
|
49
|
+
|
|
50
|
+
## Popover
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
const { ref, isOpen } = usePopover("#filters");
|
|
54
|
+
|
|
55
|
+
<button ref={ref} className="fui-btn">Filters</button>
|
|
56
|
+
<div id="filters" popover>…</div>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Tabs
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
const { ref, activeIndex, select } = useTabs();
|
|
63
|
+
|
|
64
|
+
<div ref={ref} className="fui-tabs" data-fui-tabs>
|
|
65
|
+
<div role="tablist">…</div>
|
|
66
|
+
</div>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The hook binds the tablist, keeps roving tabindex working and tracks the active
|
|
70
|
+
tab in state.
|
|
71
|
+
|
|
72
|
+
## Theme
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
const { mode, resolved, setMode } = useTheme();
|
|
76
|
+
|
|
77
|
+
<button className="fui-btn" onClick={() => setMode(mode === "dark" ? "light" : "dark")}>
|
|
78
|
+
{resolved === "dark" ? "Light mode" : "Dark mode"}
|
|
79
|
+
</button>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`useTheme()` reads the current mode, re-renders on `fui:themechange` and exposes
|
|
83
|
+
`setMode("light" | "dark" | "system")`.
|
|
84
|
+
|
|
85
|
+
## Styling
|
|
86
|
+
|
|
87
|
+
The hooks handle behaviour only. Class names come from the FlexUI compiler, so
|
|
88
|
+
the same markup works whether or not the hooks are mounted.
|
|
89
|
+
|
|
90
|
+
## Documentation
|
|
91
|
+
|
|
92
|
+
See the [FlexUI repository](https://github.com/Ahaduzzamankhan/flexui#readme) and
|
|
93
|
+
[docs/runtime.md](https://github.com/Ahaduzzamankhan/flexui/blob/main/docs/runtime.md)
|
|
94
|
+
for the underlying controllers, markup contracts and events.
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React bindings for
|
|
2
|
+
* React bindings for `flexui-runtime`.
|
|
3
3
|
*
|
|
4
4
|
* The hooks own the controller lifecycle: they bind on mount, dispose on
|
|
5
5
|
* unmount, and mirror the controller's open state into React state so a
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
* outside it. Component CSS still works without any of this.
|
|
8
8
|
*/
|
|
9
9
|
import { type RefObject } from "react";
|
|
10
|
-
import { type DialogOptions } from "
|
|
11
|
-
import { type DropdownOptions } from "
|
|
12
|
-
import { type PopoverOptions } from "
|
|
13
|
-
import { type ResolvedTheme, type ThemeMode } from "
|
|
10
|
+
import { type DialogOptions } from "flexui-runtime/dialog";
|
|
11
|
+
import { type DropdownOptions } from "flexui-runtime/dropdown";
|
|
12
|
+
import { type PopoverOptions } from "flexui-runtime/popover";
|
|
13
|
+
import { type ResolvedTheme, type ThemeMode } from "flexui-runtime/theme";
|
|
14
14
|
export interface UseDialogResult {
|
|
15
15
|
/** Attach to the `<dialog>` element. */
|
|
16
16
|
ref: RefObject<HTMLDialogElement | null>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React bindings for
|
|
2
|
+
* React bindings for `flexui-runtime`.
|
|
3
3
|
*
|
|
4
4
|
* The hooks own the controller lifecycle: they bind on mount, dispose on
|
|
5
5
|
* unmount, and mirror the controller's open state into React state so a
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* outside it. Component CSS still works without any of this.
|
|
8
8
|
*/
|
|
9
9
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
10
|
-
import { bindDialog } from "
|
|
11
|
-
import { bindDropdown } from "
|
|
12
|
-
import { bindPopover } from "
|
|
13
|
-
import { bindTabs } from "
|
|
14
|
-
import { getResolvedTheme, getTheme, setTheme, toggleTheme, } from "
|
|
10
|
+
import { bindDialog } from "flexui-runtime/dialog";
|
|
11
|
+
import { bindDropdown } from "flexui-runtime/dropdown";
|
|
12
|
+
import { bindPopover } from "flexui-runtime/popover";
|
|
13
|
+
import { bindTabs } from "flexui-runtime/tabs";
|
|
14
|
+
import { getResolvedTheme, getTheme, setTheme, toggleTheme, } from "flexui-runtime/theme";
|
|
15
15
|
/**
|
|
16
16
|
* Mirrors a controller's open state into React state. The ref is read inside
|
|
17
17
|
* the effect, after React has attached it, which is why the element itself is
|
package/package.json
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "flexui-react",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
4
|
-
"description": "React hooks for FlexUI interactive components",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"main": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js",
|
|
13
|
-
"default": "./dist/index.js"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"files": [
|
|
17
|
-
"dist"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "flexui-react",
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
4
|
+
"description": "React hooks for FlexUI interactive components",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"flexui-runtime": "2.0.0-alpha.3"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": "^19.3.1"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"flexui",
|
|
32
|
+
"react",
|
|
33
|
+
"hooks"
|
|
34
|
+
],
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "^19.3.3"
|
|
37
|
+
}
|
|
38
|
+
}
|