@tamagui/tabs 1.110.5 → 1.111.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.
@@ -0,0 +1,289 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { composeRefs } from "@tamagui/compose-refs";
3
+ import { isWeb } from "@tamagui/constants";
4
+ import { getButtonSized } from "@tamagui/get-button-sized";
5
+ import { Group, useGroupItem } from "@tamagui/group";
6
+ import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
7
+ import { RovingFocusGroup } from "@tamagui/roving-focus";
8
+ import { SizableStack, ThemeableStack } from "@tamagui/stacks";
9
+ import { useControllableState } from "@tamagui/use-controllable-state";
10
+ import { useDirection } from "@tamagui/use-direction";
11
+ import { Theme, createStyledContext, styled, useEvent } from "@tamagui/web";
12
+ import * as React from "react";
13
+ var TABS_CONTEXT = "TabsContext",
14
+ TAB_LIST_NAME = "TabsList",
15
+ TabsList = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
16
+ var {
17
+ __scopeTabs,
18
+ loop = !0,
19
+ children,
20
+ ...listProps
21
+ } = props,
22
+ context = useTabsContext(__scopeTabs);
23
+ return /* @__PURE__ */_jsx(RovingFocusGroup, {
24
+ __scopeRovingFocusGroup: __scopeTabs || TABS_CONTEXT,
25
+ orientation: context.orientation,
26
+ dir: context.dir,
27
+ loop,
28
+ asChild: !0,
29
+ children: /* @__PURE__ */_jsx(Group, {
30
+ role: "tablist",
31
+ componentName: TAB_LIST_NAME,
32
+ "aria-orientation": context.orientation,
33
+ ref: forwardedRef,
34
+ orientation: context.orientation,
35
+ ...listProps,
36
+ children
37
+ })
38
+ });
39
+ });
40
+ TabsList.displayName = TAB_LIST_NAME;
41
+ var TRIGGER_NAME = "TabsTrigger",
42
+ TabsTriggerFrame = styled(ThemeableStack, {
43
+ name: TRIGGER_NAME,
44
+ tag: "button",
45
+ justifyContent: "center",
46
+ alignItems: "center",
47
+ flexWrap: "nowrap",
48
+ flexDirection: "row",
49
+ cursor: "pointer",
50
+ userSelect: "none",
51
+ variants: {
52
+ size: {
53
+ "...size": getButtonSized
54
+ },
55
+ disabled: {
56
+ true: {
57
+ pointerEvents: "none"
58
+ }
59
+ },
60
+ active: {
61
+ true: {
62
+ hoverStyle: {
63
+ backgroundColor: "$background"
64
+ },
65
+ focusStyle: {
66
+ backgroundColor: "$background"
67
+ }
68
+ }
69
+ },
70
+ unstyled: {
71
+ false: {
72
+ backgroundColor: "$background",
73
+ pressStyle: {
74
+ backgroundColor: "$backgroundPress"
75
+ },
76
+ hoverStyle: {
77
+ backgroundColor: "$backgroundHover"
78
+ },
79
+ focusStyle: {
80
+ backgroundColor: "$backgroundFocus"
81
+ }
82
+ }
83
+ }
84
+ },
85
+ defaultVariants: {
86
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
87
+ }
88
+ }),
89
+ TabsTrigger = TabsTriggerFrame.styleable(function (props, forwardedRef) {
90
+ var {
91
+ __scopeTabs,
92
+ value,
93
+ disabled = !1,
94
+ onInteraction,
95
+ disableActiveTheme,
96
+ ...triggerProps
97
+ } = props,
98
+ context = useTabsContext(__scopeTabs),
99
+ triggerId = makeTriggerId(context.baseId, value),
100
+ contentId = makeContentId(context.baseId, value),
101
+ isSelected = value === context.value,
102
+ [layout, setLayout] = React.useState(null),
103
+ triggerRef = React.useRef(null),
104
+ groupItemProps = useGroupItem({
105
+ disabled: !!disabled
106
+ });
107
+ React.useEffect(function () {
108
+ return context.registerTrigger(), function () {
109
+ return context.unregisterTrigger();
110
+ };
111
+ }, []), React.useEffect(function () {
112
+ if (!triggerRef.current || !isWeb) return;
113
+ function getTriggerSize() {
114
+ triggerRef.current && setLayout({
115
+ width: triggerRef.current.offsetWidth,
116
+ height: triggerRef.current.offsetHeight,
117
+ x: triggerRef.current.offsetLeft,
118
+ y: triggerRef.current.offsetTop
119
+ });
120
+ }
121
+ getTriggerSize();
122
+ var observer = new ResizeObserver(getTriggerSize);
123
+ return observer.observe(triggerRef.current), function () {
124
+ triggerRef.current && observer.unobserve(triggerRef.current);
125
+ };
126
+ }, [context.triggersCount]), React.useEffect(function () {
127
+ isSelected && layout && onInteraction?.("select", layout);
128
+ }, [isSelected, value, layout]);
129
+ var _props_onPress;
130
+ return /* @__PURE__ */_jsx(Theme, {
131
+ name: isSelected && !disableActiveTheme ? "active" : null,
132
+ children: /* @__PURE__ */_jsx(RovingFocusGroup.Item, {
133
+ __scopeRovingFocusGroup: __scopeTabs || TABS_CONTEXT,
134
+ asChild: !0,
135
+ focusable: !disabled,
136
+ active: isSelected,
137
+ children: /* @__PURE__ */_jsx(TabsTriggerFrame, {
138
+ onLayout: function (event) {
139
+ isWeb || setLayout(event.nativeEvent.layout);
140
+ },
141
+ onHoverIn: composeEventHandlers(props.onHoverIn, function () {
142
+ layout && onInteraction?.("hover", layout);
143
+ }),
144
+ onHoverOut: composeEventHandlers(props.onHoverOut, function () {
145
+ onInteraction?.("hover", null);
146
+ }),
147
+ role: "tab",
148
+ "aria-selected": isSelected,
149
+ "aria-controls": contentId,
150
+ "data-state": isSelected ? "active" : "inactive",
151
+ "data-disabled": disabled ? "" : void 0,
152
+ disabled,
153
+ id: triggerId,
154
+ ...(!props.unstyled && {
155
+ size: context.size
156
+ }),
157
+ ...groupItemProps,
158
+ ...triggerProps,
159
+ ref: composeRefs(forwardedRef, triggerRef),
160
+ onPress: composeEventHandlers((_props_onPress = props.onPress) !== null && _props_onPress !== void 0 ? _props_onPress : void 0, function (event) {
161
+ var webChecks = !isWeb || event.button === 0 && event.ctrlKey === !1;
162
+ !disabled && !isSelected && webChecks ? context.onChange(value) : event.preventDefault();
163
+ }),
164
+ ...(isWeb && {
165
+ type: "button",
166
+ onKeyDown: composeEventHandlers(props.onKeyDown, function (event) {
167
+ [" ", "Enter"].includes(event.key) && (context.onChange(value), event.preventDefault());
168
+ }),
169
+ onFocus: composeEventHandlers(props.onFocus, function (event) {
170
+ layout && onInteraction?.("focus", layout);
171
+ var isAutomaticActivation = context.activationMode !== "manual";
172
+ !isSelected && !disabled && isAutomaticActivation && context.onChange(value);
173
+ }),
174
+ onBlur: composeEventHandlers(props.onFocus, function () {
175
+ onInteraction?.("focus", null);
176
+ })
177
+ })
178
+ })
179
+ })
180
+ });
181
+ });
182
+ TabsTrigger.displayName = TRIGGER_NAME;
183
+ var CONTENT_NAME = "TabsContent",
184
+ TabsContentFrame = styled(ThemeableStack, {
185
+ name: CONTENT_NAME
186
+ }),
187
+ TabsContent = TabsContentFrame.styleable(function (props, forwardedRef) {
188
+ var {
189
+ __scopeTabs,
190
+ value,
191
+ forceMount,
192
+ children,
193
+ ...contentProps
194
+ } = props,
195
+ context = useTabsContext(__scopeTabs),
196
+ isSelected = value === context.value,
197
+ show = forceMount || isSelected,
198
+ triggerId = makeTriggerId(context.baseId, value),
199
+ contentId = makeContentId(context.baseId, value);
200
+ return show ? /* @__PURE__ */_jsx(TabsContentFrame, {
201
+ "data-state": isSelected ? "active" : "inactive",
202
+ "data-orientation": context.orientation,
203
+ role: "tabpanel",
204
+ "aria-labelledby": triggerId,
205
+ // @ts-ignore
206
+ hidden: !show,
207
+ id: contentId,
208
+ tabIndex: 0,
209
+ ...contentProps,
210
+ ref: forwardedRef,
211
+ children
212
+ }, value) : null;
213
+ }),
214
+ TABS_NAME = "Tabs",
215
+ {
216
+ Provider: TabsProvider,
217
+ useStyledContext: useTabsContext
218
+ } = createStyledContext(),
219
+ TabsFrame = styled(SizableStack, {
220
+ name: TABS_NAME
221
+ }),
222
+ TabsComponent = TabsFrame.styleable(function (props, forwardedRef) {
223
+ var {
224
+ __scopeTabs,
225
+ value: valueProp,
226
+ onValueChange,
227
+ defaultValue,
228
+ orientation = "horizontal",
229
+ dir,
230
+ activationMode = "automatic",
231
+ size = "$true",
232
+ ...tabsProps
233
+ } = props,
234
+ direction = useDirection(dir),
235
+ [value, setValue] = useControllableState({
236
+ prop: valueProp,
237
+ onChange: onValueChange,
238
+ defaultProp: defaultValue ?? ""
239
+ }),
240
+ [triggersCount, setTriggersCount] = React.useState(0),
241
+ registerTrigger = useEvent(function () {
242
+ return setTriggersCount(function (v) {
243
+ return v + 1;
244
+ });
245
+ }),
246
+ unregisterTrigger = useEvent(function () {
247
+ return setTriggersCount(function (v) {
248
+ return v - 1;
249
+ });
250
+ });
251
+ return /* @__PURE__ */_jsx(TabsProvider, {
252
+ scope: __scopeTabs,
253
+ baseId: React.useId(),
254
+ value,
255
+ onChange: setValue,
256
+ orientation,
257
+ dir: direction,
258
+ activationMode,
259
+ size,
260
+ registerTrigger,
261
+ triggersCount,
262
+ unregisterTrigger,
263
+ children: /* @__PURE__ */_jsx(TabsFrame, {
264
+ direction,
265
+ // dir={direction}
266
+ "data-orientation": orientation,
267
+ ...tabsProps,
268
+ ref: forwardedRef
269
+ })
270
+ });
271
+ }),
272
+ Tabs = withStaticProperties(TabsComponent, {
273
+ List: TabsList,
274
+ /**
275
+ * @deprecated Use Tabs.Tab instead
276
+ */
277
+ Trigger: TabsTrigger,
278
+ Tab: TabsTrigger,
279
+ Content: TabsContent
280
+ });
281
+ Tabs.displayName = TABS_NAME;
282
+ function makeTriggerId(baseId, value) {
283
+ return `${baseId}-trigger-${value}`;
284
+ }
285
+ function makeContentId(baseId, value) {
286
+ return `${baseId}-content-${value}`;
287
+ }
288
+ export { Tabs, useTabsContext };
289
+ //# sourceMappingURL=Tabs.native.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["jsx","_jsx","composeRefs","isWeb","getButtonSized","Group","useGroupItem","composeEventHandlers","withStaticProperties","RovingFocusGroup","SizableStack","ThemeableStack","useControllableState","useDirection","Theme","createStyledContext","styled","useEvent","React","TABS_CONTEXT","TAB_LIST_NAME","TabsList","forwardRef","props","forwardedRef","__scopeTabs","loop","children","listProps","context","useTabsContext","__scopeRovingFocusGroup","orientation","dir","asChild","role","componentName","ref","displayName","TRIGGER_NAME","TabsTriggerFrame","name","tag","justifyContent","alignItems","flexWrap","flexDirection","cursor","userSelect","variants","size","disabled","true","pointerEvents","active","hoverStyle","backgroundColor","focusStyle","unstyled","false","pressStyle","defaultVariants","process","env","TAMAGUI_HEADLESS","TabsTrigger","styleable","value","onInteraction","disableActiveTheme","triggerProps","triggerId","makeTriggerId","baseId","contentId","makeContentId","isSelected","layout","setLayout","useState","triggerRef","useRef","groupItemProps","useEffect","registerTrigger","unregisterTrigger","current","getTriggerSize","width","offsetWidth","height","offsetHeight","x","offsetLeft","y","offsetTop","observer","ResizeObserver","observe","unobserve","triggersCount","_props_onPress","Item","focusable","onLayout","event","nativeEvent","onHoverIn","onHoverOut","id","onPress","webChecks","button","ctrlKey","onChange","preventDefault","type","onKeyDown","includes","key","onFocus","isAutomaticActivation","activationMode","onBlur","CONTENT_NAME","TabsContentFrame","TabsContent","forceMount","contentProps","show","hidden","tabIndex","TABS_NAME","Provider","TabsProvider","useStyledContext","TabsFrame","TabsComponent","valueProp","onValueChange","defaultValue","tabsProps","direction","setValue","prop","defaultProp","setTriggersCount","v","scope","useId","Tabs","List","Trigger","Tab","Content"],"sources":["../../src/Tabs.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAA,IAAAC,IAAA,QAAmB;AAC5B,SAASC,WAAA,QAAa;AACtB,SAASC,KAAA,4BAAsB;AAE/B,SAASC,cAAO,mCAAoB;AACpC,SAASC,KAAA,EAAAC,YAAA,QAAsB;AAC/B,SAASC,oBAAA,EAAAC,oBAAwB;AACjC,SAASC,gBAAc,+BAAsB;AAC7C,SAASC,YAAA,EAAAC,cAA4B;AACrC,SAASC,oBAAoB;AAE7B,SAASC,YAAO,gCAA6B;AAC7C,SAAAC,KAAY,EAAAC,mBAAW,EAAAC,MAAA,EAAAC,QAAA;AAkCf,YAAAC,KAAA;AA/BR,IAAAC,YAAM,gBAAe;EAAAC,aAMf,aAAgB;EAAAC,QAYhB,kBAAiBH,KAAA,CAAAI,UAAA,WAAAC,KAAA,EAAAC,YAAA;IACrB,IAAC;QAAAC,WAAmC;QAAAC,IAAA,GAAiB;QAA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AlBOA,CAAA;QAoBX;MACF,CAMM;MAAA9D,iBAqBA,GAAEpE,QAAA,CAAU;QAIhB,OAAMiI,gBAAA,WAAAC,CAAA;UAiCF,OAAAA,CAAA;QACH;MACC;IAAM,OACJ,eAAAlJ,IAAA,CAAAqI,YAAA;MAAAc,KACA,EAAA3H,WAAO;MAAAgD,MACP,EAAAvD,KAAA,CAAAmI,KAAA;MAAAlF,KACA;MAAA+C,QACA,EAAA6B,QAAc;MAAA/G,WACd;MAAAC,GACA,EAAA6G,SAAA;MAAiBpB,cACV;MAAAxE,IACP;MACFkC,eACM;MACyCgB,aACvC;MAAAf,iBACI;MAAA1D,QACV,iBAAa1B,IAAA,CAAgBuI,SAAA;QAC9BM,SACM;QAIP;QACG,oBAAA9G,WAAA;QAAA,GAAA6G,SAAA;QAAAxG,GACC,EAAAb;MAAO;IACa;EACpB;EAAA8H,IACA,GAAA9I,oBAAU,CAAAiI,aAAA;IAAAc,IAAA,EACVlI,QAAA;IAAA;AACK;AACL;IACAmI,OACA,EAAAvF,WAAA;IAAAwF,GAAA,EAAAxF,WACA;IAAAyF,OACA,EAAA5B;EAAA;AAEAwB,IAAA,CAAAhH,WAAC,GAAA8F,SAAA;AAAA,SAAA5D,cAAAC,MAAA,EAAAN,KAAA;EAAA,UACCM,MAAA,YAAAN,KAAA;AAAA;AAEkB,SAAAQ,aACdA,CAAAF,MAAA,EAAAN,KAAA;EAAA,UACJM,MAAK,YAAAN,KAAA;AAAA;AAAA,SACPmF,IAAA,EAAAxH,cACF","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./Tabs.mjs";
2
+ //# sourceMappingURL=index.native.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
@@ -10,119 +10,23 @@ import { useControllableState } from "@tamagui/use-controllable-state";
10
10
  import { useDirection } from "@tamagui/use-direction";
