@zag-js/tabs 0.8.0 → 0.9.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.
@@ -44,11 +44,11 @@ var dom = createScope({
44
44
  return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
45
45
  },
46
46
  resolveRect(rect, orientation) {
47
- const prop = orientation === "vertical" ? "height" : "width";
47
+ const sizeProp = orientation === "vertical" ? "height" : "width";
48
+ const placementProp = orientation === "vertical" ? "top" : "left";
48
49
  return {
49
- left: `${rect.left}px`,
50
- top: `${rect.top}px`,
51
- [prop]: `${rect[prop]}px`
50
+ [placementProp]: `${rect[placementProp]}px`,
51
+ [sizeProp]: `${rect[sizeProp]}px`
52
52
  };
53
53
  }
54
54
  });
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-S2KW2DT4.mjs";
4
4
  import {
5
5
  dom
6
- } from "./chunk-SVFEUEGP.mjs";
6
+ } from "./chunk-EU4R7SET.mjs";
7
7
 
8
8
  // src/tabs.connect.ts
9
9
  import { getEventKey } from "@zag-js/dom-event";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-SVFEUEGP.mjs";
3
+ } from "./chunk-EU4R7SET.mjs";
4
4
 
5
5
  // src/tabs.machine.ts
6
6
  import { createMachine, guards } from "@zag-js/core";
@@ -21,7 +21,12 @@ function machine(userContext) {
21
21
  value: null,
22
22
  focusedValue: null,
23
23
  previousValues: [],
24
- indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
24
+ indicatorRect: {
25
+ left: "0px",
26
+ top: "0px",
27
+ width: "0px",
28
+ height: "0px"
29
+ },
25
30
  canIndicatorTransition: false,
26
31
  isIndicatorRendered: false,
27
32
  loop: true,
@@ -44,7 +49,8 @@ function machine(userContext) {
44
49
  "syncIndicatorRect",
45
50
  "setContentTabIndex"
46
51
  ],
47
- dir: ["syncIndicatorRect"]
52
+ dir: ["syncIndicatorRect"],
53
+ orientation: ["syncIndicatorRect"]
48
54
  },
