@zag-js/tabs 0.82.1 → 1.0.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.
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, NormalizeProps } from '@zag-js/types';
3
2
  import * as _zag_js_core from '@zag-js/core';
4
- import { Machine, StateMachine } from '@zag-js/core';
3
+ import { Service, EventObject } from '@zag-js/core';
4
+ import { DirectionProperty, CommonProperties, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
5
5
 
6
6
  declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "list" | "trigger" | "content" | "indicator">;
7
7
 
@@ -25,7 +25,7 @@ type ElementIds = Partial<{
25
25
  content: string;
26
26
  indicator: string;
27
27
  }>;
28
- interface PublicContext extends DirectionProperty, CommonProperties {
28
+ interface TabsProps extends DirectionProperty, CommonProperties {
29
29
  /**
30
30
  * The ids of the elements in the tabs. Useful for composition.
31
31
  */
@@ -38,11 +38,16 @@ interface PublicContext extends DirectionProperty, CommonProperties {
38
38
  * Whether the keyboard navigation will loop from last tab to first, and vice versa.
39
39
  * @default true
40
40
  */
41
- loopFocus: boolean;
41
+ loopFocus?: boolean | undefined;
42
42
  /**
43
- * The selected tab id
43
+ * The controlled selected tab value
44
44
  */
45
- value: string | null;
45
+ value?: string | null | undefined;
46
+ /**
47
+ * The initial selected tab value when rendered.
48
+ * Use when you don't need to control the selected tab value.
49
+ */
50
+ defaultValue?: string | null | undefined;
46
51
  /**
47
52
  * The orientation of the tabs. Can be `horizontal` or `vertical`
48
53
  * - `horizontal`: only left and right arrow key navigation will work.
@@ -70,7 +75,7 @@ interface PublicContext extends DirectionProperty, CommonProperties {
70
75
  /**
71
76
  * Whether the tab is composite
72
77
  */
73
- composite: boolean;
78
+ composite?: boolean | undefined;
74
79
  /**
75
80
  * Whether the active tab can be deselected when clicking on it.
76
81
  */
@@ -79,20 +84,36 @@ interface PublicContext extends DirectionProperty, CommonProperties {
79
84
  * Function to navigate to the selected tab when clicking on it.
80
85
  * Useful if tab triggers are anchor elements.
81
86
  */
82
- navigate: (details: NavigateDetails) => void;
83
- }
84
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
85
- type ComputedContext = Readonly<{}>;
86
- interface PrivateContext {
87
- }
88
- interface MachineContext extends PublicContext, ComputedContext, PrivateContext {
89
- }
90
- interface MachineState {
91
- value: "idle" | "focused";
87
+ navigate?: ((details: NavigateDetails) => void) | undefined;
92
88
  }
93
- type State = StateMachine.State<MachineContext, MachineState>;
94
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
95
- type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
89
+ type PropsWithDefault = "orientation" | "activationMode" | "loopFocus";
90
+ type TabsSchema = {
91
+ state: "idle" | "focused";
92
+ props: RequiredBy<TabsProps, PropsWithDefault>;
93
+ context: {
94
+ ssr: boolean;
95
+ value: string | null;
96
+ focusedValue: string | null;
97
+ indicatorTransition: boolean;
98
+ indicatorRect: {
99
+ left: string;
100
+ top: string;
101
+ width: string;
102
+ height: string;
103
+ };
104
+ };
105
+ refs: {
106
+ indicatorCleanup: VoidFunction | null | undefined;
107
+ };
108
+ computed: {
109
+ focused: boolean;
110
+ };
111
+ action: string;
112
+ guard: string;
113
+ effect: string;
114
+ event: EventObject;
115
+ };
116
+ type TabsService = Service<TabsSchema>;
96
117
  interface TriggerProps {
97
118
  /**
98
119
  * The value of the tab
@@ -123,7 +144,7 @@ interface ContentProps {
123
144
  */
124
145
  value: string;
125
146
  }
126
- interface MachineApi<T extends PropTypes = PropTypes> {
147
+ interface TabsApi<T extends PropTypes = PropTypes> {
127
148
  /**
128
149
  * The current value of the tabs.
129
150
  */
@@ -172,15 +193,15 @@ interface MachineApi<T extends PropTypes = PropTypes> {
172
193
  getIndicatorProps(): T["element"];
173
194
  }
174
195
 
175
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
196
+ declare function connect<T extends PropTypes>(service: Service<TabsSchema>, normalize: NormalizeProps<T>): TabsApi<T>;
176
197
 
177
- declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
198
+ declare const machine: _zag_js_core.MachineConfig<TabsSchema>;
178
199
 
179
- declare const props: ("dir" | "id" | "value" | "orientation" | "getRootNode" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate")[];
180
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "dir" | "id" | "value" | "orientation" | "getRootNode" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate">];
200
+ declare const props: (keyof TabsProps)[];
201
+ declare const splitProps: <Props extends Partial<TabsProps>>(props: Props) => [Partial<TabsProps>, Omit<Props, keyof TabsProps>];
181
202
  declare const triggerProps: (keyof TriggerProps)[];
182
203
  declare const splitTriggerProps: <Props extends TriggerProps>(props: Props) => [TriggerProps, Omit<Props, keyof TriggerProps>];
183
204
  declare const contentProps: "value"[];
184
205
  declare const splitContentProps: <Props extends ContentProps>(props: Props) => [ContentProps, Omit<Props, "value">];
185
206
 
186
- export { type MachineApi as Api, type ContentProps, type UserDefinedContext as Context, type ElementIds, type FocusChangeDetails, type IntlTranslations, type NavigateDetails, type Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
207
+ export { type TabsApi as Api, type ContentProps, type ElementIds, type FocusChangeDetails, type IntlTranslations, type NavigateDetails, type TabsProps as Props, type TabsService as Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { RequiredBy, PropTypes, DirectionProperty, CommonProperties, NormalizeProps } from '@zag-js/types';
3
2
  import * as _zag_js_core from '@zag-js/core';
4
- import { Machine, StateMachine } from '@zag-js/core';
3
+ import { Service, EventObject } from '@zag-js/core';
4
+ import { DirectionProperty, CommonProperties, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
5
5
 
6
6
  declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "list" | "trigger" | "content" | "indicator">;
7
7
 
@@ -25,7 +25,7 @@ type ElementIds = Partial<{
25
25
  content: string;
26
26
  indicator: string;
27
27
  }>;
28
- interface PublicContext extends DirectionProperty, CommonProperties {
28
+ interface TabsProps extends DirectionProperty, CommonProperties {
29
29
  /**
30
30
  * The ids of the elements in the tabs. Useful for composition.
31
31
  */
@@ -38,11 +38,16 @@ interface PublicContext extends DirectionProperty, CommonProperties {
38
38
  * Whether the keyboard navigation will loop from last tab to first, and vice versa.
39
39
  * @default true
40
40
  */
41
- loopFocus: boolean;
41
+ loopFocus?: boolean | undefined;
42
42
  /**
43
- * The selected tab id
43
+ * The controlled selected tab value
44
44
  */
45
- value: string | null;
45
+ value?: string | null | undefined;
46
+ /**
47
+ * The initial selected tab value when rendered.
48
+ * Use when you don't need to control the selected tab value.
49
+ */
50
+ defaultValue?: string | null | undefined;
46
51
  /**
47
52
  * The orientation of the tabs. Can be `horizontal` or `vertical`
48
53
  * - `horizontal`: only left and right arrow key navigation will work.
@@ -70,7 +75,7 @@ interface PublicContext extends DirectionProperty, CommonProperties {
70
75
  /**
71
76
  * Whether the tab is composite
72
77
  */
73
- composite: boolean;
78
+ composite?: boolean | undefined;
74
79
  /**
75
80
  * Whether the active tab can be deselected when clicking on it.
76
81
  */
@@ -79,20 +84,36 @@ interface PublicContext extends DirectionProperty, CommonProperties {
79
84
  * Function to navigate to the selected tab when clicking on it.
80
85
  * Useful if tab triggers are anchor elements.
81
86
  */
82
- navigate: (details: NavigateDetails) => void;
83
- }
84
- type UserDefinedContext = RequiredBy<PublicContext, "id">;
85
- type ComputedContext = Readonly<{}>;
86
- interface PrivateContext {
87
- }
88
- interface MachineContext extends PublicContext, ComputedContext, PrivateContext {
89
- }
90
- interface MachineState {
91
- value: "idle" | "focused";
87
+ navigate?: ((details: NavigateDetails) => void) | undefined;
92
88
  }
93
- type State = StateMachine.State<MachineContext, MachineState>;
94
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
95
- type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
89
+ type PropsWithDefault = "orientation" | "activationMode" | "loopFocus";
90
+ type TabsSchema = {
91
+ state: "idle" | "focused";
92
+ props: RequiredBy<TabsProps, PropsWithDefault>;
93
+ context: {
94
+ ssr: boolean;
95
+ value: string | null;
96
+ focusedValue: string | null;
97
+ indicatorTransition: boolean;
98
+ indicatorRect: {
99
+ left: string;
100
+ top: string;
101
+ width: string;
102
+ height: string;
103
+ };
104
+ };
105
+ refs: {
106
+ indicatorCleanup: VoidFunction | null | undefined;
107
+ };
108
+ computed: {
109
+ focused: boolean;
110
+ };
111
+ action: string;
112
+ guard: string;
113
+ effect: string;
114
+ event: EventObject;
115
+ };
116
+ type TabsService = Service<TabsSchema>;
96
117
  interface TriggerProps {
97
118
  /**
98
119
  * The value of the tab
@@ -123,7 +144,7 @@ interface ContentProps {
123
144
  */
124
145
  value: string;
125
146
  }
126
- interface MachineApi<T extends PropTypes = PropTypes> {
147
+ interface TabsApi<T extends PropTypes = PropTypes> {
127
148
  /**
128
149
  * The current value of the tabs.
129
150
  */
@@ -172,15 +193,15 @@ interface MachineApi<T extends PropTypes = PropTypes> {
172
193
  getIndicatorProps(): T["element"];
173
194
  }
174
195
 
175
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
196
+ declare function connect<T extends PropTypes>(service: Service<TabsSchema>, normalize: NormalizeProps<T>): TabsApi<T>;
176
197
 
177
- declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
198
+ declare const machine: _zag_js_core.MachineConfig<TabsSchema>;
178
199
 
179
- declare const props: ("dir" | "id" | "value" | "orientation" | "getRootNode" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate")[];
180
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "dir" | "id" | "value" | "orientation" | "getRootNode" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate">];
200
+ declare const props: (keyof TabsProps)[];
201
+ declare const splitProps: <Props extends Partial<TabsProps>>(props: Props) => [Partial<TabsProps>, Omit<Props, keyof TabsProps>];
181
202
  declare const triggerProps: (keyof TriggerProps)[];
182
203
  declare const splitTriggerProps: <Props extends TriggerProps>(props: Props) => [TriggerProps, Omit<Props, keyof TriggerProps>];
183
204
  declare const contentProps: "value"[];
184
205
  declare const splitContentProps: <Props extends ContentProps>(props: Props) => [ContentProps, Omit<Props, "value">];
185
206
 
186
- export { type MachineApi as Api, type ContentProps, type UserDefinedContext as Context, type ElementIds, type FocusChangeDetails, type IntlTranslations, type NavigateDetails, type Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
207
+ export { type TabsApi as Api, type ContentProps, type ElementIds, type FocusChangeDetails, type IntlTranslations, type NavigateDetails, type TabsProps as Props, type TabsService as Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };