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