@tamagui/accordion 2.7.7 → 3.0.0-beta.643.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,497 +1,411 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { View, createRefComponent, createStyledContext, createStyledHOC, styled } from "@tamagui/core";
2
3
  import { Collapsible } from "@tamagui/collapsible";
3
4
  import { createCollection } from "@tamagui/collection";
4
5
  import { useComposedRefs } from "@tamagui/compose-refs";
5
6
  import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
6
- import { View, createStyledContext, styled } from "@tamagui/core";
7
7
  import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
8
8
  import { YStack } from "@tamagui/stacks";
9
9
  import { H1 } from "@tamagui/text";
10
10
  import { useControllableState } from "@tamagui/use-controllable-state";
11
11
  import { useDirection } from "@tamagui/use-direction";
12
12
  import * as React from "react";
13
+
13
14
  var ACCORDION_NAME = "Accordion";
14
- var ACCORDION_KEYS = ["Home", "End", "ArrowDown", "ArrowUp", "ArrowLeft", "ArrowRight"];
15
+ var ACCORDION_KEYS = [
16
+ "Home",
17
+ "End",
18
+ "ArrowDown",
19
+ "ArrowUp",
20
+ "ArrowLeft",
21
+ "ArrowRight"
22
+ ];
15
23
  var [Collection, useCollection] = createCollection(ACCORDION_NAME);
16
24
  var ACCORDION_CONTEXT = "Accordion";
17
- var AccordionComponent = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
18
- var {
19
- type,
20
- ...accordionProps
21
- } = props;
22
- var singleProps = accordionProps;
23
- var multipleProps = accordionProps;
24
- return /* @__PURE__ */_jsx(Collection.Provider, {
25
- scope: props.__scopeAccordion || ACCORDION_CONTEXT,
26
- children: type === "multiple" ? /* @__PURE__ */_jsx(AccordionImplMultiple, {
27
- ...multipleProps,
28
- ref: forwardedRef
29
- }) : /* @__PURE__ */_jsx(AccordionImplSingle, {
30
- ...singleProps,
31
- ref: forwardedRef
32
- })
33
- });
25
+ var AccordionComponent = createRefComponent(function(props, forwardedRef) {
26
+ var { type, ...accordionProps } = props;
27
+ var singleProps = accordionProps;
28
+ var multipleProps = accordionProps;
29
+ return /* @__PURE__ */ jsx(Collection.Provider, {
30
+ scope: props.__scopeAccordion || ACCORDION_CONTEXT,
31
+ children: type === "multiple" ? /* @__PURE__ */ jsx(AccordionImplMultiple, {
32
+ ...multipleProps,
33
+ ref: forwardedRef
34
+ }) : /* @__PURE__ */ jsx(AccordionImplSingle, {
35
+ ...singleProps,
36
+ ref: forwardedRef
37
+ })
38
+ });
34
39
  });
35
40
  AccordionComponent.displayName = ACCORDION_NAME;
36
- AccordionComponent.propTypes = {
37
- type(props) {
38
- var value = props.value || props.defaultValue;
39
- if (props.type && !["single", "multiple"].includes(props.type)) {
40
- return new Error("Invalid prop `type` supplied to `Accordion`. Expected one of `single | multiple`.");
41
- }
42
- if (props.type === "multiple" && typeof value === "string") {
43
- return new Error("Invalid prop `type` supplied to `Accordion`. Expected `single` when `defaultValue` or `value` is type `string`.");
44
- }
45
- if (props.type === "single" && Array.isArray(value)) {
46
- return new Error("Invalid prop `type` supplied to `Accordion`. Expected `multiple` when `defaultValue` or `value` is type `string[]`.");
47
- }
48
- return null;
49
- }
50
- };
51
- var {
52
- Provider: AccordionValueProvider,
53
- useStyledContext: useAccordionValueContext
54
- } = createStyledContext();
55
- var {
56
- Provider: AccordionCollapsibleProvider,
57
- useStyledContext: useAccordionCollapsibleContext
58
- } = createStyledContext();
59
- var AccordionImplSingle = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
60
- var {
61
- value: valueProp,
62
- defaultValue,
63
- control,
64
- onValueChange = function () {},
65
- collapsible = false,
66
- ...accordionSingleProps
67
- } = props;
68
- var [value, setValue] = useControllableState({
69
- prop: valueProp,
70
- defaultProp: defaultValue || "",
71
- onChange: onValueChange
72
- });
73
- return /* @__PURE__ */_jsx(AccordionValueProvider, {
74
- scope: props.__scopeAccordion,
75
- value: value ? [value] : [],
76
- onItemOpen: setValue,
77
- onItemClose: React.useCallback(function () {
78
- return collapsible && setValue("");
79
- }, [setValue, collapsible]),
80
- children: /* @__PURE__ */_jsx(AccordionCollapsibleProvider, {
81
- scope: props.__scopeAccordion,
82
- collapsible,
83
- children: /* @__PURE__ */_jsx(AccordionImpl, {
84
- ...accordionSingleProps,
85
- ref: forwardedRef
86
- })
87
- })
88
- });
41
+ AccordionComponent.propTypes = { type(props) {
42
+ var value = props.value || props.defaultValue;
43
+ if (props.type && !["single", "multiple"].includes(props.type)) {
44
+ return new Error("Invalid prop `type` supplied to `Accordion`. Expected one of `single | multiple`.");
45
+ }
46
+ if (props.type === "multiple" && typeof value === "string") {
47
+ return new Error("Invalid prop `type` supplied to `Accordion`. Expected `single` when `defaultValue` or `value` is type `string`.");
48
+ }
49
+ if (props.type === "single" && Array.isArray(value)) {
50
+ return new Error("Invalid prop `type` supplied to `Accordion`. Expected `multiple` when `defaultValue` or `value` is type `string[]`.");
51
+ }
52
+ return null;
53
+ } };
54
+ var { Provider: AccordionValueProvider, useStyledContext: useAccordionValueContext } = createStyledContext();
55
+ var { Provider: AccordionCollapsibleProvider, useStyledContext: useAccordionCollapsibleContext } = createStyledContext();
56
+ var AccordionImplSingle = createRefComponent(function(props, forwardedRef) {
57
+ var { value: valueProp, defaultValue, control, onValueChange = function() {}, collapsible = false, ...accordionSingleProps } = props;
58
+ var [value, setValue] = useControllableState({
59
+ prop: valueProp,
60
+ defaultProp: defaultValue || "",
61
+ onChange: onValueChange
62
+ });
63
+ return /* @__PURE__ */ jsx(AccordionValueProvider, {
64
+ scope: props.__scopeAccordion,
65
+ value: value ? [value] : [],
66
+ onItemOpen: setValue,
67
+ onItemClose: React.useCallback(function() {
68
+ return collapsible && setValue("");
69
+ }, [setValue, collapsible]),
70
+ children: /* @__PURE__ */ jsx(AccordionCollapsibleProvider, {
71
+ scope: props.__scopeAccordion,
72
+ collapsible,
73
+ children: /* @__PURE__ */ jsx(AccordionImpl, {
74
+ ...accordionSingleProps,
75
+ ref: forwardedRef
76
+ })
77
+ })
78
+ });
89
79
  });
90
- var AccordionImplMultiple = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
91
- var {
92
- value: valueProp,
93
- defaultValue,
94
- onValueChange = function () {},
95
- ...accordionMultipleProps
96
- } = props;
97
- var [value, setValue] = useControllableState({
98
- prop: valueProp,
99
- defaultProp: defaultValue || [],
100
- onChange: onValueChange
101
- });
102
- var handleItemOpen = React.useCallback(function (itemValue) {
103
- return setValue(function () {
104
- var prevValue = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
105
- return [...prevValue, itemValue];
106
- });
107
- }, [setValue]);
108
- var handleItemClose = React.useCallback(function (itemValue) {
109
- return setValue(function () {
110
- var prevValue = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
111
- return prevValue.filter(function (value2) {
112
- return value2 !== itemValue;
113
- });
114
- });
115
- }, [setValue]);
116
- return /* @__PURE__ */_jsx(AccordionValueProvider, {
117
- scope: props.__scopeAccordion,
118
- value: value || [],
119
- onItemOpen: handleItemOpen,
120
- onItemClose: handleItemClose,
121
- children: /* @__PURE__ */_jsx(AccordionCollapsibleProvider, {
122
- scope: props.__scopeAccordion,
123
- collapsible: true,
124
- children: /* @__PURE__ */_jsx(AccordionImpl, {
125
- ...accordionMultipleProps,
126
- ref: forwardedRef
127
- })
128
- })
129
- });
80
+ var AccordionImplMultiple = createRefComponent(function(props, forwardedRef) {
81
+ var { value: valueProp, defaultValue, onValueChange = function() {}, ...accordionMultipleProps } = props;
82
+ var [value, setValue] = useControllableState({
83
+ prop: valueProp,
84
+ defaultProp: defaultValue || [],
85
+ onChange: onValueChange
86
+ });
87
+ var handleItemOpen = React.useCallback(function(itemValue) {
88
+ return setValue(function() {
89
+ var prevValue = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
90
+ return [...prevValue, itemValue];
91
+ });
92
+ }, [setValue]);
93
+ var handleItemClose = React.useCallback(function(itemValue) {
94
+ return setValue(function() {
95
+ var prevValue = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
96
+ return prevValue.filter(function(value2) {
97
+ return value2 !== itemValue;
98
+ });
99
+ });
100
+ }, [setValue]);
101
+ return /* @__PURE__ */ jsx(AccordionValueProvider, {
102
+ scope: props.__scopeAccordion,
103
+ value: value || [],
104
+ onItemOpen: handleItemOpen,
105
+ onItemClose: handleItemClose,
106
+ children: /* @__PURE__ */ jsx(AccordionCollapsibleProvider, {
107
+ scope: props.__scopeAccordion,
108
+ collapsible: true,
109
+ children: /* @__PURE__ */ jsx(AccordionImpl, {
110
+ ...accordionMultipleProps,
111
+ ref: forwardedRef
112
+ })
113
+ })
114
+ });
130
115
  });
131
- var {
132
- Provider: AccordionImplProvider,
133
- useStyledContext: useAccordionContext
134
- } = createStyledContext();
135
- var AccordionImpl = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
136
- var {
137
- __scopeAccordion,
138
- disabled,
139
- dir,
140
- orientation = "vertical",
141
- ...accordionProps
142
- } = props;
143
- var accordionRef = React.useRef(null);
144
- var composedRef = useComposedRefs(accordionRef, forwardedRef);
145
- var getItems = useCollection(__scopeAccordion || ACCORDION_CONTEXT);
146
- var direction = useDirection(dir);
147
- var isDirectionLTR = direction === "ltr";
148
- var handleKeyDown = composeEventHandlers(props.onKeyDown, function (event) {
149
- var _triggerCollection_clampedIndex_ref_current;
150
- if (!ACCORDION_KEYS.includes(event.key)) return;
151
- var target = event.target;
152
- var triggerCollection = getItems().filter(function (item) {
153
- var el = item.ref.current;
154
- return !(el === null || el === void 0 ? void 0 : el.disabled);
155
- });
156
- var triggerIndex = triggerCollection.findIndex(function (item) {
157
- return item.ref.current === target;
158
- });
159
- var triggerCount = triggerCollection.length;
160
- if (triggerIndex === -1) return;
161
- event.preventDefault();
162
- var nextIndex = triggerIndex;
163
- var homeIndex = 0;
164
- var endIndex = triggerCount - 1;
165
- var moveNext = function () {
166
- nextIndex = triggerIndex + 1;
167
- if (nextIndex > endIndex) {
168
- nextIndex = homeIndex;
169
- }
170
- };
171
- var movePrev = function () {
172
- nextIndex = triggerIndex - 1;
173
- if (nextIndex < homeIndex) {
174
- nextIndex = endIndex;
175
- }
176
- };
177
- switch (event.key) {
178
- case "Home":
179
- nextIndex = homeIndex;
180
- break;
181
- case "End":
182
- nextIndex = endIndex;
183
- break;
184
- case "ArrowRight":
185
- if (orientation === "horizontal") {
186
- if (isDirectionLTR) {
187
- moveNext();
188
- } else {
189
- movePrev();
190
- }
191
- }
192
- break;
193
- case "ArrowDown":
194
- if (orientation === "vertical") {
195
- moveNext();
196
- }
197
- break;
198
- case "ArrowLeft":
199
- if (orientation === "horizontal") {
200
- if (isDirectionLTR) {
201
- movePrev();
202
- } else {
203
- moveNext();
204
- }
205
- }
206
- break;
207
- case "ArrowUp":
208
- if (orientation === "vertical") {
209
- movePrev();
210
- }
211
- break;
212
- }
213
- var clampedIndex = nextIndex % triggerCount;
214
- (_triggerCollection_clampedIndex_ref_current = triggerCollection[clampedIndex].ref.current) === null || _triggerCollection_clampedIndex_ref_current === void 0 ? void 0 : _triggerCollection_clampedIndex_ref_current.focus();
215
- });
216
- return /* @__PURE__ */_jsx(AccordionImplProvider, {
217
- scope: __scopeAccordion,
218
- disabled,
219
- direction: dir,
220
- orientation,
221
- children: /* @__PURE__ */_jsx(Collection.Slot, {
222
- scope: __scopeAccordion || ACCORDION_CONTEXT,
223
- children: /* @__PURE__ */_jsx(YStack, {
224
- "data-orientation": orientation,
225
- ref: composedRef,
226
- ...accordionProps,
227
- ...(isWeb && {
228
- onKeyDown: handleKeyDown
229
- })
230
- })
231
- })
232
- });
116
+ var { Provider: AccordionImplProvider, useStyledContext: useAccordionContext } = createStyledContext();
117
+ var AccordionImpl = createRefComponent(function(props, forwardedRef) {
118
+ var { __scopeAccordion, disabled, dir, orientation = "vertical", ...accordionProps } = props;
119
+ var accordionRef = React.useRef(null);
120
+ var composedRef = useComposedRefs(accordionRef, forwardedRef);
121
+ var getItems = useCollection(__scopeAccordion || ACCORDION_CONTEXT);
122
+ var direction = useDirection(dir);
123
+ var isDirectionLTR = direction === "ltr";
124
+ var handleKeyDown = composeEventHandlers(props.onKeyDown, function(event) {
125
+ var _triggerCollection_clampedIndex_ref_current;
126
+ if (!ACCORDION_KEYS.includes(event.key)) return;
127
+ var target = event.target;
128
+ var triggerCollection = getItems().filter(function(item) {
129
+ var el = item.ref.current;
130
+ return !(el === null || el === void 0 ? void 0 : el.disabled);
131
+ });
132
+ var triggerIndex = triggerCollection.findIndex(function(item) {
133
+ return item.ref.current === target;
134
+ });
135
+ var triggerCount = triggerCollection.length;
136
+ if (triggerIndex === -1) return;
137
+ event.preventDefault();
138
+ var nextIndex = triggerIndex;
139
+ var homeIndex = 0;
140
+ var endIndex = triggerCount - 1;
141
+ var moveNext = function() {
142
+ nextIndex = triggerIndex + 1;
143
+ if (nextIndex > endIndex) {
144
+ nextIndex = homeIndex;
145
+ }
146
+ };
147
+ var movePrev = function() {
148
+ nextIndex = triggerIndex - 1;
149
+ if (nextIndex < homeIndex) {
150
+ nextIndex = endIndex;
151
+ }
152
+ };
153
+ switch (event.key) {
154
+ case "Home":
155
+ nextIndex = homeIndex;
156
+ break;
157
+ case "End":
158
+ nextIndex = endIndex;
159
+ break;
160
+ case "ArrowRight":
161
+ if (orientation === "horizontal") {
162
+ if (isDirectionLTR) {
163
+ moveNext();
164
+ } else {
165
+ movePrev();
166
+ }
167
+ }
168
+ break;
169
+ case "ArrowDown":
170
+ if (orientation === "vertical") {
171
+ moveNext();
172
+ }
173
+ break;
174
+ case "ArrowLeft":
175
+ if (orientation === "horizontal") {
176
+ if (isDirectionLTR) {
177
+ movePrev();
178
+ } else {
179
+ moveNext();
180
+ }
181
+ }
182
+ break;
183
+ case "ArrowUp":
184
+ if (orientation === "vertical") {
185
+ movePrev();
186
+ }
187
+ break;
188
+ }
189
+ var clampedIndex = nextIndex % triggerCount;
190
+ (_triggerCollection_clampedIndex_ref_current = triggerCollection[clampedIndex].ref.current) === null || _triggerCollection_clampedIndex_ref_current === void 0 ? void 0 : _triggerCollection_clampedIndex_ref_current.focus();
191
+ });
192
+ return /* @__PURE__ */ jsx(AccordionImplProvider, {
193
+ scope: __scopeAccordion,
194
+ disabled,
195
+ direction: dir,
196
+ orientation,
197
+ children: /* @__PURE__ */ jsx(Collection.Slot, {
198
+ scope: __scopeAccordion || ACCORDION_CONTEXT,
199
+ children: /* @__PURE__ */ jsx(YStack, {
200
+ "data-orientation": orientation,
201
+ ref: composedRef,
202
+ ...accordionProps,
203
+ ...isWeb && { onKeyDown: handleKeyDown }
204
+ })
205
+ })
206
+ });
233
207
  });
