@zag-js/tabs 2.0.0-next.0 → 2.0.0-next.2

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/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ export { anatomy } from './tabs.anatomy.mjs';
2
2
  export { connect } from './tabs.connect.mjs';
3
3
  export { machine } from './tabs.machine.mjs';
4
4
  export { contentProps, props, splitContentProps, splitProps, splitTriggerProps, triggerProps } from './tabs.props.mjs';
5
- export { TabsApi as Api, ContentProps, ElementIds, FocusChangeDetails, IntlTranslations, TabsMachine as Machine, NavigateDetails, TabsProps as Props, TabsService as Service, TriggerProps, TriggerState, ValueChangeDetails } from './tabs.types.mjs';
5
+ export { TabsApi as Api, ContentProps, ContentState, ElementIds, FocusChangeDetails, IntlTranslations, TabsMachine as Machine, NavigateDetails, TabsProps as Props, TabsService as Service, TriggerProps, TriggerState, ValueChangeDetails } from './tabs.types.mjs';
6
6
  import '@zag-js/anatomy';
7
7
  import '@zag-js/core';
8
8
  import '@zag-js/types';
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { anatomy } from './tabs.anatomy.js';
2
2
  export { connect } from './tabs.connect.js';
3
3
  export { machine } from './tabs.machine.js';
4
4
  export { contentProps, props, splitContentProps, splitProps, splitTriggerProps, triggerProps } from './tabs.props.js';
5
- export { TabsApi as Api, ContentProps, ElementIds, FocusChangeDetails, IntlTranslations, TabsMachine as Machine, NavigateDetails, TabsProps as Props, TabsService as Service, TriggerProps, TriggerState, ValueChangeDetails } from './tabs.types.js';
5
+ export { TabsApi as Api, ContentProps, ContentState, ElementIds, FocusChangeDetails, IntlTranslations, TabsMachine as Machine, NavigateDetails, TabsProps as Props, TabsService as Service, TriggerProps, TriggerState, ValueChangeDetails } from './tabs.types.js';
6
6
  import '@zag-js/anatomy';
7
7
  import '@zag-js/core';
8
8
  import '@zag-js/types';
@@ -51,6 +51,9 @@ function connect(service, normalize) {
51
51
  disabled: !!props.disabled
52
52
  };
53
53
  }
54
+ function getContentState(props) {
55
+ return { selected: context.get("value") === props.value };
56
+ }
54
57
  return {
55
58
  value: context.get("value"),
56
59
  focusedValue: context.get("focusedValue"),
@@ -179,9 +182,10 @@ function connect(service, normalize) {
179
182
  }
180
183
  });
181
184
  },
185
+ getContentState,
182
186
  getContentProps(props) {
183
187
  const { value } = props;
184
- const selected = context.get("value") === value;
188
+ const contentState = getContentState(props);
185
189
  return normalize.element({
186
190
  ...import_tabs.parts.content.attrs(scope.id),
187
191
  dir: prop("dir"),
@@ -189,9 +193,9 @@ function connect(service, normalize) {
189
193
  tabIndex: !virtualFocus ? 0 : -1,
190
194
  "aria-labelledby": dom.getTriggerId(scope, value),
191
195
  role: "tabpanel",
192
- "data-selected": (0, import_dom_query.dataAttr)(selected),
196
+ "data-selected": (0, import_dom_query.dataAttr)(contentState.selected),
193
197
  "data-orientation": prop("orientation"),
194
- hidden: !selected
198
+ hidden: !contentState.selected
195
199
  });
196
200
  },
197
201
  getIndicatorProps() {
@@ -25,6 +25,9 @@ function connect(service, normalize) {
25
25
  disabled: !!props.disabled
26
26
  };
27
27
  }
28
+ function getContentState(props) {
29
+ return { selected: context.get("value") === props.value };
30
+ }
28
31
  return {
29
32
  value: context.get("value"),
30
33
  focusedValue: context.get("focusedValue"),
@@ -153,9 +156,10 @@ function connect(service, normalize) {
153
156
  }
154
157
  });
155
158
  },
159
+ getContentState,
156
160
  getContentProps(props) {
157
161
  const { value } = props;
158
- const selected = context.get("value") === value;
162
+ const contentState = getContentState(props);
159
163
  return normalize.element({
160
164
  ...parts.content.attrs(scope.id),
161
165
  dir: prop("dir"),
@@ -163,9 +167,9 @@ function connect(service, normalize) {
163
167
  tabIndex: !virtualFocus ? 0 : -1,
164
168
  "aria-labelledby": dom.getTriggerId(scope, value),
165
169
  role: "tabpanel",
166
- "data-selected": dataAttr(selected),
170
+ "data-selected": dataAttr(contentState.selected),
167
171
  "data-orientation": prop("orientation"),
168
- hidden: !selected
172
+ hidden: !contentState.selected
169
173
  });
170
174
  },
171
175
  getIndicatorProps() {
@@ -1,5 +1,5 @@
1
1
  import { Machine, EventObject, Service } from '@zag-js/core';
2
- import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
2
+ import { PropTypes, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
3
3
 
4
4
  interface ValueChangeDetails {
5
5
  value: string;
@@ -15,13 +15,13 @@ interface NavigateDetails {
15
15
  interface IntlTranslations {
16
16
  listLabel?: string | undefined;
17
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
- }>;
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;
24
+ }
25
25
  interface TabsProps extends DirectionProperty, CommonProperties {
26
26
  /**
27
27
  * The ids of the elements in the tabs. Useful for composition.
@@ -92,7 +92,8 @@ interface TabsProps extends DirectionProperty, CommonProperties {
92
92
  type PropsWithDefault = "orientation" | "activationMode" | "loopFocus";
93
93
  type TabsSchema = {
94
94
  state: "idle" | "focused";
95
- props: RequiredBy<TabsProps, PropsWithDefault>;
95
+ props: TabsProps;
96
+ defaultPropKey: PropsWithDefault;
96
97
  context: {
97
98
  ssr: boolean;
98
99
  value: string | null;
@@ -144,6 +145,12 @@ interface ContentProps {
144
145
  */
145
146
  value: string;
146
147
  }
148
+ interface ContentState {
149
+ /**
150
+ * Whether the tab content is selected
151
+ */
152
+ selected: boolean;
153
+ }
147
154
  interface TabsApi<T extends PropTypes = PropTypes> {
148
155
  /**
149
156
  * The current value of the tabs.
@@ -189,8 +196,12 @@ interface TabsApi<T extends PropTypes = PropTypes> {
189
196
  getRootProps: () => T["element"];
190
197
  getListProps: () => T["element"];
191
198
  getTriggerProps: (props: TriggerProps) => T["button"];
199
+ /**
200
+ * Returns the state of the content with the given props
201
+ */
202
+ getContentState: (props: ContentProps) => ContentState;
192
203
  getContentProps: (props: ContentProps) => T["element"];
193
204
  getIndicatorProps: () => T["element"];
194
205
  }
195
206
 
196
- export type { ContentProps, ElementIds, FocusChangeDetails, IntlTranslations, NavigateDetails, TabsApi, TabsMachine, TabsProps, TabsSchema, TabsService, TriggerProps, TriggerState, ValueChangeDetails };
207
+ export type { ContentProps, ContentState, ElementIds, FocusChangeDetails, IntlTranslations, NavigateDetails, TabsApi, TabsMachine, TabsProps, TabsSchema, TabsService, TriggerProps, TriggerState, ValueChangeDetails };
@@ -1,5 +1,5 @@
1
1
  import { Machine, EventObject, Service } from '@zag-js/core';
2
- import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
2
+ import { PropTypes, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
3
3
 
4
4
  interface ValueChangeDetails {
5
5
  value: string;
@@ -15,13 +15,13 @@ interface NavigateDetails {
15
15
  interface IntlTranslations {
16
16
  listLabel?: string | undefined;
17
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
- }>;
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;
24
+ }
25
25
  interface TabsProps extends DirectionProperty, CommonProperties {
26
26
  /**
27
27
  * The ids of the elements in the tabs. Useful for composition.
@@ -92,7 +92,8 @@ interface TabsProps extends DirectionProperty, CommonProperties {
92
92
  type PropsWithDefault = "orientation" | "activationMode" | "loopFocus";
93
93
  type TabsSchema = {
94
94
  state: "idle" | "focused";
95
- props: RequiredBy<TabsProps, PropsWithDefault>;
95
+ props: TabsProps;
96
+ defaultPropKey: PropsWithDefault;
96
97
  context: {
97
98
  ssr: boolean;
98
99
  value: string | null;
@@ -144,6 +145,12 @@ interface ContentProps {
144
145
  */
145
146
  value: string;
146
147
  }
148
+ interface ContentState {
149
+ /**
150
+ * Whether the tab content is selected
151
+ */
152
+ selected: boolean;
153
+ }
147
154
  interface TabsApi<T extends PropTypes = PropTypes> {
148
155
  /**
149
156
  * The current value of the tabs.
@@ -189,8 +196,12 @@ interface TabsApi<T extends PropTypes = PropTypes> {
189
196
  getRootProps: () => T["element"];
190
197
  getListProps: () => T["element"];
191
198
  getTriggerProps: (props: TriggerProps) => T["button"];
199
+ /**
200
+ * Returns the state of the content with the given props
201
+ */
202
+ getContentState: (props: ContentProps) => ContentState;
192
203
  getContentProps: (props: ContentProps) => T["element"];
193
204
  getIndicatorProps: () => T["element"];
194
205
  }
195
206
 
196
- export type { ContentProps, ElementIds, FocusChangeDetails, IntlTranslations, NavigateDetails, TabsApi, TabsMachine, TabsProps, TabsSchema, TabsService, TriggerProps, TriggerState, ValueChangeDetails };
207
+ export type { ContentProps, ContentState, ElementIds, FocusChangeDetails, IntlTranslations, NavigateDetails, TabsApi, TabsMachine, TabsProps, TabsSchema, TabsService, TriggerProps, TriggerState, ValueChangeDetails };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "2.0.0-next.0",
3
+ "version": "2.0.0-next.2",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -14,7 +14,10 @@
14
14
  "author": "Segun Adebayo <sage@adebayosegun.com>",
15
15
  "homepage": "https://github.com/chakra-ui/zag#readme",
16
16
  "license": "MIT",
17
- "repository": "https://github.com/chakra-ui/zag/tree/main/packages/tabs",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/chakra-ui/zag/tree/main/packages/tabs"
20
+ },
18
21
  "sideEffects": false,
19
22
  "files": [
20
23
  "dist"
@@ -26,11 +29,11 @@
26
29
  "url": "https://github.com/chakra-ui/zag/issues"
27
30
  },
28
31
  "dependencies": {
29
- "@zag-js/anatomy": "2.0.0-next.0",
30
- "@zag-js/dom-query": "2.0.0-next.0",
31
- "@zag-js/utils": "2.0.0-next.0",
32
- "@zag-js/core": "2.0.0-next.0",
33
- "@zag-js/types": "2.0.0-next.0"
32
+ "@zag-js/anatomy": "2.0.0-next.2",
33
+ "@zag-js/dom-query": "2.0.0-next.2",
34
+ "@zag-js/utils": "2.0.0-next.2",
35
+ "@zag-js/core": "2.0.0-next.2",
36
+ "@zag-js/types": "2.0.0-next.2"
34
37
  },
35
38
  "devDependencies": {
36
39
  "clean-package": "2.2.0"
@@ -64,7 +67,7 @@
64
67
  },
65
68
  "scripts": {
66
69
  "build": "tsup",
67
- "lint": "eslint src",
70
+ "lint": "oxlint src",
68
71
  "typecheck": "tsc --noEmit"
69
72
  }
70
73
  }