@zag-js/tabs 1.34.1 → 1.35.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.
@@ -0,0 +1,188 @@
1
+ import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
3
+
4
+ interface ValueChangeDetails {
5
+ value: string;
6
+ }
7
+ interface FocusChangeDetails {
8
+ focusedValue: string;
9
+ }
10
+ interface NavigateDetails {
11
+ value: string;
12
+ node: HTMLAnchorElement;
13
+ href: string;
14
+ }
15
+ interface IntlTranslations {
16
+ listLabel?: string | undefined;
17
+ }
18
+ type ElementIds = Partial<{
19
+ root: string;
20
+ trigger: (value: string) => string;
21
+ list: string;
22
+ content: (value: string) => string;
23
+ indicator: string;
24
+ }>;
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 tab is composite
74
+ */
75
+ composite?: boolean | undefined;
76
+ /**
77
+ * Whether the active tab can be deselected when clicking on it.
78
+ */
79
+ deselectable?: boolean | undefined;
80
+ /**
81
+ * Function to navigate to the selected tab when clicking on it.
82
+ * Useful if tab triggers are anchor elements.
83
+ */
84
+ navigate?: ((details: NavigateDetails) => void) | null | undefined;
85
+ }
86
+ type PropsWithDefault = "orientation" | "activationMode" | "loopFocus";
87
+ type TabsSchema = {
88
+ state: "idle" | "focused";
89
+ props: RequiredBy<TabsProps, PropsWithDefault>;
90
+ context: {
91
+ ssr: boolean;
92
+ value: string | null;
93
+ focusedValue: string | null;
94
+ indicatorRect: Rect | null;
95
+ };
96
+ refs: {
97
+ indicatorCleanup: VoidFunction | null | undefined;
98
+ };
99
+ computed: {
100
+ focused: boolean;
101
+ };
102
+ action: string;
103
+ guard: string;
104
+ effect: string;
105
+ event: EventObject;
106
+ };
107
+ type TabsService = Service<TabsSchema>;
108
+ type TabsMachine = Machine<TabsSchema>;
109
+ interface TriggerProps {
110
+ /**
111
+ * The value of the tab
112
+ */
113
+ value: string;
114
+ /**
115
+ * Whether the tab is disabled
116
+ */
117
+ disabled?: boolean | undefined;
118
+ }
119
+ interface TriggerState {
120
+ /**
121
+ * Whether the tab is selected
122
+ */
123
+ selected: boolean;
124
+ /**
125
+ * Whether the tab is focused
126
+ */
127
+ focused: boolean;
128
+ /**
129
+ * Whether the tab is disabled
130
+ */
131
+ disabled: boolean;
132
+ }
133
+ interface ContentProps {
134
+ /**
135
+ * The value of the tab
136
+ */
137
+ value: string;
138
+ }
139
+ interface TabsApi<T extends PropTypes = PropTypes> {
140
+ /**
141
+ * The current value of the tabs.
142
+ */
143
+ value: string | null;
144
+ /**
145
+ * The value of the tab that is currently focused.
146
+ */
147
+ focusedValue: string | null;
148
+ /**
149
+ * Sets the value of the tabs.
150
+ */
151
+ setValue: (value: string) => void;
152
+ /**
153
+ * Clears the value of the tabs.
154
+ */
155
+ clearValue: VoidFunction;
156
+ /**
157
+ * Sets the indicator rect to the tab with the given value
158
+ */
159
+ setIndicatorRect: (value: string) => void;
160
+ /**
161
+ * Synchronizes the tab index of the content element.
162
+ * Useful when rendering tabs within a select or combobox
163
+ */
164
+ syncTabIndex: VoidFunction;
165
+ /**
166
+ * Set focus on the selected tab trigger
167
+ */
168
+ focus: VoidFunction;
169
+ /**
170
+ * Selects the next tab
171
+ */
172
+ selectNext: (fromValue?: string) => void;
173
+ /**
174
+ * Selects the previous tab
175
+ */
176
+ selectPrev: (fromValue?: string) => void;
177
+ /**
178
+ * Returns the state of the trigger with the given props
179
+ */
180
+ getTriggerState: (props: TriggerProps) => TriggerState;
181
+ getRootProps: () => T["element"];
182
+ getListProps: () => T["element"];
183
+ getTriggerProps: (props: TriggerProps) => T["button"];
184
+ getContentProps: (props: ContentProps) => T["element"];
185
+ getIndicatorProps: () => T["element"];
186
+ }
187
+
188
+ export type { ContentProps, ElementIds, FocusChangeDetails, IntlTranslations, NavigateDetails, TabsApi, TabsMachine, TabsProps, TabsSchema, TabsService, TriggerProps, TriggerState, ValueChangeDetails };
@@ -0,0 +1,188 @@
1
+ import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
3
+
4
+ interface ValueChangeDetails {
5
+ value: string;
6
+ }
7
+ interface FocusChangeDetails {
8
+ focusedValue: string;
9
+ }
10
+ interface NavigateDetails {
11
+ value: string;
12
+ node: HTMLAnchorElement;
13
+ href: string;
14
+ }
15
+ interface IntlTranslations {
16
+ listLabel?: string | undefined;
17
+ }
18
+ type ElementIds = Partial<{
19
+ root: string;
20
+ trigger: (value: string) => string;
21
+ list: string;
22
+ content: (value: string) => string;
23
+ indicator: string;
24
+ }>;
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 tab is composite
74
+ */
75
+ composite?: boolean | undefined;
76
+ /**
77
+ * Whether the active tab can be deselected when clicking on it.
78
+ */
79
+ deselectable?: boolean | undefined;
80
+ /**
81
+ * Function to navigate to the selected tab when clicking on it.
82
+ * Useful if tab triggers are anchor elements.
83
+ */
84
+ navigate?: ((details: NavigateDetails) => void) | null | undefined;
85
+ }
86
+ type PropsWithDefault = "orientation" | "activationMode" | "loopFocus";
87
+ type TabsSchema = {
88
+ state: "idle" | "focused";
89
+ props: RequiredBy<TabsProps, PropsWithDefault>;
90
+ context: {
91
+ ssr: boolean;
92
+ value: string | null;
93
+ focusedValue: string | null;
94
+ indicatorRect: Rect | null;
95
+ };
96
+ refs: {
97
+ indicatorCleanup: VoidFunction | null | undefined;
98
+ };
99
+ computed: {
100
+ focused: boolean;
101
+ };
102
+ action: string;
103
+ guard: string;
104
+ effect: string;
105
+ event: EventObject;
106
+ };
107
+ type TabsService = Service<TabsSchema>;
108
+ type TabsMachine = Machine<TabsSchema>;
109
+ interface TriggerProps {
110
+ /**
111
+ * The value of the tab
112
+ */
113
+ value: string;
114
+ /**
115
+ * Whether the tab is disabled
116
+ */
117
+ disabled?: boolean | undefined;
118
+ }
119
+ interface TriggerState {
120
+ /**
121
+ * Whether the tab is selected
122
+ */
123
+ selected: boolean;
124
+ /**
125
+ * Whether the tab is focused
126
+ */
127
+ focused: boolean;
128
+ /**
129
+ * Whether the tab is disabled
130
+ */
131
+ disabled: boolean;
132
+ }
133
+ interface ContentProps {
134
+ /**
135
+ * The value of the tab
136
+ */
137
+ value: string;
138
+ }
139
+ interface TabsApi<T extends PropTypes = PropTypes> {
140
+ /**
141
+ * The current value of the tabs.
142
+ */
143
+ value: string | null;
144
+ /**
145
+ * The value of the tab that is currently focused.
146
+ */
147
+ focusedValue: string | null;
148
+ /**
149
+ * Sets the value of the tabs.
150
+ */
151
+ setValue: (value: string) => void;
152
+ /**
153
+ * Clears the value of the tabs.
154
+ */
155
+ clearValue: VoidFunction;
156
+ /**
157
+ * Sets the indicator rect to the tab with the given value
158
+ */
159
+ setIndicatorRect: (value: string) => void;
160
+ /**
161
+ * Synchronizes the tab index of the content element.
162
+ * Useful when rendering tabs within a select or combobox
163
+ */
164
+ syncTabIndex: VoidFunction;
165
+ /**
166
+ * Set focus on the selected tab trigger
167
+ */
168
+ focus: VoidFunction;
169
+ /**
170
+ * Selects the next tab
171
+ */
172
+ selectNext: (fromValue?: string) => void;
173
+ /**
174
+ * Selects the previous tab
175
+ */
176
+ selectPrev: (fromValue?: string) => void;
177
+ /**
178
+ * Returns the state of the trigger with the given props
179
+ */
180
+ getTriggerState: (props: TriggerProps) => TriggerState;
181
+ getRootProps: () => T["element"];
182
+ getListProps: () => T["element"];
183
+ getTriggerProps: (props: TriggerProps) => T["button"];
184
+ getContentProps: (props: ContentProps) => T["element"];
185
+ getIndicatorProps: () => T["element"];
186
+ }
187
+
188
+ export type { ContentProps, ElementIds, FocusChangeDetails, IntlTranslations, NavigateDetails, TabsApi, TabsMachine, TabsProps, TabsSchema, TabsService, TriggerProps, TriggerState, ValueChangeDetails };
@@ -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/tabs.types.ts
17
+ var tabs_types_exports = {};
18
+ module.exports = __toCommonJS(tabs_types_exports);
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "1.34.1",
3
+ "version": "1.35.0",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,16 +26,16 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/anatomy": "1.34.1",
30
- "@zag-js/dom-query": "1.34.1",
31
- "@zag-js/utils": "1.34.1",
32
- "@zag-js/core": "1.34.1",
33
- "@zag-js/types": "1.34.1"
29
+ "@zag-js/anatomy": "1.35.0",
30
+ "@zag-js/dom-query": "1.35.0",
31
+ "@zag-js/utils": "1.35.0",
32
+ "@zag-js/core": "1.35.0",
33
+ "@zag-js/types": "1.35.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "clean-package": "2.2.0"
37
37
  },
38
- "clean-package": "../../../clean-package.config.json",
38
+ "clean-package": "./clean-package.config.json",
39
39
  "main": "dist/index.js",
40
40
  "module": "dist/index.mjs",
41
41
  "types": "dist/index.d.ts",
@@ -50,6 +50,16 @@
50
50
  "default": "./dist/index.js"
51
51
  }
52
52
  },
53
+ "./anatomy": {
54
+ "import": {
55
+ "types": "./dist/tabs.anatomy.d.mts",
56
+ "default": "./dist/tabs.anatomy.mjs"
57
+ },
58
+ "require": {
59
+ "types": "./dist/tabs.anatomy.d.ts",
60
+ "default": "./dist/tabs.anatomy.js"
61
+ }
62
+ },
53
63
  "./package.json": "./package.json"
54
64
  },
55
65
  "scripts": {