234
208
  var ITEM_NAME = "AccordionItem";
235
- var {
236
- Provider: AccordionItemProvider,
237
- useStyledContext: useAccordionItemContext
238
- } = createStyledContext();
239
- var AccordionItem = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
240
- var {
241
- __scopeAccordion,
242
- value,
243
- ...accordionItemProps
244
- } = props;
245
- var accordionContext = useAccordionContext(__scopeAccordion);
246
- var valueContext = useAccordionValueContext(__scopeAccordion);
247
- var triggerId = React.useId();
248
- var open = value && valueContext.value.includes(value) || false;
249
- var disabled = accordionContext.disabled || props.disabled;
250
- return /* @__PURE__ */_jsx(AccordionItemProvider, {
251
- scope: __scopeAccordion,
252
- open,
253
- disabled,
254
- triggerId,
255
- children: /* @__PURE__ */_jsx(Collapsible, {
256
- "data-orientation": accordionContext.orientation,
257
- "data-state": open ? "open" : "closed",
258
- __scopeCollapsible: __scopeAccordion || ACCORDION_CONTEXT,
259
- ...accordionItemProps,
260
- ref: forwardedRef,
261
- disabled,
262
- open,
263
- onOpenChange: function (open2) {
264
- if (open2) {
265
- valueContext.onItemOpen(value);
266
- } else {
267
- valueContext.onItemClose(value);
268
- }
269
- }
270
- })
271
- });
209
+ var { Provider: AccordionItemProvider, useStyledContext: useAccordionItemContext } = createStyledContext();
210
+ var AccordionItem = createRefComponent(function(props, forwardedRef) {
211
+ var { __scopeAccordion, value, ...accordionItemProps } = props;
212
+ var accordionContext = useAccordionContext(__scopeAccordion);
213
+ var valueContext = useAccordionValueContext(__scopeAccordion);
214
+ var triggerId = React.useId();
215
+ var open = value && valueContext.value.includes(value) || false;
216
+ var disabled = accordionContext.disabled || props.disabled;
217
+ return /* @__PURE__ */ jsx(AccordionItemProvider, {
218
+ scope: __scopeAccordion,
219
+ open,
220
+ disabled,
221
+ triggerId,
222
+ children: /* @__PURE__ */ jsx(Collapsible, {
223
+ "data-orientation": accordionContext.orientation,
224
+ "data-state": open ? "open" : "closed",
225
+ __scopeCollapsible: __scopeAccordion || ACCORDION_CONTEXT,
226
+ ...accordionItemProps,
227
+ ref: forwardedRef,
228
+ disabled,
229
+ open,
230
+ onOpenChange: function(open2) {
231
+ if (open2) {
232
+ valueContext.onItemOpen(value);
233
+ } else {
234
+ valueContext.onItemClose(value);
235
+ }
236
+ }
237
+ })
238
+ });
272
239
  });
