@destyler/tabs 0.0.7-beta.7 → 0.1.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.ts CHANGED
@@ -1,207 +1,220 @@
1
- import * as _zag_js_anatomy from '@zag-js/anatomy';
2
- import { DirectionProperty, CommonProperties, PropTypes, RequiredBy, NormalizeProps } from '@zag-js/types';
3
- import * as _zag_js_core from '@zag-js/core';
4
- import { StateMachine, Machine } from '@zag-js/core';
5
-
6
- declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "list" | "trigger" | "content" | "indicator">;
1
+ import * as _destyler_anatomy0 from "@destyler/anatomy";
2
+ import * as _destyler_xstate0 from "@destyler/xstate";
3
+ import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
4
+ import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, RequiredBy } from "@destyler/types";
7
5
 
6
+ //#region src/anatomy.d.ts
7
+ declare const anatomy: _destyler_anatomy0.AnatomyInstance<"root" | "list" | "trigger" | "content" | "indicator">;
8
+ //#endregion
9
+ //#region src/types.d.ts
8
10
  interface ValueChangeDetails {
9
- value: string;
11
+ value: string;
10
12
  }
11
13
  interface FocusChangeDetails {
12
- focusedValue: string;
14
+ focusedValue: string;
15
+ }
16
+ interface NavigateDetails {
17
+ value: string | null;
18
+ node: HTMLAnchorElement;
13
19
  }
14
20
  interface IntlTranslations {
15
- listLabel?: string | undefined;
21
+ listLabel?: string | undefined;
16
22
  }
17
23
  type ElementIds = Partial<{
18
- root: string;
19
- trigger: string;
20
- list: string;
21
- content: string;
22
- indicator: string;
24
+ root: string;
25
+ trigger: string;
26
+ list: string;
27
+ content: string;
28
+ indicator: string;
23
29
  }>;
24
30
  interface PublicContext extends DirectionProperty, CommonProperties {
25
- /**
26
- * The ids of the elements in the tabs. Useful for composition.
27
- */
28
- ids?: ElementIds | undefined;
29
- /**
30
- * Specifies the localized strings that identifies the accessibility elements and their states
31
- */
32
- translations?: IntlTranslations | undefined;
33
- /**
34
- * Whether the keyboard navigation will loop from last tab to first, and vice versa.
35
- * @default true
36
- */
37
- loopFocus: boolean;
38
- /**
39
- * The selected tab id
40
- */
41
- value: string | null;
42
- /**
43
- * The orientation of the tabs. Can be `horizontal` or `vertical`
44
- * - `horizontal`: only left and right arrow key navigation will work.
45
- * - `vertical`: only up and down arrow key navigation will work.
46
- *
47
- * @default "horizontal"
48
- */
49
- orientation?: 'horizontal' | 'vertical' | undefined;
50
- /**
51
- * The activation mode of the tabs. Can be `manual` or `automatic`
52
- * - `manual`: Tabs are activated when clicked or press `enter` key.
53
- * - `automatic`: Tabs are activated when receiving focus
54
- *
55
- * @default "automatic"
56
- */
57
- activationMode?: 'manual' | 'automatic' | undefined;
58
- /**
59
- * Callback to be called when the selected/active tab changes
60
- */
61
- onValueChange?: ((details: ValueChangeDetails) => void) | undefined;
62
- /**
63
- * Callback to be called when the focused tab changes
64
- */
65
- onFocusChange?: ((details: FocusChangeDetails) => void) | undefined;
66
- /**
67
- * Whether the tab is composite
68
- */
69
- composite: boolean;
70
- /**
71
- * Whether the active tab can be deselected when clicking on it.
72
- */
73
- deselectable?: boolean | undefined;
31
+ /**
32
+ * The ids of the elements in the tabs. Useful for composition.
33
+ */
34
+ ids?: ElementIds | undefined;
35
+ /**
36
+ * Specifies the localized strings that identifies the accessibility elements and their states
37
+ */
38
+ translations?: IntlTranslations | undefined;
39
+ /**
40
+ * Whether the keyboard navigation will loop from last tab to first, and vice versa.
41
+ * @default true
42
+ */
43
+ loopFocus: boolean;
44
+ /**
45
+ * The selected tab id
46
+ */
47
+ value: string | null;
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;
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;
74
85
  }
