@tamagui/accordion 2.0.0-rc.9 → 2.0.0

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