49
55
  on: {
50
56
  SET_VALUE: {
@@ -60,11 +66,17 @@ function machine(userContext) {
60
66
  states: {
61
67
  idle: {
62
68
  on: {
63
- TAB_FOCUS: {
64
- guard: "selectOnFocus",
65
- target: "focused",
66
- actions: ["setFocusedValue", "setValue"]
67
- },
69
+ TAB_FOCUS: [
70
+ {
71
+ guard: "selectOnFocus",
72
+ target: "focused",
73
+ actions: ["setFocusedValue", "setValue"]
74
+ },
75
+ {
76
+ target: "focused",
77
+ actions: "setFocusedValue"
78
+ }
79
+ ],
68
80
  TAB_CLICK: {
69
81
  target: "focused",
70
82
  actions: ["setFocusedValue", "setValue"]
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { anatomy } from './tabs.anatomy.js';
2
2
  export { connect } from './tabs.connect.js';
3
3
  export { machine } from './tabs.machine.js';
4
- export { UserDefinedContext as Context } from './tabs.types.js';
4
+ export { ContentProps, UserDefinedContext as Context, TriggerProps } from './tabs.types.js';
5
5
  import '@zag-js/anatomy';
6
6
  import '@zag-js/types';
7
7
  import '@zag-js/core';
package/dist/index.js CHANGED
@@ -81,11 +81,11 @@ var dom = (0, import_dom_query.createScope)({
81
81
  return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
82
82
  },
83
83
  resolveRect(rect, orientation) {
84
- const prop = orientation === "vertical" ? "height" : "width";
84
+ const sizeProp = orientation === "vertical" ? "height" : "width";
85
+ const placementProp = orientation === "vertical" ? "top" : "left";
85
86
  return {
86
- left: `${rect.left}px`,
87
- top: `${rect.top}px`,
88
- [prop]: `${rect[prop]}px`
87
+ [placementProp]: `${rect[placementProp]}px`,
88
+ [sizeProp]: `${rect[sizeProp]}px`
89
89
  };
90
90
  }
91
91
  });
@@ -263,7 +263,12 @@ function machine(userContext) {
263
263
  value: null,
264
264
  focusedValue: null,
265
265
  previousValues: [],
266
- indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
266
+ indicatorRect: {
267
+ left: "0px",
268
+ top: "0px",
269
+ width: "0px",
270
+ height: "0px"
271
+ },
267
272
  canIndicatorTransition: false,
268
273
  isIndicatorRendered: false,
269
274
  loop: true,
@@ -286,7 +291,8 @@ function machine(userContext) {
286
291
  "syncIndicatorRect",
287
292
  "setContentTabIndex"
288
293
  ],
289
- dir: ["syncIndicatorRect"]
294
+ dir: ["syncIndicatorRect"],
295
+ orientation: ["syncIndicatorRect"]
290
296
  },
291
297
  on: {
292
298
  SET_VALUE: {
@@ -302,11 +308,17 @@ function machine(userContext) {
302
308
  states: {
303
309
  idle: {
304
310
  on: {
305
- TAB_FOCUS: {
306
- guard: "selectOnFocus",
307
- target: "focused",
308
- actions: ["setFocusedValue", "setValue"]
309
- },
311
+ TAB_FOCUS: [
312
+ {
313
+ guard: "selectOnFocus",
314
+ target: "focused",
315
+ actions: ["setFocusedValue", "setValue"]
316
+ },
317
+ {
318
+ target: "focused",
319
+ actions: "setFocusedValue"
320
+ }
321
+ ],
310
322
  TAB_CLICK: {
311
323
  target: "focused",
312
324
  actions: ["setFocusedValue", "setValue"]
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-N7U3IQEQ.mjs";
3
+ } from "./chunk-GMBCGZJ4.mjs";
4
4
  import {
5
5
  anatomy
6
6
  } from "./chunk-S2KW2DT4.mjs";
7
7
  import {
8
8
  machine
9
- } from "./chunk-N5FVPJXW.mjs";
10
- import "./chunk-SVFEUEGP.mjs";
9
+ } from "./chunk-HGL32F6R.mjs";
10
+ import "./chunk-EU4R7SET.mjs";
11
11
  export {
12
12
  anatomy,
13
13
  connect,
@@ -1,5 +1,5 @@
1
1
  import { PropTypes, NormalizeProps } from '@zag-js/types';
2
- import { State, Send, TabProps } from './tabs.types.js';
2
+ import { State, Send, TriggerProps, ContentProps } from './tabs.types.js';
3
3
  import '@zag-js/core';
4
4
 
5
5
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
@@ -29,11 +29,9 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
29
29
  setIndicatorRect(id: string | null | undefined): void;
30
30
  rootProps: T["element"];
31
31
  tablistProps: T["element"];
32
- getTriggerProps(props: TabProps): T["button"];
32
+ getTriggerProps(props: TriggerProps): T["button"];
33
33
  contentGroupProps: T["element"];
34
- getContentProps({ value }: {
35
- value: string;
36
- }): T["element"];
34
+ getContentProps({ value }: ContentProps): T["element"];
37
35
  indicatorProps: T["element"];
38
36
  };
39
37
 
@@ -77,11 +77,11 @@ var dom = (0, import_dom_query.createScope)({
77
77
  return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
78
78
  },
79
79
  resolveRect(rect, orientation) {
80
- const prop = orientation === "vertical" ? "height" : "width";
80
+ const sizeProp = orientation === "vertical" ? "height" : "width";
81
+ const placementProp = orientation === "vertical" ? "top" : "left";
81
82
  return {
82
- left: `${rect.left}px`,
83
- top: `${rect.top}px`,
84
- [prop]: `${rect[prop]}px`
83
+ [placementProp]: `${rect[placementProp]}px`,
84
+ [sizeProp]: `${rect[sizeProp]}px`
85
85
  };
86
86
  }
87
87
  });
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-N7U3IQEQ.mjs";
3
+ } from "./chunk-GMBCGZJ4.mjs";
4
4
  import "./chunk-S2KW2DT4.mjs";
5
- import "./chunk-SVFEUEGP.mjs";
5
+ import "./chunk-EU4R7SET.mjs";
6
6
  export {
7
7
  connect
8
8
  };
@@ -47,13 +47,9 @@ declare const dom: {
47
47
  };
48
48
  getRectById: (ctx: MachineContext, id: string) => {
49
49
  [x: string]: string;
50
- left: string;
51
- top: string;
52
50
  };
53
51
  resolveRect(rect: Record<"width" | "height" | "left" | "top", number>, orientation?: "horizontal" | "vertical"): {
54
52
  [x: string]: string;
55
- left: string;
56
- top: string;
57
53
  };
58
54
  };
59
55
 
package/dist/tabs.dom.js CHANGED
@@ -68,11 +68,11 @@ var dom = (0, import_dom_query.createScope)({
68
68
  return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
69
69
  },
70
70
  resolveRect(rect, orientation) {
71
- const prop = orientation === "vertical" ? "height" : "width";
71
+ const sizeProp = orientation === "vertical" ? "height" : "width";
72
+ const placementProp = orientation === "vertical" ? "top" : "left";
72
73
  return {
73
- left: `${rect.left}px`,
74
- top: `${rect.top}px`,
75
- [prop]: `${rect[prop]}px`
74
+ [placementProp]: `${rect[placementProp]}px`,
75
+ [sizeProp]: `${rect[sizeProp]}px`
76
76
  };
77
77
  }
78
78
  });
package/dist/tabs.dom.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  dom
3
- } from "./chunk-SVFEUEGP.mjs";
3
+ } from "./chunk-EU4R7SET.mjs";
4
4
  export {
5
5
  dom
6
6
  };
@@ -75,11 +75,11 @@ var dom = (0, import_dom_query.createScope)({
75
75
  return dom.resolveRect(dom.getOffsetRect(tab), ctx.orientation);
76
76
  },
77
77
  resolveRect(rect, orientation) {
78
- const prop = orientation === "vertical" ? "height" : "width";
78
+ const sizeProp = orientation === "vertical" ? "height" : "width";
79
+ const placementProp = orientation === "vertical" ? "top" : "left";
79
80
  return {
80
- left: `${rect.left}px`,
81
- top: `${rect.top}px`,
82
- [prop]: `${rect[prop]}px`
81
+ [placementProp]: `${rect[placementProp]}px`,
82
+ [sizeProp]: `${rect[sizeProp]}px`
83
83
  };
84
84
  }
85
85
  });
@@ -98,7 +98,12 @@ function machine(userContext) {
98
98
  value: null,
99
99
  focusedValue: null,
100
100
  previousValues: [],
101
- indicatorRect: { left: "0px", top: "0px", width: "0px", height: "0px" },
101
+ indicatorRect: {
102
+ left: "0px",
103
+ top: "0px",
104
+ width: "0px",
105
+ height: "0px"
106
+ },
102
107
  canIndicatorTransition: false,
103
108
  isIndicatorRendered: false,
104
109
  loop: true,
@@ -121,7 +126,8 @@ function machine(userContext) {
121
126
  "syncIndicatorRect",
122
127
  "setContentTabIndex"
123
128
  ],
124
- dir: ["syncIndicatorRect"]
129
+ dir: ["syncIndicatorRect"],
130
+ orientation: ["syncIndicatorRect"]
125
131
  },
126
132
  on: {
127
133
  SET_VALUE: {
@@ -137,11 +143,17 @@ function machine(userContext) {
137
143
  states: {
138
144
  idle: {
139
145
  on: {
140
- TAB_FOCUS: {
141
- guard: "selectOnFocus",
142
- target: "focused",
143
- actions: ["setFocusedValue", "setValue"]
144
- },
146
+ TAB_FOCUS: [
147
+ {
148
+ guard: "selectOnFocus",
149
+ target: "focused",
150
+ actions: ["setFocusedValue", "setValue"]
151
+ },
152
+ {
153
+ target: "focused",
154
+ actions: "setFocusedValue"
155
+ }
156
+ ],
145
157
  TAB_CLICK: {
146
158
  target: "focused",
147
159
  actions: ["setFocusedValue", "setValue"]
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-N5FVPJXW.mjs";
4
- import "./chunk-SVFEUEGP.mjs";
3
+ } from "./chunk-HGL32F6R.mjs";
4
+ import "./chunk-EU4R7SET.mjs";
5
5
  export {
6
6
  machine
7
7
  };
@@ -12,6 +12,13 @@ type ElementIds = Partial<{
12
12
  content: string;
13
13
  indicator: string;
14
14
  }>;
15
+ type TriggerProps = {
16
+ value: string;
17
+ disabled?: boolean;
18
+ };
19
+ type ContentProps = {
20
+ value: string;
21
+ };
15
22
  type PublicContext = DirectionProperty & CommonProperties & {
16
23
  /**
17
24
  * The ids of the elements in the tabs. Useful for composition.
@@ -84,9 +91,5 @@ type MachineState = {
84
91
  };
85
92
  type State = StateMachine.State<MachineContext, MachineState>;
86
93
  type Send = StateMachine.Send<StateMachine.AnyEventObject>;
87
- type TabProps = {
88
- value: string;
89
- disabled?: boolean;
90
- };
91
94
 
92
- export { MachineContext, MachineState, Send, State, TabProps, UserDefinedContext };
95
+ export { ContentProps, MachineContext, MachineState, Send, State, TriggerProps, UserDefinedContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,14 +26,14 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/anatomy": "0.1.4",
30
- "@zag-js/dom-query": "0.1.4",
31
- "@zag-js/dom-event": "0.8.0",
32
- "@zag-js/element-rect": "0.8.0",
33
- "@zag-js/tabbable": "0.8.0",
34
- "@zag-js/utils": "0.3.4",
35
- "@zag-js/core": "0.7.0",
36
- "@zag-js/types": "0.5.0"
29
+ "@zag-js/anatomy": "0.9.1",
30
+ "@zag-js/dom-query": "0.9.1",
31
+ "@zag-js/dom-event": "0.9.1",
32
+ "@zag-js/element-rect": "0.9.1",
33
+ "@zag-js/tabbable": "0.9.1",
34
+ "@zag-js/utils": "0.9.1",
35
+ "@zag-js/core": "0.9.1",
36
+ "@zag-js/types": "0.9.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "clean-package": "2.2.0"