75
86
  type UserDefinedContext = RequiredBy<PublicContext, 'id'>;
76
87
  type ComputedContext = Readonly<{}>;
77
88
  interface IndicatorState {
78
- rendered: boolean;
79
- rect: Partial<{
80
- left: string;
81
- top: string;
82
- width: string;
83
- height: string;
84
- }>;
85
- transition: boolean;
89
+ rendered: boolean;
90
+ rect: Partial<{
91
+ left: string;
92
+ top: string;
93
+ width: string;
94
+ height: string;
95
+ }>;
96
+ transition: boolean;
86
97
  }
87
98
  interface PrivateContext {
88
- /**
89
- * @internal
90
- * The focused tab id
91
- */
92
- focusedValue: string | null;
93
- /**
94
- * @internal
95
- * The active tab indicator details
96
- */
97
- indicatorState: IndicatorState;
98
- /**
99
- * @internal
100
- * Function to clean up the observer for the active tab's rect
101
- */
102
- indicatorCleanup?: VoidFunction | null | undefined;
103
- /**
104
- * @internal
105
- * Whether the radio group is in server-side rendering
106
- */
107
- ssr: boolean;
108
- }
109
- interface MachineContext extends PublicContext, ComputedContext, PrivateContext {
99
+ /**
100
+ * @internal
101
+ * The focused tab id
102
+ */
103
+ focusedValue: string | null;
104
+ /**
105
+ * @internal
106
+ * The active tab indicator details
107
+ */
108
+ indicatorState: IndicatorState;
109
+ /**
110
+ * @internal
111
+ * Function to clean up the observer for the active tab's rect
112
+ */
113
+ indicatorCleanup?: VoidFunction | null | undefined;
114
+ /**
115
+ * @internal
116
+ * Whether the radio group is in server-side rendering
117
+ */
118
+ ssr: boolean;
110
119
  }
120
+ interface MachineContext extends PublicContext, ComputedContext, PrivateContext {}
111
121
  interface MachineState {
112
- value: 'idle' | 'focused';
122
+ value: 'idle' | 'focused';
113
123
  }
114
- type State = StateMachine.State<MachineContext, MachineState>;
115
- type Send = StateMachine.Send<StateMachine.AnyEventObject>;
116
- type Service = Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
124
+ type State = XState<MachineContext, MachineState>;
125
+ type Send = XSend<AnyEventObject>;
126
+ type Service = Machine<MachineContext, MachineState, AnyEventObject>;
117
127
  interface TriggerProps {
118
- /**
119
- * The value of the tab
120
- */
121
- value: string;
122
- /**
123
- * Whether the tab is disabled
124
- */
125
- disabled?: boolean | undefined;
128
+ /**
129
+ * The value of the tab
130
+ */
131
+ value: string;
132
+ /**
133
+ * Whether the tab is disabled
134
+ */
135
+ disabled?: boolean | undefined;
126
136
  }
127
137
  interface TriggerState {
128
- /**
129
- * Whether the tab is selected
130
- */
131
- selected: boolean;
132
- /**
133
- * Whether the tab is focused
134
- */
135
- focused: boolean;
136
- /**
137
- * Whether the tab is disabled
138
- */
139
- disabled: boolean;
138
+ /**
139
+ * Whether the tab is selected
140
+ */
141
+ selected: boolean;
142
+ /**
143
+ * Whether the tab is focused
144
+ */
145
+ focused: boolean;
146
+ /**
147
+ * Whether the tab is disabled
148
+ */
149
+ disabled: boolean;
140
150
  }
141
151
  interface ContentProps {
142
- /**
143
- * The value of the tab
144
- */
145
- value: string;
152
+ /**
153
+ * The value of the tab
154
+ */
155
+ value: string;
146
156
  }
