@zag-js/tabs 2.0.0-next.3 → 2.0.0-next.4

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.
@@ -1,63 +1,35 @@
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 __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/tabs.props.ts
21
- var tabs_props_exports = {};
22
- __export(tabs_props_exports, {
23
- contentProps: () => contentProps,
24
- props: () => props,
25
- splitContentProps: () => splitContentProps,
26
- splitProps: () => splitProps,
27
- splitTriggerProps: () => splitTriggerProps,
28
- triggerProps: () => triggerProps
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
29
4
  });
30
- module.exports = __toCommonJS(tabs_props_exports);
31
- var import_types = require("@zag-js/types");
32
- var import_utils = require("@zag-js/utils");
33
- var props = (0, import_types.createProps)()([
34
- "activationMode",
35
- "virtualFocus",
36
- "deselectable",
37
- "dir",
38
- "getRootNode",
39
- "id",
40
- "ids",
41
- "loopFocus",
42
- "navigate",
43
- "onFocusChange",
44
- "onValueChange",
45
- "orientation",
46
- "translations",
47
- "value",
48
- "defaultValue"
5
+ let _zag_js_utils = require("@zag-js/utils");
6
+ let _zag_js_types = require("@zag-js/types");
7
+ // src/tabs.props.ts
8
+ const props = (0, _zag_js_types.createProps)()([
9
+ "activationMode",
10
+ "virtualFocus",
11
+ "deselectable",
12
+ "dir",
13
+ "getRootNode",
14
+ "id",
15
+ "ids",
16
+ "loopFocus",
17
+ "navigate",
18
+ "onFocusChange",
19
+ "onValueChange",
20
+ "orientation",
21
+ "translations",
22
+ "value",
23
+ "defaultValue"
49
24
  ]);
50
- var splitProps = (0, import_utils.createSplitProps)(props);
51
- var triggerProps = (0, import_types.createProps)()(["disabled", "value"]);
52
- var splitTriggerProps = (0, import_utils.createSplitProps)(triggerProps);
53
- var contentProps = (0, import_types.createProps)()(["value"]);
54
- var splitContentProps = (0, import_utils.createSplitProps)(contentProps);
55
- // Annotate the CommonJS export names for ESM import in node:
56
- 0 && (module.exports = {
57
- contentProps,
58
- props,
59
- splitContentProps,
60
- splitProps,
61
- splitTriggerProps,
62
- triggerProps
63
- });
25
+ const splitProps = (0, _zag_js_utils.createSplitProps)(props);
26
+ const triggerProps = (0, _zag_js_types.createProps)()(["disabled", "value"]);
27
+ const splitTriggerProps = (0, _zag_js_utils.createSplitProps)(triggerProps);
28
+ const contentProps = (0, _zag_js_types.createProps)()(["value"]);
29
+ const splitContentProps = (0, _zag_js_utils.createSplitProps)(contentProps);
30
+ exports.contentProps = contentProps;
31
+ exports.props = props;
32
+ exports.splitContentProps = splitContentProps;
33
+ exports.splitProps = splitProps;
34
+ exports.splitTriggerProps = splitTriggerProps;
35
+ exports.triggerProps = triggerProps;
@@ -1,33 +1,26 @@
1
- // src/tabs.props.ts
2
- import { createProps } from "@zag-js/types";
3
1
  import { createSplitProps } from "@zag-js/utils";
4
- var props = createProps()([
5
- "activationMode",
6
- "virtualFocus",
7
- "deselectable",
8
- "dir",
9
- "getRootNode",
10
- "id",
11
- "ids",
12
- "loopFocus",
13
- "navigate",
14
- "onFocusChange",
15
- "onValueChange",
16
- "orientation",
17
- "translations",
18
- "value",
19
- "defaultValue"
2
+ import { createProps } from "@zag-js/types";
3
+ // src/tabs.props.ts
4
+ const props = createProps()([
5
+ "activationMode",
6
+ "virtualFocus",
7
+ "deselectable",
8
+ "dir",
9
+ "getRootNode",
10
+ "id",
11
+ "ids",
12
+ "loopFocus",
13
+ "navigate",
14
+ "onFocusChange",
15
+ "onValueChange",
16
+ "orientation",
17
+ "translations",
18
+ "value",
19
+ "defaultValue"
20
20
  ]);
21
- var splitProps = createSplitProps(props);
22
- var triggerProps = createProps()(["disabled", "value"]);
23
- var splitTriggerProps = createSplitProps(triggerProps);
24
- var contentProps = createProps()(["value"]);
25
- var splitContentProps = createSplitProps(contentProps);
26
- export {
27
- contentProps,
28
- props,
29
- splitContentProps,
30
- splitProps,
31
- splitTriggerProps,
32
- triggerProps
33
- };
21
+ const splitProps = createSplitProps(props);
22
+ const triggerProps = createProps()(["disabled", "value"]);
23
+ const splitTriggerProps = createSplitProps(triggerProps);
24
+ const contentProps = createProps()(["value"]);
25
+ const splitContentProps = createSplitProps(contentProps);
26
+ export { contentProps, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
@@ -1,207 +1,265 @@
1
- import { Machine, EventObject, Service } from '@zag-js/core';
2
- import { PropTypes, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
3
-
4
- interface ValueChangeDetails {
5
- value: string;
1
+ import { AnimationFrame } from "@zag-js/dom-query";
2
+ import { EventObject, Machine, Service } from "@zag-js/core";
3
+ import { ActivationDirection, CommonProperties, DirectionProperty, PropTypes, Rect } from "@zag-js/types";
4
+ /**
5
+ * What changed the selected tab:
6
+ * - `trigger-click`: a tab trigger was pressed
7
+ * - `keyboard`: an arrow, `Home` or `End` key moved focus and selected the tab (automatic activation)
8
+ * - `script`: `setValue`, `clearValue`, `selectNext` or `selectPrevious` was called
9
+ */
10
+ export type ValueChangeReason = "trigger-click" | "keyboard" | "script";
11
+ export interface ValueChangeDetails {
12
+ /** `null` when a `deselectable` tab is deselected */
13
+ value: string | null;
14
+ /** Where the selected tab sits relative to the previous one */
15
+ activationDirection: ActivationDirection;
16
+ /** What changed the selected tab */
17
+ reason?: ValueChangeReason | undefined;
6
18
  }
7
- interface FocusChangeDetails {
8
- focusedValue: string;
19
+ export interface FocusChangeDetails {
20
+ /** `null` when focus leaves the tab list */
21
+ focusedValue: string | null;
9
22
  }
10
- interface NavigateDetails {
11
- value: string;
12
- node: HTMLAnchorElement;
13
- href: string;
23
+ export interface NavigateDetails {
24
+ value: string;
25
+ node: HTMLAnchorElement;
26
+ href: string;
14
27
  }
15
- interface IntlTranslations {
16
- listLabel?: string | undefined;
28
+ export interface IntlTranslations {
29
+ listLabel?: string | undefined;
17
30
  }
18
- interface ElementIds {
19
- root?: string | undefined;
20
- trigger?: ((value: string) => string) | undefined;
21
- list?: string | undefined;
22
- content?: ((value: string) => string) | undefined;
23
- indicator?: string | undefined;
31
+ export interface ElementIds {
32
+ root?: string | undefined;
33
+ trigger?: ((value: string) => string) | undefined;
34
+ list?: string | undefined;
35
+ content?: ((value: string) => string) | undefined;
36
+ indicator?: string | undefined;
24
37
  }
25
- interface TabsProps extends DirectionProperty, CommonProperties {
26
- /**
27
- * The ids of the elements in the tabs. Useful for composition.
28
- */
29
- ids?: ElementIds | undefined;
30
- /**
31
- * Specifies the localized strings that identifies the accessibility elements and their states
32
- */
33
- translations?: IntlTranslations | undefined;
34
- /**
35
- * Whether the keyboard navigation will loop from last tab to first, and vice versa.
36
- * @default true
37
- */
38
- loopFocus?: boolean | undefined;
39
- /**
40
- * The controlled selected tab value
41
- */
42
- value?: string | null | undefined;
43
- /**
44
- * The initial selected tab value when rendered.
45
- * Use when you don't need to control the selected tab value.
46
- */
47
- defaultValue?: string | null | undefined;
48
- /**
49
- * The orientation of the tabs. Can be `horizontal` or `vertical`
50
- * - `horizontal`: only left and right arrow key navigation will work.
51
- * - `vertical`: only up and down arrow key navigation will work.
52
- *
53
- * @default "horizontal"
54
- */
55
- orientation?: "horizontal" | "vertical" | undefined;
56
- /**
57
- * The activation mode of the tabs. Can be `manual` or `automatic`
58
- * - `manual`: Tabs are activated when clicked or press `enter` key.
59
- * - `automatic`: Tabs are activated when receiving focus
60
- *
61
- * @default "automatic"
62
- */
63
- activationMode?: "manual" | "automatic" | undefined;
64
- /**
65
- * Callback to be called when the selected/active tab changes
66
- */
67
- onValueChange?: ((details: ValueChangeDetails) => void) | undefined;
68
- /**
69
- * Callback to be called when the focused tab changes
70
- */
71
- onFocusChange?: ((details: FocusChangeDetails) => void) | undefined;
72
- /**
73
- * Whether the tabs use virtual focus instead of roving tabindex.
74
- *
75
- * When `true`, triggers receive no DOM focus — arrow keys update `focusedValue`
76
- * and all triggers remain `tabIndex: -1`. Useful when tabs live inside another
77
- * widget that manages focus (e.g. a combobox).
78
- *
79
- * @default false
80
- */
81
- virtualFocus?: boolean | undefined;
82
- /**
83
- * Whether the active tab can be deselected when clicking on it.
84
- */
85
- deselectable?: boolean | undefined;
86
- /**
87
- * Function to navigate to the selected tab when clicking on it.
88
- * Useful if tab triggers are anchor elements.
89
- */
90
- navigate?: ((details: NavigateDetails) => void) | null | undefined;
38
+ export interface TabsProps extends DirectionProperty, CommonProperties {
39
+ /**
40
+ * The ids of the elements in the tabs. Useful for composition.
41
+ */
42
+ ids?: ElementIds | undefined;
43
+ /**
44
+ * Specifies the localized strings that identifies the accessibility elements and their states
45
+ */
46
+ translations?: IntlTranslations | undefined;
47
+ /**
48
+ * Whether the keyboard navigation will loop from last tab to first, and vice versa.
49
+ * @default true
50
+ */
51
+ loopFocus?: boolean | undefined;
52
+ /**
53
+ * The controlled selected tab value
54
+ */
55
+ value?: string | null | undefined;
56
+ /**
57
+ * The initial selected tab value when rendered.
58
+ * Use when you don't need to control the selected tab value.
59
+ */
60
+ defaultValue?: string | null | undefined;
61
+ /**
62
+ * The orientation of the tabs. Can be `horizontal` or `vertical`
63
+ * - `horizontal`: only left and right arrow key navigation will work.
64
+ * - `vertical`: only up and down arrow key navigation will work.
65
+ *
66
+ * @default "horizontal"
67
+ */
68
+ orientation?: "horizontal" | "vertical" | undefined;
69
+ /**
70
+ * The activation mode of the tabs. Can be `manual` or `automatic`
71
+ * - `manual`: Tabs are activated when clicked or press `enter` key.
72
+ * - `automatic`: Tabs are activated when receiving focus
73
+ *
74
+ * @default "automatic"
75
+ */
76
+ activationMode?: "manual" | "automatic" | undefined;
77
+ /**
78
+ * Callback to be called when the selected/active tab changes
79
+ */
80
+ onValueChange?: ((details: ValueChangeDetails) => void) | undefined;
81
+ /**
82
+ * Callback to be called when the focused tab changes
83
+ */
84
+ onFocusChange?: ((details: FocusChangeDetails) => void) | undefined;
85
+ /**
86
+ * Whether the tabs use virtual focus instead of roving tabindex.
87
+ *
88
+ * When `true`, triggers receive no DOM focus — arrow keys update `focusedValue`
89
+ * and all triggers remain `tabIndex: -1`. Useful when tabs live inside another
90
+ * widget that manages focus (e.g. a combobox).
91
+ *
92
+ * @default false
93
+ */
94
+ virtualFocus?: boolean | undefined;
95
+ /**
96
+ * Whether the active tab can be deselected when clicking on it.
97
+ */
98
+ deselectable?: boolean | undefined;
99
+ /**
100
+ * Function to navigate to the selected tab when clicking on it.
101
+ * Useful if tab triggers are anchor elements.
102
+ */
103
+ navigate?: ((details: NavigateDetails) => void) | null | undefined;
91
104
  }
92
105
  type PropsWithDefault = "orientation" | "activationMode" | "loopFocus";
93
- type TabsSchema = {
94
- state: "idle" | "focused";
95
- props: TabsProps;
96
- defaultPropKey: PropsWithDefault;
97
- context: {
98
- ssr: boolean;
99
- value: string | null;
100
- focusedValue: string | null;
101
- indicatorRect: Rect | null;
102
- animateIndicator: boolean;
103
- };
104
- refs: {
105
- indicatorCleanup: VoidFunction | null | undefined;
106
- prevValue: string | null;
107
- };
108
- computed: {
109
- focused: boolean;
110
- };
111
- action: string;
112
- guard: string;
113
- effect: string;
114
- event: EventObject;
106
+ export type TabsSchema = {
107
+ state: "idle" | "focused";
108
+ props: TabsProps;
109
+ defaultPropKey: PropsWithDefault;
110
+ context: {
111
+ ssr: boolean;
112
+ value: string | null;
113
+ focusedValue: string | null;
114
+ indicatorRect: Rect | null;
115
+ indicatorInstant: boolean;
116
+ tabStopValue: string | null;
117
+ hasFocusableContent: boolean;
118
+ activationDirection: ActivationDirection;
119
+ };
120
+ refs: {
121
+ indicatorCleanup: VoidFunction | null | undefined;
122
+ indicatorFrame: AnimationFrame;
123
+ focusFrame: AnimationFrame;
124
+ selectFrame: AnimationFrame;
125
+ tabIndexFrame: AnimationFrame;
126
+ directionFrame: AnimationFrame;
127
+ previousValue: string | null;
128
+ };
129
+ computed: {
130
+ activationDirection: ActivationDirection;
131
+ };
132
+ action: string;
133
+ guard: string;
134
+ effect: string;
135
+ event: EventObject & {
136
+ src?: ValueChangeReason | undefined;
137
+ };
115
138
  };
116
- type TabsService = Service<TabsSchema>;
117
- type TabsMachine = Machine<TabsSchema>;
118
- interface TriggerProps {
119
- /**
120
- * The value of the tab
121
- */
122
- value: string;
123
- /**
124
- * Whether the tab is disabled
125
- */
126
- disabled?: boolean | undefined;
139
+ export type TabsService = Service<TabsSchema>;
140
+ export type TabsMachine = Machine<TabsSchema>;
141
+ export interface TriggerProps {
142
+ /**
143
+ * The value of the tab
144
+ */
145
+ value: string;
146
+ /**
147
+ * Whether the tab is disabled
148
+ */
149
+ disabled?: boolean | undefined;
127
150
  }
128
- interface TriggerState {
129
- /**
130
- * Whether the tab is selected
131
- */
132
- selected: boolean;
133
- /**
134
- * Whether the tab is focused
135
- */
136
- focused: boolean;
137
- /**
138
- * Whether the tab is disabled
139
- */
140
- disabled: boolean;
151
+ export interface TriggerState {
152
+ /**
153
+ * Whether the tab is selected
154
+ */
155
+ selected: boolean;
156
+ /**
157
+ * Whether the tab is focused
158
+ */
159
+ focused: boolean;
160
+ /**
161
+ * Whether the tab is disabled
162
+ */
163
+ disabled: boolean;
141
164
  }
142
- interface ContentProps {
143
- /**
144
- * The value of the tab
145
- */
146
- value: string;
165
+ export interface ContentProps {
166
+ /**
167
+ * The value of the tab
168
+ */
169
+ value: string;
147
170
  }
148
- interface ContentState {
149
- /**
150
- * Whether the tab content is selected
151
- */
152
- selected: boolean;
171
+ export interface RootState {
172
+ /**
173
+ * Whether a tab trigger has focus
174
+ */
175
+ focused: boolean;
176
+ /**
177
+ * The orientation of the tabs
178
+ */
179
+ orientation: "horizontal" | "vertical";
180
+ /**
181
+ * Where the selected tab sits relative to the previously selected one
182
+ */
183
+ activationDirection: ActivationDirection;
153
184
  }
154
- interface TabsApi<T extends PropTypes = PropTypes> {
155
- /**
156
- * The current value of the tabs.
157
- */
158
- value: string | null;
159
- /**
160
- * The value of the tab that is currently focused.
161
- */
162
- focusedValue: string | null;
163
- /**
164
- * Sets the value of the tabs.
165
- */
166
- setValue: (value: string) => void;
167
- /**
168
- * Clears the value of the tabs.
169
- */
170
- clearValue: VoidFunction;
171
- /**
172
- * Sets the indicator rect to the tab with the given value
173
- */
174
- setIndicatorRect: (value: string) => void;
175
- /**
176
- * Synchronizes the tab index of the content element.
177
- * Useful when rendering tabs within a select or combobox
178
- */
179
- syncTabIndex: VoidFunction;
180
- /**
181
- * Set focus on the selected tab trigger
182
- */
183
- focus: VoidFunction;
184
- /**
185
- * Selects the next tab
186
- */
187
- selectNext: (fromValue?: string) => void;
188
- /**
189
- * Selects the previous tab
190
- */
191
- selectPrev: (fromValue?: string) => void;
192
- /**
193
- * Returns the state of the trigger with the given props
194
- */
195
- getTriggerState: (props: TriggerProps) => TriggerState;
196
- getRootProps: () => T["element"];
197
- getListProps: () => T["element"];
198
- getTriggerProps: (props: TriggerProps) => T["button"];
199
- /**
200
- * Returns the state of the content with the given props
201
- */
202
- getContentState: (props: ContentProps) => ContentState;
203
- getContentProps: (props: ContentProps) => T["element"];
204
- getIndicatorProps: () => T["element"];
185
+ export interface ContentState extends RootState {
186
+ /**
187
+ * Whether the tab content is selected
188
+ */
189
+ selected: boolean;
190
+ }
191
+ export interface IndicatorState extends RootState {
192
+ /**
193
+ * Whether the indicator has a measured rect to point to
194
+ */
195
+ visible: boolean;
196
+ /**
197
+ * Whether the indicator should snap into place instead of animating
198
+ */
199
+ instant: boolean;
200
+ }
201
+ export interface TabsApi<T extends PropTypes = PropTypes> {
202
+ /**
203
+ * The current value of the tabs.
204
+ */
205
+ value: string | null;
206
+ /**
207
+ * The value of the tab that is currently focused.
208
+ */
209
+ focusedValue: string | null;
210
+ /**
211
+ * Where the selected tab sits relative to the previously selected one
212
+ */
213
+ activationDirection: ActivationDirection;
214
+ /**
215
+ * Sets the value of the tabs.
216
+ */
217
+ setValue: (value: string, reason?: ValueChangeReason) => void;
218
+ /**
219
+ * Clears the value of the tabs.
220
+ */
221
+ clearValue: VoidFunction;
222
+ /**
223
+ * Sets the indicator rect to the tab with the given value
224
+ */
225
+ setIndicatorRect: (value: string) => void;
226
+ /**
227
+ * Synchronizes the tab index of the content element.
228
+ * Useful when rendering tabs within a select or combobox
229
+ */
230
+ syncTabIndex: VoidFunction;
231
+ /**
232
+ * Set focus on the selected tab trigger
233
+ */
234
+ focus: VoidFunction;
235
+ /**
236
+ * Selects the next enabled tab, without moving focus
237
+ */
238
+ selectNext: (fromValue?: string) => void;
239
+ /**
240
+ * Selects the previous enabled tab, without moving focus
241
+ */
242
+ selectPrevious: (fromValue?: string) => void;
243
+ /**
244
+ * Returns the state of the trigger with the given props
245
+ */
246
+ getTriggerState: (props: TriggerProps) => TriggerState;
247
+ getTriggerProps: (props: TriggerProps) => T["button"];
248
+ /**
249
+ * Returns the state of the root. The list shares it.
250
+ */
251
+ getRootState: () => RootState;
252
+ getRootProps: () => T["element"];
253
+ getListProps: () => T["element"];
254
+ /**
255
+ * Returns the state of the content with the given props
256
+ */
257
+ getContentState: (props: ContentProps) => ContentState;
258
+ getContentProps: (props: ContentProps) => T["element"];
259
+ /**
260
+ * Returns the state of the indicator
261
+ */
262
+ getIndicatorState: () => IndicatorState;
263
+ getIndicatorProps: () => T["element"];
205
264
  }
206
-
207
- export type { ContentProps, ContentState, ElementIds, FocusChangeDetails, IntlTranslations, NavigateDetails, TabsApi, TabsMachine, TabsProps, TabsSchema, TabsService, TriggerProps, TriggerState, ValueChangeDetails };
265
+ export {};