11
11
  import { Theme, createStyledContext, styled, useEvent } from "@tamagui/web";
12
12
  import * as React from "react";
13
- function _array_like_to_array(arr, len) {
14
- (len == null || len > arr.length) && (len = arr.length);
15
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
16
- return arr2;
17
- }
18
- function _array_with_holes(arr) {
19
- if (Array.isArray(arr)) return arr;
20
- }
21
- function _define_property(obj, key, value) {
22
- return key in obj ? Object.defineProperty(obj, key, {
23
- value,
24
- enumerable: !0,
25
- configurable: !0,
26
- writable: !0
27
- }) : obj[key] = value, obj;
28
- }
29
- function _iterable_to_array_limit(arr, i) {
30
- var _i = arr == null ? null : typeof Symbol < "u" && arr[Symbol.iterator] || arr["@@iterator"];
31
- if (_i != null) {
32
- var _arr = [], _n = !0, _d = !1, _s, _e;
33
- try {
34
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done) && (_arr.push(_s.value), !(i && _arr.length === i)); _n = !0)
35
- ;
36
- } catch (err) {
37
- _d = !0, _e = err;
38
- } finally {
39
- try {
40
- !_n && _i.return != null && _i.return();
41
- } finally {
42
- if (_d) throw _e;
43
- }
44
- }
45
- return _arr;
46
- }
47
- }
48
- function _non_iterable_rest() {
49
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
50
- }
51
- function _object_spread(target) {
52
- for (var i = 1; i < arguments.length; i++) {
53
- var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
54
- typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
55
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
56
- }))), ownKeys2.forEach(function(key) {
57
- _define_property(target, key, source[key]);
58
- });
59
- }
60
- return target;
61
- }
62
- function ownKeys(object, enumerableOnly) {
63
- var keys = Object.keys(object);
64
- if (Object.getOwnPropertySymbols) {
65
- var symbols = Object.getOwnPropertySymbols(object);
66
- enumerableOnly && (symbols = symbols.filter(function(sym) {
67
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
68
- })), keys.push.apply(keys, symbols);
69
- }
70
- return keys;
71
- }
72
- function _object_spread_props(target, source) {
73
- return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
74
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
75
- }), target;
76
- }
77
- function _object_without_properties(source, excluded) {
78
- if (source == null) return {};
79
- var target = _object_without_properties_loose(source, excluded), key, i;
80
- if (Object.getOwnPropertySymbols) {
81
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
82
- for (i = 0; i < sourceSymbolKeys.length; i++)
83
- key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
84
- }
85
- return target;
86
- }
87
- function _object_without_properties_loose(source, excluded) {
88
- if (source == null) return {};
89
- var target = {}, sourceKeys = Object.keys(source), key, i;
90
- for (i = 0; i < sourceKeys.length; i++)
91
- key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
92
- return target;
93
- }
94
- function _sliced_to_array(arr, i) {
95
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
96
- }
97
- function _unsupported_iterable_to_array(o, minLen) {
98
- if (o) {
99
- if (typeof o == "string") return _array_like_to_array(o, minLen);
100
- var n = Object.prototype.toString.call(o).slice(8, -1);
101
- if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set") return Array.from(n);
102
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
103
- }
104
- }
105
13
  var TABS_CONTEXT = "TabsContext", TAB_LIST_NAME = "TabsList", TabsList = /* @__PURE__ */ React.forwardRef(function(props, forwardedRef) {
106
- var __scopeTabs = props.__scopeTabs, _props_loop = props.loop, loop = _props_loop === void 0 ? !0 : _props_loop, children = props.children, listProps = _object_without_properties(props, [
107
- "__scopeTabs",
108
- "loop",
109
- "children"
110
- ]), context = useTabsContext(__scopeTabs);
14
+ var { __scopeTabs, loop = !0, children, ...listProps } = props, context = useTabsContext(__scopeTabs);
111
15
  return /* @__PURE__ */ _jsx(RovingFocusGroup, {
112
16
  __scopeRovingFocusGroup: __scopeTabs || TABS_CONTEXT,
113
17
  orientation: context.orientation,
114
18
  dir: context.dir,
115
19
  loop,
116
20
  asChild: !0,
117
- children: /* @__PURE__ */ _jsx(Group, _object_spread_props(_object_spread({
21
+ children: /* @__PURE__ */ _jsx(Group, {
118
22
  role: "tablist",
119
23
  componentName: TAB_LIST_NAME,
120
24
  "aria-orientation": context.orientation,
121
25
  ref: forwardedRef,
122
- orientation: context.orientation
123
- }, listProps), {
26
+ orientation: context.orientation,
27
+ ...listProps,
124
28
  children
125
- }))
29
+ })
126
30
  });
127
31
  });
