@zag-js/toolbar 2.0.0-next.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.
@@ -0,0 +1,148 @@
1
+ import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { PropTypes, Orientation, RequiredBy, DirectionProperty, CommonProperties } from '@zag-js/types';
3
+ export { Orientation } from '@zag-js/types';
4
+
5
+ type ElementIds = Partial<{
6
+ root: string;
7
+ item: (value: string) => string;
8
+ group: (value: string) => string;
9
+ }>;
10
+ interface ToolbarProps extends DirectionProperty, CommonProperties {
11
+ /**
12
+ * The ids of the elements in the toolbar. Useful for composition.
13
+ */
14
+ ids?: ElementIds | undefined;
15
+ /**
16
+ * Whether the toolbar is disabled. This cascades into every item's
17
+ * effective `disabled` state, but never affects `getLinkProps`.
18
+ */
19
+ disabled?: boolean | undefined;
20
+ /**
21
+ * The orientation of the toolbar.
22
+ * @default "horizontal"
23
+ */
24
+ orientation?: Orientation | undefined;
25
+ /**
26
+ * Whether to loop focus inside the toolbar when navigating with the keyboard.
27
+ * @default true
28
+ */
29
+ loopFocus?: boolean | undefined;
30
+ }
31
+ type PropsWithDefault = "orientation" | "loopFocus";
32
+ interface PrivateContext {
33
+ /**
34
+ * The value of the item that currently holds the roving tabindex.
35
+ * Persists across blur, so tabbing away and back resumes at the same item.
36
+ */
37
+ focusedValue: string | null;
38
+ /**
39
+ * Whether the root has ever redirected focus to an item. Once true, the root
40
+ * permanently cedes its own tabindex to whichever item is tracked.
41
+ */
42
+ hasInteracted: boolean;
43
+ /**
44
+ * Whether the toolbar was focused by a click.
45
+ */
46
+ isClickFocus: boolean;
47
+ }
48
+ interface ToolbarSchema {
49
+ props: RequiredBy<ToolbarProps, PropsWithDefault>;
50
+ context: PrivateContext;
51
+ state: "idle" | "focused";
52
+ event: EventObject;
53
+ action: string;
54
+ guard: string;
55
+ effect: string;
56
+ }
57
+ type ToolbarService = Service<ToolbarSchema>;
58
+ type ToolbarMachine = Machine<ToolbarSchema>;
59
+ interface ItemProps {
60
+ /**
61
+ * The unique value of the item.
62
+ */
63
+ value: string;
64
+ /**
65
+ * Whether the item is disabled.
66
+ */
67
+ disabled?: boolean | undefined;
68
+ /**
69
+ * Whether the item remains focusable (and reachable via arrow keys) while disabled.
70
+ * Keeping disabled controls in the roving tabindex sequence makes them discoverable.
71
+ * @default true
72
+ */
73
+ focusableWhenDisabled?: boolean | undefined;
74
+ }
75
+ interface ItemState {
76
+ /**
77
+ * The underlying id of the item.
78
+ */
79
+ id: string;
80
+ /**
81
+ * Whether the item is disabled. When `focusableWhenDisabled` is `true`, guard your
82
+ * own action handler with this, e.g. `onClick={itemState.disabled ? undefined : fn}`.
83
+ */
84
+ disabled: boolean;
85
+ /**
86
+ * Whether the item remains focusable (and reachable via arrow keys) while disabled.
87
+ */
88
+ focusableWhenDisabled: boolean;
89
+ /**
90
+ * Whether the item is the current roving tabindex target.
91
+ */
92
+ focused: boolean;
93
+ /**
94
+ * The orientation of the toolbar this item belongs to.
95
+ */
96
+ orientation: Orientation;
97
+ }
98
+ interface LinkProps {
99
+ /**
100
+ * The unique value of the link.
101
+ */
102
+ value: string;
103
+ }
104
+ interface GroupProps {
105
+ /**
106
+ * The unique value of the group.
107
+ */
108
+ value: string;
109
+ /**
110
+ * Whether the group is disabled. This is a purely visual/ARIA concern —
111
+ * it does not automatically cascade into the disabled state of items
112
+ * rendered inside it. Thread it into each item's own `disabled` prop, e.g.
113
+ * `api.getItemProps({ value, disabled: groupDisabled || itemDisabled })`.
114
+ */
115
+ disabled?: boolean | undefined;
116
+ }
117
+ interface ToolbarApi<T extends PropTypes = PropTypes> {
118
+ /**
119
+ * Whether the toolbar is disabled.
120
+ */
121
+ disabled: boolean;
122
+ /**
123
+ * The value of the item that is currently focused, if any.
124
+ */
125
+ focusedValue: string | null;
126
+ /**
127
+ * The orientation of the toolbar.
128
+ */
129
+ orientation: Orientation;
130
+ /**
131
+ * Returns the resolved DOM id for the given item value. Useful for aligning
132
+ * a composed machine's own id (e.g. `select`'s `ids.trigger`) with a toolbar
133
+ * item, so the two machines agree on one DOM node.
134
+ */
135
+ getItemId: (value: string) => string;
136
+ /**
137
+ * Returns the state details of the given item.
138
+ */
139
+ getItemState: (props: ItemProps) => ItemState;
140
+ getRootProps: () => T["element"];
141
+ getGroupProps: (props: GroupProps) => T["element"];
142
+ getSeparatorProps: () => T["element"];
143
+ getItemProps: (props: ItemProps) => T["button"];
144
+ getLinkProps: (props: LinkProps) => T["element"];
145
+ getInputProps: (props: ItemProps) => T["input"];
146
+ }
147
+
148
+ export type { ElementIds, GroupProps, ItemProps, ItemState, LinkProps, ToolbarApi, ToolbarMachine, ToolbarProps, ToolbarSchema, ToolbarService };
@@ -0,0 +1,148 @@
1
+ import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { PropTypes, Orientation, RequiredBy, DirectionProperty, CommonProperties } from '@zag-js/types';
3
+ export { Orientation } from '@zag-js/types';
4
+
5
+ type ElementIds = Partial<{
6
+ root: string;
7
+ item: (value: string) => string;
8
+ group: (value: string) => string;
9
+ }>;
10
+ interface ToolbarProps extends DirectionProperty, CommonProperties {
11
+ /**
12
+ * The ids of the elements in the toolbar. Useful for composition.
13
+ */
14
+ ids?: ElementIds | undefined;
15
+ /**
16
+ * Whether the toolbar is disabled. This cascades into every item's
17
+ * effective `disabled` state, but never affects `getLinkProps`.
18
+ */
19
+ disabled?: boolean | undefined;
20
+ /**
21
+ * The orientation of the toolbar.
22
+ * @default "horizontal"
23
+ */
24
+ orientation?: Orientation | undefined;
25
+ /**
26
+ * Whether to loop focus inside the toolbar when navigating with the keyboard.
27
+ * @default true
28
+ */
29
+ loopFocus?: boolean | undefined;
30
+ }
31
+ type PropsWithDefault = "orientation" | "loopFocus";
32
+ interface PrivateContext {
33
+ /**
34
+ * The value of the item that currently holds the roving tabindex.
35
+ * Persists across blur, so tabbing away and back resumes at the same item.
36
+ */
37
+ focusedValue: string | null;
38
+ /**
39
+ * Whether the root has ever redirected focus to an item. Once true, the root
40
+ * permanently cedes its own tabindex to whichever item is tracked.
41
+ */
42
+ hasInteracted: boolean;
43
+ /**
44
+ * Whether the toolbar was focused by a click.
45
+ */
46
+ isClickFocus: boolean;
47
+ }
48
+ interface ToolbarSchema {
49
+ props: RequiredBy<ToolbarProps, PropsWithDefault>;
50
+ context: PrivateContext;
51
+ state: "idle" | "focused";
52
+ event: EventObject;
53
+ action: string;
54
+ guard: string;
55
+ effect: string;
56
+ }
57
+ type ToolbarService = Service<ToolbarSchema>;
58
+ type ToolbarMachine = Machine<ToolbarSchema>;
59
+ interface ItemProps {
60
+ /**
61
+ * The unique value of the item.
62
+ */
63
+ value: string;
64
+ /**
65
+ * Whether the item is disabled.
66
+ */
67
+ disabled?: boolean | undefined;
68
+ /**
69
+ * Whether the item remains focusable (and reachable via arrow keys) while disabled.
70
+ * Keeping disabled controls in the roving tabindex sequence makes them discoverable.
71
+ * @default true
72
+ */
73
+ focusableWhenDisabled?: boolean | undefined;
74
+ }
75
+ interface ItemState {
76
+ /**
77
+ * The underlying id of the item.
78
+ */
79
+ id: string;
80
+ /**
81
+ * Whether the item is disabled. When `focusableWhenDisabled` is `true`, guard your
82
+ * own action handler with this, e.g. `onClick={itemState.disabled ? undefined : fn}`.
83
+ */
84
+ disabled: boolean;
85
+ /**
86
+ * Whether the item remains focusable (and reachable via arrow keys) while disabled.
87
+ */
88
+ focusableWhenDisabled: boolean;
89
+ /**
90
+ * Whether the item is the current roving tabindex target.
91
+ */
92
+ focused: boolean;
93
+ /**
94
+ * The orientation of the toolbar this item belongs to.
95
+ */
96
+ orientation: Orientation;
97
+ }
98
+ interface LinkProps {
99
+ /**
100
+ * The unique value of the link.
101
+ */
102
+ value: string;
103
+ }
104
+ interface GroupProps {
105
+ /**
106
+ * The unique value of the group.
107
+ */
108
+ value: string;
109
+ /**
110
+ * Whether the group is disabled. This is a purely visual/ARIA concern —
111
+ * it does not automatically cascade into the disabled state of items
112
+ * rendered inside it. Thread it into each item's own `disabled` prop, e.g.
113
+ * `api.getItemProps({ value, disabled: groupDisabled || itemDisabled })`.
114
+ */
115
+ disabled?: boolean | undefined;
116
+ }
117
+ interface ToolbarApi<T extends PropTypes = PropTypes> {
118
+ /**
119
+ * Whether the toolbar is disabled.
120
+ */
121
+ disabled: boolean;
122
+ /**
123
+ * The value of the item that is currently focused, if any.
124
+ */
125
+ focusedValue: string | null;
126
+ /**
127
+ * The orientation of the toolbar.
128
+ */
129
+ orientation: Orientation;
130
+ /**
131
+ * Returns the resolved DOM id for the given item value. Useful for aligning
132
+ * a composed machine's own id (e.g. `select`'s `ids.trigger`) with a toolbar
133
+ * item, so the two machines agree on one DOM node.
134
+ */
135
+ getItemId: (value: string) => string;
136
+ /**
137
+ * Returns the state details of the given item.
138
+ */
139
+ getItemState: (props: ItemProps) => ItemState;
140
+ getRootProps: () => T["element"];
141
+ getGroupProps: (props: GroupProps) => T["element"];
142
+ getSeparatorProps: () => T["element"];
143
+ getItemProps: (props: ItemProps) => T["button"];
144
+ getLinkProps: (props: LinkProps) => T["element"];
145
+ getInputProps: (props: ItemProps) => T["input"];
146
+ }
147
+
148
+ export type { ElementIds, GroupProps, ItemProps, ItemState, LinkProps, ToolbarApi, ToolbarMachine, ToolbarProps, ToolbarSchema, ToolbarService };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/toolbar.types.ts
17
+ var toolbar_types_exports = {};
18
+ module.exports = __toCommonJS(toolbar_types_exports);
File without changes
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@zag-js/toolbar",
3
+ "version": "2.0.0-next.1",
4
+ "description": "Core logic for the toolbar widget implemented as a state machine",
5
+ "keywords": [
6
+ "js",
7
+ "machine",
8
+ "xstate",
9
+ "statechart",
10
+ "component",
11
+ "chakra-ui",
12
+ "toolbar"
13
+ ],
14
+ "author": "Segun Adebayo <sage@adebayosegun.com>",
15
+ "homepage": "https://github.com/chakra-ui/zag#readme",
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/chakra-ui/zag/tree/main/packages/toolbar"
20
+ },
21
+ "sideEffects": false,
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/chakra-ui/zag/issues"
30
+ },
31
+ "dependencies": {
32
+ "@zag-js/anatomy": "2.0.0-next.1",
33
+ "@zag-js/dom-query": "2.0.0-next.1",
34
+ "@zag-js/utils": "2.0.0-next.1",
35
+ "@zag-js/core": "2.0.0-next.1",
36
+ "@zag-js/types": "2.0.0-next.1"
37
+ },
38
+ "devDependencies": {
39
+ "clean-package": "2.2.0"
40
+ },
41
+ "clean-package": "./clean-package.config.json",
42
+ "main": "dist/index.js",
43
+ "module": "dist/index.mjs",
44
+ "types": "dist/index.d.ts",
45
+ "exports": {
46
+ ".": {
47
+ "import": {
48
+ "types": "./dist/index.d.mts",
49
+ "default": "./dist/index.mjs"
50
+ },
51
+ "require": {
52
+ "types": "./dist/index.d.ts",
53
+ "default": "./dist/index.js"
54
+ }
55
+ },
56
+ "./anatomy": {
57
+ "import": {
58
+ "types": "./dist/toolbar.anatomy.d.mts",
59
+ "default": "./dist/toolbar.anatomy.mjs"
60
+ },
61
+ "require": {
62
+ "types": "./dist/toolbar.anatomy.d.ts",
63
+ "default": "./dist/toolbar.anatomy.js"
64
+ }
65
+ },
66
+ "./package.json": "./package.json"
67
+ },
68
+ "scripts": {
69
+ "build": "tsup",
70
+ "lint": "eslint src",
71
+ "typecheck": "tsc --noEmit"
72
+ }
73
+ }