273
240
  AccordionItem.displayName = ITEM_NAME;
274
241
  var HEADER_NAME = "AccordionHeader";
275
- var AccordionHeader = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
276
- var {
277
- __scopeAccordion,
278
- ...headerProps
279
- } = props;
280
- var accordionContext = useAccordionContext(__scopeAccordion);
281
- var itemContext = useAccordionItemContext(__scopeAccordion);
282
- return /* @__PURE__ */_jsx(H1, {
283
- "data-orientation": accordionContext.orientation,
284
- "data-state": getState(itemContext.open),
285
- "data-disabled": itemContext.disabled ? "" : void 0,
286
- ...headerProps,
287
- ref: forwardedRef
288
- });
242
+ var AccordionHeader = createRefComponent(function(props, forwardedRef) {
243
+ var { __scopeAccordion, ...headerProps } = props;
244
+ var accordionContext = useAccordionContext(__scopeAccordion);
245
+ var itemContext = useAccordionItemContext(__scopeAccordion);
246
+ return /* @__PURE__ */ jsx(H1, {
247
+ "data-orientation": accordionContext.orientation,
248
+ "data-state": getState(itemContext.open),
249
+ "data-disabled": itemContext.disabled ? "" : void 0,
250
+ ...headerProps,
251
+ ref: forwardedRef
252
+ });
289
253
  });
290
254
  AccordionHeader.displayName = HEADER_NAME;
291
- var AccordionTriggerFrame = styled(Collapsible.Trigger, {
292
- variants: {
293
- unstyled: {
294
- false: {
295
- cursor: "pointer",
296
- backgroundColor: "$background",
297
- padding: "$true",
298
- hoverStyle: {
299
- backgroundColor: "$backgroundHover"
300
- },
301
- focusStyle: {
302
- backgroundColor: "$backgroundFocus"
303
- },
304
- pressStyle: {
305
- backgroundColor: "$backgroundPress"
306
- }
307
- }
308
- }
309
- },
310
- defaultVariants: {
311
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
312
- }
255
+ var AccordionTriggerFrame = styled(Collapsible.Trigger, { displayName: "AccordionTrigger" });
256
+ var AccordionTrigger = createStyledHOC(AccordionTriggerFrame, function AccordionTrigger2(props, forwardedRef) {
257
+ var { __scopeAccordion, ...triggerProps } = props;
258
+ var accordionContext = useAccordionContext(__scopeAccordion);
259
+ var itemContext = useAccordionItemContext(__scopeAccordion);
260
+ var collapsibleContext = useAccordionCollapsibleContext(__scopeAccordion);
261
+ return /* @__PURE__ */ jsx(Collection.ItemSlot, {
262
+ scope: __scopeAccordion || ACCORDION_CONTEXT,
263
+ children: /* @__PURE__ */ jsx(AccordionTriggerFrame, {
264
+ __scopeCollapsible: __scopeAccordion || ACCORDION_CONTEXT,
265
+ "aria-disabled": itemContext.open && !collapsibleContext.collapsible || void 0,
266
+ "data-orientation": accordionContext.orientation,
267
+ id: itemContext.triggerId,
268
+ ...triggerProps,
269
+ ref: forwardedRef
270
+ })
271
+ });
313
272
  });
314
- var AccordionTrigger = AccordionTriggerFrame.styleable(function AccordionTrigger2(props, forwardedRef) {
315
- var {
316
- __scopeAccordion,
317
- ...triggerProps
318
- } = props;
319
- var accordionContext = useAccordionContext(__scopeAccordion);
320
- var itemContext = useAccordionItemContext(__scopeAccordion);
321
- var collapsibleContext = useAccordionCollapsibleContext(__scopeAccordion);
322
- return /* @__PURE__ */_jsx(Collection.ItemSlot, {
323
- scope: __scopeAccordion || ACCORDION_CONTEXT,
324
- children: /* @__PURE__ */_jsx(AccordionTriggerFrame, {
325
- // @ts-ignore
326
- __scopeCollapsible: __scopeAccordion || ACCORDION_CONTEXT,
327
- "aria-disabled": itemContext.open && !collapsibleContext.collapsible || void 0,
328
- "data-orientation": accordionContext.orientation,
329
- id: itemContext.triggerId,
330
- ...triggerProps,
331
- ref: forwardedRef
332
- })
333
- });
273
+ var AccordionContentFrame = styled(Collapsible.Content, { displayName: "AccordionContent" });
274
+ var AccordionHeightAnimatorContext = /* @__PURE__ */ React.createContext(false);
275
+ var AccordionContent = createStyledHOC(AccordionContentFrame, function AccordionContent2(props, forwardedRef) {
276
+ var { __scopeAccordion, forceMount, ...contentProps } = props;
277
+ var accordionContext = useAccordionContext(__scopeAccordion);
278
+ var itemContext = useAccordionItemContext(__scopeAccordion);
279
+ var heightAnimatorPresent = React.useContext(AccordionHeightAnimatorContext);
280
+ return /* @__PURE__ */ jsx(AccordionContentFrame, {
281
+ role: "region",
282
+ "aria-labelledby": itemContext.triggerId,
283
+ "data-orientation": accordionContext.orientation,
284
+ __scopeCollapsible: __scopeAccordion || ACCORDION_CONTEXT,
285
+ ...contentProps,
286
+ forceMount: forceMount || heightAnimatorPresent,
287
+ ref: forwardedRef
288
+ });
334
289
  });
335
- var AccordionContentFrame = styled(Collapsible.Content, {
336
- variants: {
337
- unstyled: {
338
- false: {
339
- padding: "$true",
340
- backgroundColor: "$background"
341
- }
342
- }
343
- },
344
- defaultVariants: {
345
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
346
- }
347
- });
348
- var AccordionHeightAnimatorContext = /* @__PURE__ */React.createContext(false);
349
- var AccordionContent = AccordionContentFrame.styleable(function AccordionContent2(props, forwardedRef) {
350
- var {
351
- __scopeAccordion,
352
- forceMount,
353
- ...contentProps
354
- } = props;
355
- var accordionContext = useAccordionContext(__scopeAccordion);
356
- var itemContext = useAccordionItemContext(__scopeAccordion);
357
- var heightAnimatorPresent = React.useContext(AccordionHeightAnimatorContext);
358
- return /* @__PURE__ */_jsx(AccordionContentFrame, {
359
- role: "region",
360
- "aria-labelledby": itemContext.triggerId,
361
- "data-orientation": accordionContext.orientation,
362
- // @ts-ignore
363
- __scopeCollapsible: __scopeAccordion || ACCORDION_CONTEXT,
364
- ...contentProps,
365
- forceMount: forceMount || heightAnimatorPresent,
366
- ref: forwardedRef
367
- });
368
- });
369
- var HeightAnimator = View.styleable(function (props, ref) {
370
- var itemContext = useAccordionItemContext();
371
- var {
372
- children,
373
- transition,
374
- ...rest
375
- } = props;
376
- var open = !!itemContext.open;
377
- var [fixed, setFixed] = React.useState(!open);
378
- var [pinned, setPinned] = React.useState(false);
379
- var [contentPresent, setContentPresent] = React.useState(open);
380
- var [contentHeight, setContentHeight] = React.useState(0);
381
- var outerRef = React.useRef(null);
382
- var innerRef = React.useRef(null);
383
- var composedRef = useComposedRefs(outerRef, ref);
384
- var lastOuterHeightRef = React.useRef(0);
385
- var pinnedHeightRef = React.useRef(0);
386
- var settleTimerRef = React.useRef(void 0);
387
- var prevOpenRef = React.useRef(open);
388
- if (prevOpenRef.current !== open) {
389
- prevOpenRef.current = open;
390
- clearTimeout(settleTimerRef.current);
391
- if (open) {
392
- setContentPresent(true);
393
- } else if (lastOuterHeightRef.current < 1) {
394
- setContentPresent(false);
395
- }
396
- if (!fixed) {
397
- pinnedHeightRef.current = lastOuterHeightRef.current;
398
- setFixed(true);
399
- setPinned(true);
400
- }
401
- }
402
- useIsomorphicLayoutEffect(function () {
403
- if (!pinned) return;
404
- if (isWeb) {
405
- var _outerRef_current;
406
- void ((_outerRef_current = outerRef.current) === null || _outerRef_current === void 0 ? void 0 : _outerRef_current.offsetHeight);
407
- setPinned(false);
408
- return;
409
- }
410
- var frame = requestAnimationFrame(function () {
411
- return setPinned(false);
412
- });
413
- return function () {
414
- return cancelAnimationFrame(frame);
415
- };
416
- }, [pinned]);
417
- React.useEffect(function () {
418
- return function () {
419
- return clearTimeout(settleTimerRef.current);
420
- };
421
- }, []);
422
- useIsomorphicLayoutEffect(function () {
423
- var _el_getBoundingClientRect;
424
- if (!fixed || !open) return;
425
- var el = innerRef.current;
426
- var naturalHeight = el === null || el === void 0 ? void 0 : (_el_getBoundingClientRect = el.getBoundingClientRect) === null || _el_getBoundingClientRect === void 0 ? void 0 : _el_getBoundingClientRect.call(el).height;
427
- if (naturalHeight && naturalHeight > 0 && naturalHeight !== contentHeight) {
428
- setContentHeight(naturalHeight);
429
- }
430
- });
431
- var minHeight = pinned ? pinnedHeightRef.current : open ? contentHeight : 0;
432
- return /* @__PURE__ */_jsx(View, {
433
- ref: composedRef,
434
- position: "relative",
435
- ...rest,
436
- transition: fixed ? transition : void 0,
437
- height: "auto",
438
- minHeight,
439
- overflow: "hidden",
440
- onLayout: function (param) {
441
- var {
442
- nativeEvent
443
- } = param;
444
- var outerHeight = nativeEvent.layout.height;
445
- lastOuterHeightRef.current = outerHeight;
446
- if (isWeb && !open && contentPresent && outerHeight < 1) {
447
- setContentPresent(false);
448
- }
449
- clearTimeout(settleTimerRef.current);
450
- if (fixed && !pinned && open && contentHeight > 0) {
451
- if (Math.abs(outerHeight - contentHeight) < 1) {
452
- settleTimerRef.current = setTimeout(function () {
453
- return setFixed(false);
454
- }, 100);
455
- }
456
- }
457
- },
458
- // @ts-expect-error internal animation-driver completion hook
459
- onDidAnimate: function () {
460
- if (!prevOpenRef.current && !pinned) {
461
- setContentPresent(false);
462
- }
463
- },
464
- children: /* @__PURE__ */_jsx(View, {
465
- ref: innerRef,
466
- position: fixed ? "absolute" : "relative",
467
- top: fixed ? 0 : void 0,
468
- left: fixed ? 0 : void 0,
469
- right: fixed ? 0 : void 0,
470
- onLayout: function (param) {
471
- var {
472
- nativeEvent
473
- } = param;
474
- var naturalHeight = nativeEvent.layout.height;
475
- if (open && naturalHeight !== contentHeight) {
476
- setContentHeight(naturalHeight);
477
- }
478
- },
479
- children: /* @__PURE__ */_jsx(AccordionHeightAnimatorContext.Provider, {
480
- value: contentPresent,
481
- children
482
- })
483
- })
484
- });
290
+ var HeightAnimator = createStyledHOC(View, function(props, ref) {
291
+ var itemContext = useAccordionItemContext();
292
+ var { children, transition, ...rest } = props;
293
+ var open = !!itemContext.open;
294
+ var [fixed, setFixed] = React.useState(!open);
295
+ var [pinned, setPinned] = React.useState(false);
296
+ var [contentPresent, setContentPresent] = React.useState(open);
297
+ var [contentHeight, setContentHeight] = React.useState(0);
298
+ var outerRef = React.useRef(null);
299
+ var innerRef = React.useRef(null);
300
+ var composedRef = useComposedRefs(outerRef, ref);
301
+ var lastOuterHeightRef = React.useRef(0);
302
+ var pinnedHeightRef = React.useRef(0);
303
+ var settleTimerRef = React.useRef(void 0);
304
+ var prevOpenRef = React.useRef(open);
305
+ if (prevOpenRef.current !== open) {
306
+ prevOpenRef.current = open;
307
+ clearTimeout(settleTimerRef.current);
308
+ if (open) {
309
+ setContentPresent(true);
310
+ } else if (lastOuterHeightRef.current < 1) {
311
+ setContentPresent(false);
312
+ }
313
+ if (!fixed) {
314
+ pinnedHeightRef.current = lastOuterHeightRef.current;
315
+ setFixed(true);
316
+ setPinned(true);
317
+ }
318
+ }
319
+ useIsomorphicLayoutEffect(function() {
320
+ if (!pinned) return;
321
+ if (isWeb) {
322
+ var _outerRef_current;
323
+ void ((_outerRef_current = outerRef.current) === null || _outerRef_current === void 0 ? void 0 : _outerRef_current.offsetHeight);
324
+ setPinned(false);
325
+ return;
326
+ }
327
+ var frame = requestAnimationFrame(function() {
328
+ return setPinned(false);
329
+ });
330
+ return function() {
331
+ return cancelAnimationFrame(frame);
332
+ };
333
+ }, [pinned]);
334
+ React.useEffect(function() {
335
+ return function() {
336
+ return clearTimeout(settleTimerRef.current);
337
+ };
338
+ }, []);
339
+ useIsomorphicLayoutEffect(function() {
340
+ var _el_getBoundingClientRect;
341
+ if (!fixed || !open) return;
342
+ var el = innerRef.current;
343
+ var naturalHeight = el === null || el === void 0 ? void 0 : (_el_getBoundingClientRect = el.getBoundingClientRect) === null || _el_getBoundingClientRect === void 0 ? void 0 : _el_getBoundingClientRect.call(el).height;
344
+ if (naturalHeight && naturalHeight > 0 && naturalHeight !== contentHeight) {
345
+ setContentHeight(naturalHeight);
346
+ }
347
+ });
348
+ var minHeight = pinned ? pinnedHeightRef.current : open ? contentHeight : 0;
349
+ return /* @__PURE__ */ jsx(View, {
350
+ ref: composedRef,
351
+ position: "relative",
352
+ ...rest,
353
+ transition: fixed ? transition : void 0,
354
+ height: "auto",
355
+ minHeight,
356
+ overflow: "hidden",
357
+ onLayout: function(param) {
358
+ var { nativeEvent } = param;
359
+ var outerHeight = nativeEvent.layout.height;
360
+ lastOuterHeightRef.current = outerHeight;
361
+ if (isWeb && !open && contentPresent && outerHeight < 1) {
362
+ setContentPresent(false);
363
+ }
364
+ clearTimeout(settleTimerRef.current);
365
+ if (fixed && !pinned && open && contentHeight > 0) {
366
+ if (Math.abs(outerHeight - contentHeight) < 1) {
367
+ settleTimerRef.current = setTimeout(function() {
368
+ return setFixed(false);
369
+ }, 100);
370
+ }
371
+ }
372
+ },
373
+ onTransition: function(event) {
374
+ if (event.phase !== "end" || event.cause !== "update" || !event.finished) return;
375
+ if (!prevOpenRef.current && !pinned) {
376
+ setContentPresent(false);
377
+ }
378
+ },
379
+ children: /* @__PURE__ */ jsx(View, {
380
+ ref: innerRef,
381
+ position: fixed ? "absolute" : "relative",
382
+ top: fixed ? 0 : void 0,
383
+ left: fixed ? 0 : void 0,
384
+ right: fixed ? 0 : void 0,
385
+ onLayout: function(param) {
386
+ var { nativeEvent } = param;
387
+ var naturalHeight = nativeEvent.layout.height;
388
+ if (open && naturalHeight !== contentHeight) {
389
+ setContentHeight(naturalHeight);
390
+ }
391
+ },
392
+ children: /* @__PURE__ */ jsx(AccordionHeightAnimatorContext.Provider, {
393
+ value: contentPresent,
394
+ children
395
+ })
396
+ })
397
+ });
485
398
  });
486
399
  function getState(open) {
487
- return open ? "open" : "closed";
400
+ return open ? "open" : "closed";
488
401
  }
489
402
  var Accordion = withStaticProperties(AccordionComponent, {
490
- Trigger: AccordionTrigger,
491
- Header: AccordionHeader,
492
- Content: AccordionContent,
493
- Item: AccordionItem,
494
- HeightAnimator
403
+ Trigger: AccordionTrigger,
404
+ Header: AccordionHeader,
405
+ Content: AccordionContent,
406
+ Item: AccordionItem,
407
+ HeightAnimator
495
408
  });
409
+
496
410
  export { Accordion };
497
411
  //# sourceMappingURL=Accordion.native.js.map