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