147
157
  interface MachineApi<T extends PropTypes = PropTypes> {
148
- /**
149
- * The current value of the tabs.
150
- */
151
- value: string | null;
152
- /**
153
- * The value of the tab that is currently focused.
154
- */
155
- focusedValue: string | null;
156
- /**
157
- * Sets the value of the tabs.
158
- */
159
- setValue: (value: string) => void;
160
- /**
161
- * Clears the value of the tabs.
162
- */
163
- clearValue: () => void;
164
- /**
165
- * Sets the indicator rect to the tab with the given value
166
- */
167
- setIndicatorRect: (value: string) => void;
168
- /**
169
- * Synchronizes the tab index of the content element.
170
- * Useful when rendering tabs within a select or combobox
171
- */
172
- syncTabIndex: () => void;
173
- /**
174
- * Set focus on the selected tab trigger
175
- */
176
- focus: () => void;
177
- /**
178
- * Selects the next tab
179
- */
180
- selectNext: (fromValue?: string) => void;
181
- /**
182
- * Selects the previous tab
183
- */
184
- selectPrev: (fromValue?: string) => void;
185
- /**
186
- * Returns the state of the trigger with the given props
187
- */
188
- getTriggerState: (props: TriggerProps) => TriggerState;
189
- getRootProps: () => T['element'];
190
- getListProps: () => T['element'];
191
- getTriggerProps: (props: TriggerProps) => T['button'];
192
- getContentProps: (props: ContentProps) => T['element'];
193
- getIndicatorProps: () => T['element'];
158
+ /**
159
+ * The current value of the tabs.
160
+ */
161
+ value: string | null;
162
+ /**
163
+ * The value of the tab that is currently focused.
164
+ */
165
+ focusedValue: string | null;
166
+ /**
167
+ * Sets the value of the tabs.
168
+ */
169
+ setValue: (value: string) => void;
170
+ /**
171
+ * Clears the value of the tabs.
172
+ */
173
+ clearValue: () => void;
174
+ /**
175
+ * Sets the indicator rect to the tab with the given value
176
+ */
177
+ setIndicatorRect: (value: string) => void;
178
+ /**
179
+ * Synchronizes the tab index of the content element.
180
+ * Useful when rendering tabs within a select or combobox
181
+ */
182
+ syncTabIndex: () => void;
183
+ /**
184
+ * Set focus on the selected tab trigger
185
+ */
186
+ focus: () => void;
187
+ /**
188
+ * Selects the next tab
189
+ */
190
+ selectNext: (fromValue?: string) => void;
191
+ /**
192
+ * Selects the previous tab
193
+ */
194
+ selectPrev: (fromValue?: string) => void;
195
+ /**
196
+ * Returns the state of the trigger with the given props
197
+ */
198
+ getTriggerState: (props: TriggerProps) => TriggerState;
199
+ getRootProps: () => T['element'];
200
+ getListProps: () => T['element'];
201
+ getTriggerProps: (props: TriggerProps) => T['button'];
202
+ getContentProps: (props: ContentProps) => T['element'];
203
+ getIndicatorProps: () => T['element'];
194
204
  }
195
-
205
+ //#endregion
206
+ //#region src/connect.d.ts
196
207
  declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
197
-
198
- declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
199
-
200
- declare const props: ("ids" | "translations" | "loopFocus" | "value" | "orientation" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "id" | "dir" | "getRootNode")[];
201
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "ids" | "translations" | "loopFocus" | "value" | "orientation" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "id" | "dir" | "getRootNode">];
208
+ //#endregion
209
+ //#region src/machine.d.ts
210
+ declare function machine(userContext: UserDefinedContext): _destyler_xstate0.Machine<MachineContext, MachineState, _destyler_xstate0.AnyEventObject>;
211
+ //#endregion
212
+ //#region src/props.d.ts
213
+ declare const props: ("value" | "ids" | "translations" | "loopFocus" | "orientation" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate" | "dir" | "id" | "getRootNode")[];
214
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "value" | "ids" | "translations" | "loopFocus" | "orientation" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate" | "dir" | "id" | "getRootNode">];
202
215
  declare const triggerProps: (keyof TriggerProps)[];
203
216
  declare const splitTriggerProps: <Props extends TriggerProps>(props: Props) => [TriggerProps, Omit<Props, keyof TriggerProps>];
204
217
  declare const contentProps: "value"[];
205
218
  declare const splitContentProps: <Props extends ContentProps>(props: Props) => [ContentProps, Omit<Props, "value">];
206
-
207
- export { type MachineApi as Api, type ContentProps, type UserDefinedContext as Context, type ElementIds, type FocusChangeDetails, type IntlTranslations, type Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
219
+ //#endregion
220
+ export { type MachineApi as Api, type ContentProps, type UserDefinedContext as Context, type ElementIds, type FocusChangeDetails, type IntlTranslations, type Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };