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