128
32
  TabsList.displayName = TAB_LIST_NAME;
@@ -173,13 +77,7 @@ var TRIGGER_NAME = "TabsTrigger", TabsTriggerFrame = styled(ThemeableStack, {
173
77
  unstyled: process.env.TAMAGUI_HEADLESS === "1"
174
78
  }
175
79
  }), TabsTrigger = TabsTriggerFrame.styleable(function(props, forwardedRef) {
176
- var __scopeTabs = props.__scopeTabs, value = props.value, _props_disabled = props.disabled, disabled = _props_disabled === void 0 ? !1 : _props_disabled, onInteraction = props.onInteraction, disableActiveTheme = props.disableActiveTheme, triggerProps = _object_without_properties(props, [
177
- "__scopeTabs",
178
- "value",
179
- "disabled",
180
- "onInteraction",
181
- "disableActiveTheme"
182
- ]), context = useTabsContext(__scopeTabs), triggerId = makeTriggerId(context.baseId, value), contentId = makeContentId(context.baseId, value), isSelected = value === context.value, _React_useState = _sliced_to_array(React.useState(null), 2), layout = _React_useState[0], setLayout = _React_useState[1], triggerRef = React.useRef(null), groupItemProps = useGroupItem({
80
+ var { __scopeTabs, value, disabled = !1, onInteraction, disableActiveTheme, ...triggerProps } = props, context = useTabsContext(__scopeTabs), triggerId = makeTriggerId(context.baseId, value), contentId = makeContentId(context.baseId, value), isSelected = value === context.value, [layout, setLayout] = React.useState(null), triggerRef = React.useRef(null), groupItemProps = useGroupItem({
183
81
  disabled: !!disabled
184
82
  });
185
83
  React.useEffect(function() {
@@ -187,21 +85,20 @@ var TRIGGER_NAME = "TabsTrigger", TabsTriggerFrame = styled(ThemeableStack, {
187
85
  return context.unregisterTrigger();
188
86
  };
189
87
  }, []), React.useEffect(function() {
190
- var getTriggerSize = function() {
88
+ if (!triggerRef.current || !isWeb) return;
89
+ function getTriggerSize() {
191
90
  triggerRef.current && setLayout({
192
91
  width: triggerRef.current.offsetWidth,
193
92
  height: triggerRef.current.offsetHeight,
194
93
  x: triggerRef.current.offsetLeft,
195
94
  y: triggerRef.current.offsetTop
196
95
  });
197
- };
198
- if (!(!triggerRef.current || !isWeb)) {
199
- getTriggerSize();
200
- var observer = new ResizeObserver(getTriggerSize);
201
- return observer.observe(triggerRef.current), function() {
202
- triggerRef.current && observer.unobserve(triggerRef.current);
203
- };
204
96
  }
97
+ getTriggerSize();
98
+ var observer = new ResizeObserver(getTriggerSize);
99
+ return observer.observe(triggerRef.current), function() {
100
+ triggerRef.current && observer.unobserve(triggerRef.current);
101
+ };
205
102
  }, [
206
103
  context.triggersCount
207
104
  ]), React.useEffect(function() {
@@ -219,7 +116,7 @@ var TRIGGER_NAME = "TabsTrigger", TabsTriggerFrame = styled(ThemeableStack, {
219
116
  asChild: !0,
220
117
  focusable: !disabled,
221
118
  active: isSelected,
222
- children: /* @__PURE__ */ _jsx(TabsTriggerFrame, _object_spread(_object_spread_props(_object_spread({
119
+ children: /* @__PURE__ */ _jsx(TabsTriggerFrame, {
223
120
  onLayout: function(event) {
224
121
  isWeb || setLayout(event.nativeEvent.layout);
225
122
  },
@@ -235,32 +132,35 @@ var TRIGGER_NAME = "TabsTrigger", TabsTriggerFrame = styled(ThemeableStack, {
235
132
  "data-state": isSelected ? "active" : "inactive",
236
133
  "data-disabled": disabled ? "" : void 0,
237
134
  disabled,
238
- id: triggerId
239
- }, !props.unstyled && {
240
- size: context.size
241
- }, groupItemProps, triggerProps), {
135
+ id: triggerId,
136
+ ...!props.unstyled && {
137
+ size: context.size
138
+ },
139
+ ...groupItemProps,
140
+ ...triggerProps,
242
141
  ref: composeRefs(forwardedRef, triggerRef),
243
142
  onPress: composeEventHandlers((_props_onPress = props.onPress) !== null && _props_onPress !== void 0 ? _props_onPress : void 0, function(event) {
244
143
  var webChecks = !isWeb || event.button === 0 && event.ctrlKey === !1;
245
144
  !disabled && !isSelected && webChecks ? context.onChange(value) : event.preventDefault();
246
- })
247
- }), isWeb && {
248
- type: "button",
249
- onKeyDown: composeEventHandlers(props.onKeyDown, function(event) {
250
- [
251
- " ",
252
- "Enter"
253
- ].includes(event.key) && (context.onChange(value), event.preventDefault());
254
145
  }),
255
- onFocus: composeEventHandlers(props.onFocus, function(event) {
256
- layout && (onInteraction == null || onInteraction("focus", layout));
257
- var isAutomaticActivation = context.activationMode !== "manual";
258
- !isSelected && !disabled && isAutomaticActivation && context.onChange(value);
259
- }),
260
- onBlur: composeEventHandlers(props.onFocus, function() {
261
- onInteraction == null || onInteraction("focus", null);
262
- })
263
- }))
146
+ ...isWeb && {
147
+ type: "button",
148
+ onKeyDown: composeEventHandlers(props.onKeyDown, function(event) {
149
+ [
150
+ " ",
151
+ "Enter"
152
+ ].includes(event.key) && (context.onChange(value), event.preventDefault());
153
+ }),
154
+ onFocus: composeEventHandlers(props.onFocus, function(event) {
155
+ layout && (onInteraction == null || onInteraction("focus", layout));
156
+ var isAutomaticActivation = context.activationMode !== "manual";
157
+ !isSelected && !disabled && isAutomaticActivation && context.onChange(value);
158
+ }),
159
+ onBlur: composeEventHandlers(props.onFocus, function() {
160
+ onInteraction == null || onInteraction("focus", null);
161
+ })
162
+ }
163
+ })
264
164
  })
265
165
  });
266
166
  });
@@ -268,13 +168,8 @@ TabsTrigger.displayName = TRIGGER_NAME;
268
168
  var CONTENT_NAME = "TabsContent", TabsContentFrame = styled(ThemeableStack, {
269
169
  name: CONTENT_NAME
270
170
  }), TabsContent = TabsContentFrame.styleable(function(props, forwardedRef) {
271
- var __scopeTabs = props.__scopeTabs, value = props.value, forceMount = props.forceMount, children = props.children, contentProps = _object_without_properties(props, [
272
- "__scopeTabs",
273
- "value",
274
- "forceMount",
275
- "children"
276
- ]), context = useTabsContext(__scopeTabs), isSelected = value === context.value, show = forceMount || isSelected, triggerId = makeTriggerId(context.baseId, value), contentId = makeContentId(context.baseId, value);
277
- return show ? /* @__PURE__ */ _jsx(TabsContentFrame, _object_spread_props(_object_spread({
171
+ var { __scopeTabs, value, forceMount, children, ...contentProps } = props, context = useTabsContext(__scopeTabs), isSelected = value === context.value, show = forceMount || isSelected, triggerId = makeTriggerId(context.baseId, value), contentId = makeContentId(context.baseId, value);
172
+ return show ? /* @__PURE__ */ _jsx(TabsContentFrame, {
278
173
  "data-state": isSelected ? "active" : "inactive",
279
174
  "data-orientation": context.orientation,
280
175
  role: "tabpanel",
@@ -282,28 +177,19 @@ var CONTENT_NAME = "TabsContent", TabsContentFrame = styled(ThemeableStack, {
282
177
  // @ts-ignore
283
178
  hidden: !show,
284
179
  id: contentId,
285
- tabIndex: 0
286
- }, contentProps), {
180
+ tabIndex: 0,
181
+ ...contentProps,
287
182
  ref: forwardedRef,
288
183
  children
289
- }), value) : null;
290
- }), TABS_NAME = "Tabs", _createStyledContext = createStyledContext(), TabsProvider = _createStyledContext.Provider, useTabsContext = _createStyledContext.useStyledContext, TabsFrame = styled(SizableStack, {
184
+ }, value) : null;
185
+ }), TABS_NAME = "Tabs", { Provider: TabsProvider, useStyledContext: useTabsContext } = createStyledContext(), TabsFrame = styled(SizableStack, {
291
186
  name: TABS_NAME
292
187
  }), TabsComponent = TabsFrame.styleable(function(props, forwardedRef) {
293
- var __scopeTabs = props.__scopeTabs, valueProp = props.value, onValueChange = props.onValueChange, defaultValue = props.defaultValue, _props_orientation = props.orientation, orientation = _props_orientation === void 0 ? "horizontal" : _props_orientation, dir = props.dir, _props_activationMode = props.activationMode, activationMode = _props_activationMode === void 0 ? "automatic" : _props_activationMode, _props_size = props.size, size = _props_size === void 0 ? "$true" : _props_size, tabsProps = _object_without_properties(props, [
294
- "__scopeTabs",
295
- "value",
296
- "onValueChange",
297
- "defaultValue",
298
- "orientation",
299
- "dir",
300
- "activationMode",
301
- "size"
302
- ]), direction = useDirection(dir), _useControllableState = _sliced_to_array(useControllableState({
188
+ var { __scopeTabs, value: valueProp, onValueChange, defaultValue, orientation = "horizontal", dir, activationMode = "automatic", size = "$true", ...tabsProps } = props, direction = useDirection(dir), [value, setValue] = useControllableState({
303
189
  prop: valueProp,
304
190
  onChange: onValueChange,
305
191
  defaultProp: defaultValue ?? ""
306
- }), 2), value = _useControllableState[0], setValue = _useControllableState[1], _React_useState = _sliced_to_array(React.useState(0), 2), triggersCount = _React_useState[0], setTriggersCount = _React_useState[1], registerTrigger = useEvent(function() {
192
+ }), [triggersCount, setTriggersCount] = React.useState(0), registerTrigger = useEvent(function() {
307
193
  return setTriggersCount(function(v) {
308
194
  return v + 1;
309
195
  });
@@ -324,13 +210,13 @@ var CONTENT_NAME = "TabsContent", TabsContentFrame = styled(ThemeableStack, {
324
210
  registerTrigger,
325
211
  triggersCount,
326
212
  unregisterTrigger,
327
- children: /* @__PURE__ */ _jsx(TabsFrame, _object_spread_props(_object_spread({
213
+ children: /* @__PURE__ */ _jsx(TabsFrame, {
328
214
  direction,
329
215
  // dir={direction}
330
- "data-orientation": orientation
331
- }, tabsProps), {
216
+ "data-orientation": orientation,
217
+ ...tabsProps,
332
218
  ref: forwardedRef
333
- }))
219
+ })
334
220
  });
335
221
  }), Tabs = withStaticProperties(TabsComponent, {
336
222
  List: TabsList,
@@ -343,10 +229,10 @@ var CONTENT_NAME = "TabsContent", TabsContentFrame = styled(ThemeableStack, {
343
229
  });
344
230
  Tabs.displayName = TABS_NAME;
345
231
  function makeTriggerId(baseId, value) {
346
- return "".concat(baseId, "-trigger-").concat(value);
232
+ return `${baseId}-trigger-${value}`;
347
233
  }
348
234
  function makeContentId(baseId, value) {
349
- return "".concat(baseId, "-content-").concat(value);
235
+ return `${baseId}-content-${value}`;
350
236
  }
351
237
  export {
352
238
  Tabs,