@tamagui/accordion 2.0.0-rc.4 → 2.0.0-rc.40

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