@hanzogui/tabs-headless 8.3.1 → 8.3.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.
@@ -98,18 +98,18 @@ export interface UseTabProps {
98
98
  export declare function useTab(props: UseTabProps): {
99
99
  isSelected: boolean;
100
100
  tabProps: {
101
- disabled: boolean | undefined;
102
- tabIndex: number;
103
- onKeyDown: import("@hanzogui/helpers").EventHandler<React.KeyboardEvent<Element>> | undefined;
104
- onPress: import("@hanzogui/helpers").EventHandler<any> | undefined;
105
- onFocus: import("@hanzogui/helpers").EventHandler<React.FocusEvent<Element, Element>> | undefined;
106
- 'data-disabled'?: "" | undefined;
107
101
  ref: React.RefObject<HTMLElement | null>;
108
- role: "tab";
102
+ role: 'tab';
109
103
  id: string;
110
104
  'aria-selected': boolean;
111
105
  'aria-controls': string;
112
106
  'data-state': string;
107
+ 'data-disabled'?: "" | undefined;
108
+ disabled: boolean | undefined;
109
+ tabIndex: number;
110
+ onKeyDown: import("@hanzogui/helpers").EventHandler<React.KeyboardEvent<Element>> | undefined;
111
+ onPress: import("@hanzogui/helpers").EventHandler<any> | undefined;
112
+ onFocus: import("@hanzogui/helpers").EventHandler<React.FocusEvent<Element, Element>> | undefined;
113
113
  };
114
114
  };
115
115
  export interface UseTabContentProps {
@@ -120,7 +120,7 @@ export declare function useTabContent(props: UseTabContentProps): {
120
120
  isSelected: boolean;
121
121
  shouldMount: boolean;
122
122
  contentProps: {
123
- role: "tabpanel";
123
+ role: 'tabpanel';
124
124
  id: string;
125
125
  'aria-labelledby': string;
126
126
  'data-state': string;
@@ -1 +1 @@
1
- {"version":3,"file":"useTabs.d.ts","sourceRoot":"","sources":["../src/useTabs.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,QAAQ,CAAA;AACvD,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,UAA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A;IACf,QAAQ,EAAE,CAAC,CAAA;CACZ;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,WAAW,EAAE,eAAe,CAAA;IAC5B,SAAS,EAAE,SAAS,CAAA;IACpB,cAAc,EAAE,kBAAkB,CAAA;IAClC,IAAI,EAAE,OAAO,CAAA;CACd;AAED,wBAAgB,OAAO,CAAC,KAAK,GAAE,YAAiB,GAAG,aAAa,CAyL/D;AAQD,eAAO,MAAM,YAAY,yCAAuB,CAAA;AAEhD,wBAAgB,cAAc,IAAI,gBAAgB,CAMjD;AAMD,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;IAC9B,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,CAAA;IAChD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,KAAK,IAAI,CAAA;CAC5C;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW;;;;cAgB7B,KAAK;;;;;;;;;;;;EA2BhB;AAMD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB;;;;cAa3C,UAAU;;;;;;;;EASrB"}
@@ -1,20 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
8
- get: () => from[key],
9
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
10
- });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
16
- value: true
17
- }), mod);
18
- var index_exports = {};
19
- module.exports = __toCommonJS(index_exports);
20
- __reExport(index_exports, require("./useTabs.cjs"), module.exports);
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") {
9
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
10
- get: () => from[key],
11
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
12
- });
13
- }
14
- return to;
15
- };
16
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
18
- value: true
19
- }), mod);
20
- var index_exports = {};
21
- module.exports = __toCommonJS(index_exports);
22
- __reExport(index_exports, require("./useTabs.native.js"), module.exports);
23
- //# sourceMappingURL=index.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA","ignoreList":[]}
@@ -1,305 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
30
- }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
34
- var useTabs_exports = {};
35
- __export(useTabs_exports, {
36
- TabsProvider: () => TabsProvider,
37
- useTab: () => useTab,
38
- useTabContent: () => useTabContent,
39
- useTabs: () => useTabs,
40
- useTabsContext: () => useTabsContext
41
- });
42
- module.exports = __toCommonJS(useTabs_exports);
43
- var import_helpers = require("@hanzogui/helpers");
44
- var import_use_controllable_state = require("@hanzogui/use-controllable-state");
45
- var import_use_direction = require("@hanzogui/use-direction");
46
- var React = __toESM(require("react"), 1);
47
- var import_react = require("react");
48
- function useTabs(props = {}) {
49
- const {
50
- value: valueProp,
51
- onValueChange,
52
- defaultValue = "",
53
- orientation = "horizontal",
54
- dir,
55
- activationMode = "automatic",
56
- loop = true
57
- } = props;
58
- const direction = (0, import_use_direction.useDirection)(dir);
59
- const baseId = (0, import_react.useId)();
60
- const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
61
- prop: valueProp,
62
- onChange: onValueChange,
63
- defaultProp: defaultValue
64
- });
65
- const tabRefs = (0, import_react.useRef)(/* @__PURE__ */new Map());
66
- const [tabValues, setTabValues] = (0, import_react.useState)([]);
67
- const registerTab = (0, import_react.useCallback)((tabValue, element) => {
68
- if (element) {
69
- tabRefs.current.set(tabValue, element);
70
- setTabValues(prev => prev.includes(tabValue) ? prev : [...prev, tabValue]);
71
- } else {
72
- tabRefs.current.delete(tabValue);
73
- setTabValues(prev => prev.filter(v => v !== tabValue));
74
- }
75
- }, []);
76
- const focusTab = (0, import_react.useCallback)(tabValue => {
77
- const element = tabRefs.current.get(tabValue);
78
- element?.focus();
79
- }, []);
80
- const getNextTab = (0, import_react.useCallback)((currentValue, direction2) => {
81
- const currentIndex = tabValues.indexOf(currentValue);
82
- if (currentIndex === -1) return null;
83
- let nextIndex = currentIndex + direction2;
84
- if (loop) {
85
- nextIndex = (nextIndex + tabValues.length) % tabValues.length;
86
- } else {
87
- if (nextIndex < 0 || nextIndex >= tabValues.length) return null;
88
- }
89
- return tabValues[nextIndex] ?? null;
90
- }, [tabValues, loop]);
91
- const handleKeyDown = (0, import_react.useCallback)(tabValue => event => {
92
- const isHorizontal = orientation === "horizontal";
93
- const isRtl = direction === "rtl";
94
- let nextTab = null;
95
- switch (event.key) {
96
- case "ArrowRight":
97
- if (isHorizontal) {
98
- nextTab = getNextTab(tabValue, isRtl ? -1 : 1);
99
- }
100
- break;
101
- case "ArrowLeft":
102
- if (isHorizontal) {
103
- nextTab = getNextTab(tabValue, isRtl ? 1 : -1);
104
- }
105
- break;
106
- case "ArrowDown":
107
- if (!isHorizontal) {
108
- nextTab = getNextTab(tabValue, 1);
109
- }
110
- break;
111
- case "ArrowUp":
112
- if (!isHorizontal) {
113
- nextTab = getNextTab(tabValue, -1);
114
- }
115
- break;
116
- case "Home":
117
- nextTab = tabValues[0] ?? null;
118
- break;
119
- case "End":
120
- nextTab = tabValues[tabValues.length - 1] ?? null;
121
- break;
122
- case " ":
123
- case "Enter":
124
- if (activationMode === "manual") {
125
- setValue(tabValue);
126
- event.preventDefault();
127
- }
128
- return;
129
- }
130
- if (nextTab) {
131
- event.preventDefault();
132
- focusTab(nextTab);
133
- if (activationMode === "automatic") {
134
- setValue(nextTab);
135
- }
136
- }
137
- }, [orientation, direction, getNextTab, tabValues, activationMode, setValue, focusTab]);
138
- const getTabProps = (0, import_react.useCallback)((tabValue, disabled) => {
139
- const isSelected = value === tabValue;
140
- const triggerId = makeTriggerId(baseId, tabValue);
141
- const contentId = makeContentId(baseId, tabValue);
142
- return {
143
- role: "tab",
144
- id: triggerId,
145
- "aria-selected": isSelected,
146
- "aria-controls": contentId,
147
- "data-state": isSelected ? "active" : "inactive",
148
- ...(disabled && {
149
- "data-disabled": ""
150
- }),
151
- disabled,
152
- tabIndex: isSelected ? 0 : -1,
153
- onKeyDown: disabled ? () => {} : handleKeyDown(tabValue),
154
- onClick: event => {
155
- if (!disabled && !isSelected) {
156
- setValue(tabValue);
157
- }
158
- },
159
- onFocus: event => {
160
- registerTab(tabValue, event.currentTarget);
161
- if (!disabled && !isSelected && activationMode === "automatic") {
162
- setValue(tabValue);
163
- }
164
- }
165
- };
166
- }, [value, baseId, handleKeyDown, setValue, activationMode, registerTab]);
167
- const getContentProps = (0, import_react.useCallback)(tabValue => {
168
- const isSelected = value === tabValue;
169
- const triggerId = makeTriggerId(baseId, tabValue);
170
- const contentId = makeContentId(baseId, tabValue);
171
- return {
172
- role: "tabpanel",
173
- id: contentId,
174
- "aria-labelledby": triggerId,
175
- "data-state": isSelected ? "active" : "inactive",
176
- "data-orientation": orientation,
177
- hidden: !isSelected,
178
- tabIndex: 0
179
- };
180
- }, [value, baseId, orientation]);
181
- const contextValue = {
182
- baseId,
183
- value,
184
- setValue,
185
- orientation,
186
- direction,
187
- activationMode,
188
- loop
189
- };
190
- return {
191
- value,
192
- setValue,
193
- direction,
194
- tabsProps: {
195
- "data-orientation": orientation,
196
- dir: direction
197
- },
198
- listProps: {
199
- role: "tablist",
200
- "aria-orientation": orientation
201
- },
202
- getTabProps,
203
- getContentProps,
204
- contextValue
205
- };
206
- }
207
- const TabsContext = React.createContext(null);
208
- const TabsProvider = TabsContext.Provider;
209
- function useTabsContext() {
210
- const context = React.useContext(TabsContext);
211
- if (!context) {
212
- throw new Error("useTabsContext must be used within a TabsProvider");
213
- }
214
- return context;
215
- }
216
- function useTab(props) {
217
- const {
218
- value: tabValue,
219
- disabled,
220
- onPress,
221
- onKeyDown,
222
- onFocus
223
- } = props;
224
- const context = useTabsContext();
225
- const {
226
- value,
227
- setValue,
228
- baseId,
229
- activationMode,
230
- orientation,
231
- direction,
232
- loop
233
- } = context;
234
- const isSelected = value === tabValue;
235
- const triggerId = makeTriggerId(baseId, tabValue);
236
- const contentId = makeContentId(baseId, tabValue);
237
- const ref = (0, import_react.useRef)(null);
238
- return {
239
- isSelected,
240
- tabProps: {
241
- ref,
242
- role: "tab",
243
- id: triggerId,
244
- "aria-selected": isSelected,
245
- "aria-controls": contentId,
246
- "data-state": isSelected ? "active" : "inactive",
247
- ...(disabled && {
248
- "data-disabled": ""
249
- }),
250
- disabled,
251
- tabIndex: isSelected ? 0 : -1,
252
- onKeyDown: (0, import_helpers.composeEventHandlers)(onKeyDown, event => {
253
- if (disabled) return;
254
- if ([" ", "Enter"].includes(event.key)) {
255
- setValue(tabValue);
256
- event.preventDefault();
257
- }
258
- }),
259
- onPress: (0, import_helpers.composeEventHandlers)(onPress, () => {
260
- if (!disabled && !isSelected) {
261
- setValue(tabValue);
262
- }
263
- }),
264
- onFocus: (0, import_helpers.composeEventHandlers)(onFocus, () => {
265
- if (!disabled && !isSelected && activationMode === "automatic") {
266
- setValue(tabValue);
267
- }
268
- })
269
- }
270
- };
271
- }
272
- function useTabContent(props) {
273
- const {
274
- value: tabValue,
275
- forceMount
276
- } = props;
277
- const context = useTabsContext();
278
- const {
279
- value,
280
- baseId,
281
- orientation
282
- } = context;
283
- const isSelected = value === tabValue;
284
- const triggerId = makeTriggerId(baseId, tabValue);
285
- const contentId = makeContentId(baseId, tabValue);
286
- return {
287
- isSelected,
288
- shouldMount: forceMount || isSelected,
289
- contentProps: {
290
- role: "tabpanel",
291
- id: contentId,
292
- "aria-labelledby": triggerId,
293
- "data-state": isSelected ? "active" : "inactive",
294
- "data-orientation": orientation,
295
- hidden: !isSelected,
296
- tabIndex: 0
297
- }
298
- };
299
- }
300
- function makeTriggerId(baseId, value) {
301
- return `${baseId}-trigger-${value}`;
302
- }
303
- function makeContentId(baseId, value) {
304
- return `${baseId}-content-${value}`;
305
- }