@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.
- package/dist/cjs/Accordion.cjs +371 -328
- package/dist/cjs/Accordion.native.js +389 -352
- package/dist/cjs/Accordion.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Accordion.mjs +335 -294
- package/dist/esm/Accordion.mjs.map +1 -1
- package/dist/esm/Accordion.native.js +353 -318
- package/dist/esm/Accordion.native.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -6
- package/dist/jsx/Accordion.mjs +335 -294
- package/dist/jsx/Accordion.mjs.map +1 -1
- package/dist/jsx/Accordion.native.js +389 -352
- package/dist/jsx/Accordion.native.js.map +1 -1
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -6
- package/dist/jsx/index.native.js +7 -5
- package/package.json +17 -20
- package/dist/cjs/Accordion.js +0 -308
- package/dist/cjs/Accordion.js.map +0 -6
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/index.js.map +0 -6
- package/dist/esm/Accordion.js +0 -295
- package/dist/esm/Accordion.js.map +0 -6
- package/dist/jsx/Accordion.js +0 -295
- package/dist/jsx/Accordion.js.map +0 -6
package/dist/cjs/Accordion.cjs
CHANGED
|
@@ -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
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const ACCORDION_NAME = "Accordion"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
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
|
}
|