@zag-js/tabs 0.10.5 → 0.11.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.
@@ -1,5 +1,10 @@
1
- import type { StateMachine as S } from "@zag-js/core";
2
- import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+ import { RequiredBy, DirectionProperty, CommonProperties, Context, PropTypes, NormalizeProps } from '@zag-js/types';
3
+ import * as _zag_js_core from '@zag-js/core';
4
+ import { StateMachine } from '@zag-js/core';
5
+
6
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "tablist" | "trigger" | "contentGroup" | "content" | "indicator">;
7
+
3
8
  type IntlTranslations = {
4
9
  tablistLabel?: string;
5
10
  };
@@ -11,11 +16,11 @@ type ElementIds = Partial<{
11
16
  content: string;
12
17
  indicator: string;
13
18
  }>;
14
- export type TriggerProps = {
19
+ type TriggerProps = {
15
20
  value: string;
16
21
  disabled?: boolean;
17
22
  };
18
- export type ContentProps = {
23
+ type ContentProps = {
19
24
  value: string;
20
25
  };
21
26
  type PublicContext = DirectionProperty & CommonProperties & {
@@ -70,7 +75,7 @@ type PublicContext = DirectionProperty & CommonProperties & {
70
75
  value: string;
71
76
  }) => void;
72
77
  };
73
- export type UserDefinedContext = RequiredBy<PublicContext, "id">;
78
+ type UserDefinedContext = RequiredBy<PublicContext, "id">;
74
79
  type ComputedContext = Readonly<{
75
80
  /**
76
81
  * @computed
@@ -84,10 +89,46 @@ type ComputedContext = Readonly<{
84
89
  isVertical: boolean;
85
90
  }>;
86
91
  type PrivateContext = Context<{}>;
87
- export type MachineContext = PublicContext & ComputedContext & PrivateContext;
88
- export type MachineState = {
92
+ type MachineContext = PublicContext & ComputedContext & PrivateContext;
93
+ type MachineState = {
89
94
  value: "idle" | "focused";
90
95
  };
91
- export type State = S.State<MachineContext, MachineState>;
92
- export type Send = S.Send<S.AnyEventObject>;
93
- export {};
96
+ type State = StateMachine.State<MachineContext, MachineState>;
97
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
98
+
99
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
100
+ /**
101
+ * The current value of the tabs.
102
+ */
103
+ value: string | null;
104
+ /**
105
+ * The value of the tab that is currently focused.
106
+ */
107
+ focusedValue: string | null;
108
+ /**
109
+ * The previous values of the tabs in sequence of selection.
110
+ */
111
+ previousValues: string[];
112
+ /**
113
+ * Sets the value of the tabs.
114
+ */
115
+ setValue(value: string): void;
116
+ /**
117
+ * Clears the value of the tabs.
118
+ */
119
+ clearValue(): void;
120
+ /**
121
+ * Sets the indicator rect to the tab with the given id.
122
+ */
123
+ setIndicatorRect(id: string | null | undefined): void;
124
+ rootProps: T["element"];
125
+ tablistProps: T["element"];
126
+ getTriggerProps(props: TriggerProps): T["button"];
127
+ contentGroupProps: T["element"];
128
+ getContentProps({ value }: ContentProps): T["element"];
129
+ indicatorProps: T["element"];
130
+ };
131
+
132
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
133
+
134
+ export { ContentProps, UserDefinedContext as Context, TriggerProps, anatomy, connect, machine };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,134 @@
1
- export { anatomy } from "./tabs.anatomy";
2
- export { connect } from "./tabs.connect";
3
- export { machine } from "./tabs.machine";
4
- export type { UserDefinedContext as Context, TriggerProps, ContentProps } from "./tabs.types";
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+ import { RequiredBy, DirectionProperty, CommonProperties, Context, PropTypes, NormalizeProps } from '@zag-js/types';
3
+ import * as _zag_js_core from '@zag-js/core';
4
+ import { StateMachine } from '@zag-js/core';
5
+
6
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "tablist" | "trigger" | "contentGroup" | "content" | "indicator">;
7
+
8
+ type IntlTranslations = {
9
+ tablistLabel?: string;
10
+ };
11
+ type ElementIds = Partial<{
12
+ root: string;
13
+ trigger: string;
14
+ tablist: string;
15
+ contentGroup: string;
16
+ content: string;
17
+ indicator: string;
18
+ }>;
19
+ type TriggerProps = {
20
+ value: string;
21
+ disabled?: boolean;
22
+ };
23
+ type ContentProps = {
24
+ value: string;
25
+ };
26
+ type PublicContext = DirectionProperty & CommonProperties & {
27
+ /**
28
+ * The ids of the elements in the tabs. Useful for composition.
29
+ */
30
+ ids?: ElementIds;
31
+ /**
32
+ * Specifies the localized strings that identifies the accessibility elements and their states
33
+ */
34
+ translations: IntlTranslations;
35
+ /**
36
+ * Whether the keyboard navigation will loop from last tab to first, and vice versa.
37
+ * @default true
38
+ */
39
+ loop: boolean;
40
+ /**
41
+ * The selected tab id
42
+ */
43
+ value: string | null;
44
+ /**
45
+ * The orientation of the tabs. Can be `horizontal` or `vertical`
46
+ * - `horizontal`: only left and right arrow key navigation will work.
47
+ * - `vertical`: only up and down arrow key navigation will work.
48
+ *
49
+ * @default "horizontal"
50
+ */
51
+ orientation?: "horizontal" | "vertical";
52
+ /**
53
+ * The activation mode of the tabs. Can be `manual` or `automatic`
54
+ * - `manual`: Tabs are activated when clicked or press `enter` key.
55
+ * - `automatic`: Tabs are activated when receiving focus
56
+ * @default "automatic"
57
+ */
58
+ activationMode?: "manual" | "automatic";
59
+ /**
60
+ * Callback to be called when the selected/active tab changes
61
+ */
62
+ onChange?: (details: {
63
+ value: string | null;
64
+ }) => void;
65
+ /**
66
+ * Callback to be called when the focused tab changes
67
+ */
68
+ onFocus?: (details: {
69
+ value: string | null;
70
+ }) => void;
71
+ /**
72
+ * Callback to be called when a tab's close button is clicked
73
+ */
74
+ onDelete?: (details: {
75
+ value: string;
76
+ }) => void;
77
+ };
78
+ type UserDefinedContext = RequiredBy<PublicContext, "id">;
79
+ type ComputedContext = Readonly<{
80
+ /**
81
+ * @computed
82
+ * Whether the tab is in the horizontal orientation
83
+ */
84
+ isHorizontal: boolean;
85
+ /**
86
+ * @computed
87
+ * Whether the tab is in the vertical orientation
88
+ */
89
+ isVertical: boolean;
90
+ }>;
91
+ type PrivateContext = Context<{}>;
92
+ type MachineContext = PublicContext & ComputedContext & PrivateContext;
93
+ type MachineState = {
94
+ value: "idle" | "focused";
95
+ };
96
+ type State = StateMachine.State<MachineContext, MachineState>;
97
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
98
+
99
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
100
+ /**
101
+ * The current value of the tabs.
102
+ */
103
+ value: string | null;
104
+ /**
105
+ * The value of the tab that is currently focused.
106
+ */
107
+ focusedValue: string | null;
108
+ /**
109
+ * The previous values of the tabs in sequence of selection.
110
+ */
111
+ previousValues: string[];
112
+ /**
113
+ * Sets the value of the tabs.
114
+ */
115
+ setValue(value: string): void;
116
+ /**
117
+ * Clears the value of the tabs.
118
+ */
119
+ clearValue(): void;
120
+ /**
121
+ * Sets the indicator rect to the tab with the given id.
122
+ */
123
+ setIndicatorRect(id: string | null | undefined): void;
124
+ rootProps: T["element"];
125
+ tablistProps: T["element"];
126
+ getTriggerProps(props: TriggerProps): T["button"];
127
+ contentGroupProps: T["element"];
128
+ getContentProps({ value }: ContentProps): T["element"];
129
+ indicatorProps: T["element"];
130
+ };
131
+
132
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
133
+
134
+ export { ContentProps, UserDefinedContext as Context, TriggerProps, anatomy, connect, machine };