@xaui/native 0.0.3 → 0.0.5
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/accordion/index.cjs +551 -0
- package/dist/accordion/index.d.cts +141 -0
- package/dist/accordion/index.d.ts +141 -0
- package/dist/accordion/index.js +434 -0
- package/dist/button/index.cjs +4 -3
- package/dist/button/index.d.cts +1 -1
- package/dist/button/index.d.ts +1 -1
- package/dist/button/index.js +5 -5
- package/dist/checkbox/index.cjs +207 -134
- package/dist/checkbox/index.d.cts +4 -6
- package/dist/checkbox/index.d.ts +4 -6
- package/dist/checkbox/index.js +200 -128
- package/dist/{chunk-DNJWBME5.js → chunk-3ECCBLTG.js} +10 -1
- package/dist/chunk-AX7QS5WJ.js +73 -0
- package/dist/{chunk-52PIZF2Z.js → chunk-KI7CPXTP.js} +1 -1
- package/dist/core/index.cjs +5 -1
- package/dist/core/index.js +1 -1
- package/dist/divider/index.cjs +125 -0
- package/dist/divider/index.d.cts +30 -0
- package/dist/divider/index.d.ts +30 -0
- package/dist/divider/index.js +7 -0
- package/dist/{index-BDSvmsTU.d.cts → index-BOw6tbkc.d.cts} +2 -1
- package/dist/{index-BDSvmsTU.d.ts → index-BOw6tbkc.d.ts} +2 -1
- package/dist/index.cjs +71 -2
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -3
- package/dist/indicator/index.cjs +1 -0
- package/dist/indicator/index.d.cts +1 -1
- package/dist/indicator/index.d.ts +1 -1
- package/dist/indicator/index.js +2 -2
- package/dist/progress/index.cjs +1 -0
- package/dist/progress/index.d.cts +1 -1
- package/dist/progress/index.d.ts +1 -1
- package/dist/progress/index.js +1 -1
- package/package.json +12 -2
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
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", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/components/accordion/index.ts
|
|
31
|
+
var accordion_exports = {};
|
|
32
|
+
__export(accordion_exports, {
|
|
33
|
+
Accordion: () => Accordion,
|
|
34
|
+
AccordionItem: () => AccordionItem
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(accordion_exports);
|
|
37
|
+
|
|
38
|
+
// src/components/accordion/accordion.tsx
|
|
39
|
+
var import_react11 = __toESM(require("react"), 1);
|
|
40
|
+
var import_react_native8 = require("react-native");
|
|
41
|
+
|
|
42
|
+
// src/components/accordion/accordion-context.ts
|
|
43
|
+
var import_react = require("react");
|
|
44
|
+
var AccordionContext = (0, import_react.createContext)(void 0);
|
|
45
|
+
var useAccordionContext = () => {
|
|
46
|
+
const context = (0, import_react.useContext)(AccordionContext);
|
|
47
|
+
if (!context) {
|
|
48
|
+
throw new Error("AccordionItem must be used within an Accordion component");
|
|
49
|
+
}
|
|
50
|
+
return context;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/components/accordion/accordion.hook.ts
|
|
54
|
+
var import_react4 = require("react");
|
|
55
|
+
|
|
56
|
+
// src/core/theme-context.tsx
|
|
57
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
58
|
+
var import_react_native = require("react-native");
|
|
59
|
+
var import_theme = require("@xaui/core/theme");
|
|
60
|
+
var import_palette = require("@xaui/core/palette");
|
|
61
|
+
var XUIThemeContext = (0, import_react2.createContext)(null);
|
|
62
|
+
|
|
63
|
+
// src/core/theme-hooks.ts
|
|
64
|
+
var import_react3 = require("react");
|
|
65
|
+
var import_react_native2 = require("react-native");
|
|
66
|
+
function useXUITheme() {
|
|
67
|
+
const theme = (0, import_react3.useContext)(XUIThemeContext);
|
|
68
|
+
if (!theme) {
|
|
69
|
+
throw new Error("useXUITheme must be used within XUIProvider");
|
|
70
|
+
}
|
|
71
|
+
return theme;
|
|
72
|
+
}
|
|
73
|
+
function useXUIPalette() {
|
|
74
|
+
const theme = useXUITheme();
|
|
75
|
+
return (0, import_react3.useMemo)(() => theme.palette, [theme]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/components/accordion/accordion.hook.ts
|
|
79
|
+
var useAccordionStyles = ({ variant, fullWidth }) => {
|
|
80
|
+
const theme = useXUITheme();
|
|
81
|
+
const palette2 = useXUIPalette();
|
|
82
|
+
const containerStyles = (0, import_react4.useMemo)(() => {
|
|
83
|
+
const base = {};
|
|
84
|
+
if (fullWidth) {
|
|
85
|
+
base.width = "100%";
|
|
86
|
+
}
|
|
87
|
+
if (variant === "bordered") {
|
|
88
|
+
base.borderWidth = theme.borderWidth.md;
|
|
89
|
+
base.borderColor = theme.mode === "dark" ? palette2.gray[800] : theme.palette.gray[200];
|
|
90
|
+
base.borderRadius = theme.borderRadius.md;
|
|
91
|
+
base.marginHorizontal = theme.spacing.sm;
|
|
92
|
+
base.overflow = "hidden";
|
|
93
|
+
} else if (variant === "light") {
|
|
94
|
+
base.paddingHorizontal = theme.spacing.sm;
|
|
95
|
+
}
|
|
96
|
+
return base;
|
|
97
|
+
}, [variant, fullWidth, theme]);
|
|
98
|
+
const dividerColor = variant === "bordered" ? containerStyles.borderColor : theme.mode === "dark" ? palette2.gray[800] : theme.palette.gray[200];
|
|
99
|
+
const dividerOpacity = variant === "bordered" ? 1 : 0.2;
|
|
100
|
+
return { containerStyles, dividerColor, dividerOpacity };
|
|
101
|
+
};
|
|
102
|
+
var useAccordionSelection = ({
|
|
103
|
+
selectionMode,
|
|
104
|
+
expandedKeys,
|
|
105
|
+
defaultExpandedKeys,
|
|
106
|
+
onSelectionChange
|
|
107
|
+
}) => {
|
|
108
|
+
const [internalExpandedKeys, setInternalExpandedKeys] = (0, import_react4.useState)(defaultExpandedKeys);
|
|
109
|
+
const isControlled = expandedKeys !== void 0;
|
|
110
|
+
const currentExpandedKeys = isControlled ? expandedKeys : internalExpandedKeys;
|
|
111
|
+
const toggleItem = (0, import_react4.useCallback)(
|
|
112
|
+
(key) => {
|
|
113
|
+
const isExpanded = currentExpandedKeys.includes(key);
|
|
114
|
+
const newExpandedKeys = selectionMode === "toggle" ? isExpanded ? [] : [key] : isExpanded ? currentExpandedKeys.filter((k) => k !== key) : [...currentExpandedKeys, key];
|
|
115
|
+
if (!isControlled) {
|
|
116
|
+
setInternalExpandedKeys(newExpandedKeys);
|
|
117
|
+
}
|
|
118
|
+
onSelectionChange?.(newExpandedKeys);
|
|
119
|
+
},
|
|
120
|
+
[selectionMode, currentExpandedKeys, isControlled, onSelectionChange]
|
|
121
|
+
);
|
|
122
|
+
return { currentExpandedKeys, toggleItem };
|
|
123
|
+
};
|
|
124
|
+
var useAccordionContextValue = (config) => {
|
|
125
|
+
const { currentExpandedKeys, toggleItem } = useAccordionSelection({
|
|
126
|
+
selectionMode: config.selectionMode,
|
|
127
|
+
expandedKeys: config.expandedKeys,
|
|
128
|
+
defaultExpandedKeys: config.defaultExpandedKeys,
|
|
129
|
+
onSelectionChange: config.onSelectionChange
|
|
130
|
+
});
|
|
131
|
+
return (0, import_react4.useMemo)(
|
|
132
|
+
() => ({
|
|
133
|
+
variant: config.variant,
|
|
134
|
+
hideIndicator: config.hideIndicator,
|
|
135
|
+
disableAnimation: config.disableAnimation,
|
|
136
|
+
isCompact: config.isCompact,
|
|
137
|
+
showDivider: config.showDivider,
|
|
138
|
+
expandedKeys: currentExpandedKeys,
|
|
139
|
+
disabledKeys: config.disabledKeys,
|
|
140
|
+
toggleItem
|
|
141
|
+
}),
|
|
142
|
+
[
|
|
143
|
+
config.variant,
|
|
144
|
+
config.hideIndicator,
|
|
145
|
+
config.disableAnimation,
|
|
146
|
+
config.isCompact,
|
|
147
|
+
config.showDivider,
|
|
148
|
+
currentExpandedKeys,
|
|
149
|
+
config.disabledKeys,
|
|
150
|
+
toggleItem
|
|
151
|
+
]
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// src/components/accordion/accordion-item.tsx
|
|
156
|
+
var import_react7 = __toESM(require("react"), 1);
|
|
157
|
+
var import_react_native5 = require("react-native");
|
|
158
|
+
|
|
159
|
+
// src/components/accordion/accordion-item.style.ts
|
|
160
|
+
var import_react_native3 = require("react-native");
|
|
161
|
+
var styles = import_react_native3.StyleSheet.create({
|
|
162
|
+
startContent: {
|
|
163
|
+
flexShrink: 0
|
|
164
|
+
},
|
|
165
|
+
titleWrapper: {
|
|
166
|
+
flex: 1
|
|
167
|
+
},
|
|
168
|
+
indicator: {
|
|
169
|
+
flexShrink: 0
|
|
170
|
+
},
|
|
171
|
+
hiddenMeasure: {
|
|
172
|
+
position: "absolute",
|
|
173
|
+
opacity: 0,
|
|
174
|
+
left: 0,
|
|
175
|
+
right: 0,
|
|
176
|
+
zIndex: -999
|
|
177
|
+
},
|
|
178
|
+
contentOverflow: {
|
|
179
|
+
overflow: "hidden"
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// src/components/accordion/accordion-item.hook.ts
|
|
184
|
+
var import_react5 = require("react");
|
|
185
|
+
var import_react_native4 = require("react-native");
|
|
186
|
+
var import_palette2 = require("@xaui/core/palette");
|
|
187
|
+
var useAccordionItemState = (itemKey) => {
|
|
188
|
+
const context = useAccordionContext();
|
|
189
|
+
const resolvedItemKey = itemKey ?? "";
|
|
190
|
+
const isExpanded = resolvedItemKey ? context.expandedKeys.includes(resolvedItemKey) : false;
|
|
191
|
+
const isDisabled = resolvedItemKey ? context.disabledKeys.includes(resolvedItemKey) : false;
|
|
192
|
+
const handlePress = (0, import_react5.useCallback)(() => {
|
|
193
|
+
if (isDisabled || !resolvedItemKey) return;
|
|
194
|
+
context.toggleItem(resolvedItemKey);
|
|
195
|
+
}, [isDisabled, resolvedItemKey, context]);
|
|
196
|
+
return { ...context, resolvedItemKey, isExpanded, isDisabled, handlePress };
|
|
197
|
+
};
|
|
198
|
+
var useAccordionItemAnimation = (isExpanded, disableAnimation) => {
|
|
199
|
+
const [contentHeight, setContentHeight] = (0, import_react5.useState)(0);
|
|
200
|
+
const [isMeasured, setIsMeasured] = (0, import_react5.useState)(false);
|
|
201
|
+
const animatedHeight = (0, import_react5.useRef)(new import_react_native4.Animated.Value(isExpanded ? 1 : 0)).current;
|
|
202
|
+
const animatedRotation = (0, import_react5.useRef)(new import_react_native4.Animated.Value(isExpanded ? 1 : 0)).current;
|
|
203
|
+
const prevContentHeight = (0, import_react5.useRef)(contentHeight);
|
|
204
|
+
(0, import_react5.useEffect)(() => {
|
|
205
|
+
if (disableAnimation) {
|
|
206
|
+
animatedHeight.setValue(isExpanded ? 1 : 0);
|
|
207
|
+
animatedRotation.setValue(isExpanded ? 1 : 0);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
import_react_native4.Animated.parallel([
|
|
211
|
+
import_react_native4.Animated.timing(animatedHeight, {
|
|
212
|
+
toValue: isExpanded ? 1 : 0,
|
|
213
|
+
duration: 300,
|
|
214
|
+
easing: import_react_native4.Easing.bezier(0.4, 0, 0.2, 1),
|
|
215
|
+
useNativeDriver: false
|
|
216
|
+
}),
|
|
217
|
+
import_react_native4.Animated.timing(animatedRotation, {
|
|
218
|
+
toValue: isExpanded ? 1 : 0,
|
|
219
|
+
duration: 300,
|
|
220
|
+
easing: import_react_native4.Easing.bezier(0.4, 0, 0.2, 1),
|
|
221
|
+
useNativeDriver: true
|
|
222
|
+
})
|
|
223
|
+
]).start();
|
|
224
|
+
}, [isExpanded, disableAnimation, animatedHeight, animatedRotation]);
|
|
225
|
+
(0, import_react5.useEffect)(() => {
|
|
226
|
+
if (contentHeight <= 0 || contentHeight === prevContentHeight.current || !isExpanded)
|
|
227
|
+
return;
|
|
228
|
+
prevContentHeight.current = contentHeight;
|
|
229
|
+
if (!disableAnimation && isMeasured) {
|
|
230
|
+
import_react_native4.Animated.timing(animatedHeight, {
|
|
231
|
+
toValue: 1,
|
|
232
|
+
duration: 200,
|
|
233
|
+
easing: import_react_native4.Easing.out(import_react_native4.Easing.ease),
|
|
234
|
+
useNativeDriver: false
|
|
235
|
+
}).start();
|
|
236
|
+
}
|
|
237
|
+
}, [contentHeight, isExpanded, disableAnimation, isMeasured, animatedHeight]);
|
|
238
|
+
const onContentLayout = (0, import_react5.useCallback)((event) => {
|
|
239
|
+
const height = event.nativeEvent.layout.height;
|
|
240
|
+
if (height > 0) {
|
|
241
|
+
setContentHeight(height);
|
|
242
|
+
setIsMeasured(true);
|
|
243
|
+
}
|
|
244
|
+
}, []);
|
|
245
|
+
const heightInterpolation = animatedHeight.interpolate({
|
|
246
|
+
inputRange: [0, 1],
|
|
247
|
+
outputRange: [0, contentHeight]
|
|
248
|
+
});
|
|
249
|
+
const rotationInterpolation = animatedRotation.interpolate({
|
|
250
|
+
inputRange: [0, 1],
|
|
251
|
+
outputRange: ["0deg", "90deg"]
|
|
252
|
+
});
|
|
253
|
+
return {
|
|
254
|
+
onContentLayout,
|
|
255
|
+
heightInterpolation,
|
|
256
|
+
rotationInterpolation,
|
|
257
|
+
contentHeight
|
|
258
|
+
};
|
|
259
|
+
};
|
|
260
|
+
var useBaseStyles = (variant, isDisabled) => {
|
|
261
|
+
const theme = useXUITheme();
|
|
262
|
+
const baseStyles = (0, import_react5.useMemo)(() => {
|
|
263
|
+
const base = { overflow: "hidden" };
|
|
264
|
+
if (variant === "splitted") {
|
|
265
|
+
base.paddingHorizontal = theme.spacing.md;
|
|
266
|
+
base.backgroundColor = theme.colors.default.background;
|
|
267
|
+
base.borderRadius = theme.borderRadius.md;
|
|
268
|
+
base.marginBottom = theme.spacing.sm;
|
|
269
|
+
} else if (variant === "bordered") {
|
|
270
|
+
base.paddingHorizontal = theme.spacing.md;
|
|
271
|
+
}
|
|
272
|
+
if (isDisabled) {
|
|
273
|
+
base.opacity = 0.4;
|
|
274
|
+
}
|
|
275
|
+
return base;
|
|
276
|
+
}, [variant, isDisabled, theme]);
|
|
277
|
+
return baseStyles;
|
|
278
|
+
};
|
|
279
|
+
var useTriggerStyles = (variant, isCompact) => {
|
|
280
|
+
const theme = useXUITheme();
|
|
281
|
+
const triggerStyles = (0, import_react5.useMemo)(() => {
|
|
282
|
+
const trigger = {
|
|
283
|
+
flexDirection: "row",
|
|
284
|
+
alignItems: "center",
|
|
285
|
+
paddingVertical: isCompact ? theme.spacing.xs : theme.spacing.md,
|
|
286
|
+
gap: theme.spacing.md
|
|
287
|
+
};
|
|
288
|
+
if (variant === "light") {
|
|
289
|
+
trigger.paddingHorizontal = theme.spacing.sm;
|
|
290
|
+
}
|
|
291
|
+
return trigger;
|
|
292
|
+
}, [variant, isCompact, theme]);
|
|
293
|
+
return triggerStyles;
|
|
294
|
+
};
|
|
295
|
+
var useTitleTextStyle = (isCompact) => {
|
|
296
|
+
const theme = useXUITheme();
|
|
297
|
+
const titleTextStyle = (0, import_react5.useMemo)(
|
|
298
|
+
() => ({
|
|
299
|
+
fontSize: isCompact ? theme.fontSizes.md : theme.fontSizes.lg,
|
|
300
|
+
fontWeight: theme.fontWeights.medium,
|
|
301
|
+
color: theme.colors.foreground
|
|
302
|
+
}),
|
|
303
|
+
[isCompact, theme]
|
|
304
|
+
);
|
|
305
|
+
return titleTextStyle;
|
|
306
|
+
};
|
|
307
|
+
var useSubtitleTextStyle = () => {
|
|
308
|
+
const theme = useXUITheme();
|
|
309
|
+
const subtitleTextStyle = (0, import_react5.useMemo)(
|
|
310
|
+
() => ({
|
|
311
|
+
fontSize: theme.fontSizes.sm,
|
|
312
|
+
color: import_palette2.colors.gray[500],
|
|
313
|
+
marginTop: theme.spacing.xs
|
|
314
|
+
}),
|
|
315
|
+
[theme]
|
|
316
|
+
);
|
|
317
|
+
return subtitleTextStyle;
|
|
318
|
+
};
|
|
319
|
+
var useContentContainerStyle = (isCompact, variant) => {
|
|
320
|
+
const theme = useXUITheme();
|
|
321
|
+
const contentContainerStyle = (0, import_react5.useMemo)(
|
|
322
|
+
() => ({
|
|
323
|
+
paddingBottom: isCompact ? theme.spacing.sm : theme.spacing.md,
|
|
324
|
+
paddingHorizontal: variant === "light" ? theme.spacing.sm : 0
|
|
325
|
+
}),
|
|
326
|
+
[isCompact, variant, theme]
|
|
327
|
+
);
|
|
328
|
+
return contentContainerStyle;
|
|
329
|
+
};
|
|
330
|
+
var useForegroundColor = () => {
|
|
331
|
+
const theme = useXUITheme();
|
|
332
|
+
return theme.colors.foreground;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// src/components/accordion/chevron-right-icon.tsx
|
|
336
|
+
var import_react6 = __toESM(require("react"), 1);
|
|
337
|
+
var import_react_native_svg = __toESM(require("react-native-svg"), 1);
|
|
338
|
+
var ChevronRightIcon = ({
|
|
339
|
+
color = "#000",
|
|
340
|
+
size = 20
|
|
341
|
+
}) => {
|
|
342
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react_native_svg.default, { width: size, height: size, viewBox: "0 0 24 24", fill: "none" }, /* @__PURE__ */ import_react6.default.createElement(
|
|
343
|
+
import_react_native_svg.Path,
|
|
344
|
+
{
|
|
345
|
+
d: "M9 18l6-6-6-6",
|
|
346
|
+
stroke: color,
|
|
347
|
+
strokeWidth: 2,
|
|
348
|
+
strokeLinecap: "round",
|
|
349
|
+
strokeLinejoin: "round"
|
|
350
|
+
}
|
|
351
|
+
));
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// src/components/accordion/accordion-item.tsx
|
|
355
|
+
var AccordionItem = ({
|
|
356
|
+
itemKey,
|
|
357
|
+
children,
|
|
358
|
+
title,
|
|
359
|
+
subtitle,
|
|
360
|
+
startContent,
|
|
361
|
+
indicator,
|
|
362
|
+
baseStyle,
|
|
363
|
+
headingStyle,
|
|
364
|
+
triggerStyle,
|
|
365
|
+
titleStyle,
|
|
366
|
+
subtitleStyle,
|
|
367
|
+
contentStyle,
|
|
368
|
+
startContentStyle,
|
|
369
|
+
indicatorStyle,
|
|
370
|
+
onSelected
|
|
371
|
+
}) => {
|
|
372
|
+
const {
|
|
373
|
+
variant,
|
|
374
|
+
hideIndicator,
|
|
375
|
+
disableAnimation,
|
|
376
|
+
isCompact,
|
|
377
|
+
isExpanded,
|
|
378
|
+
isDisabled,
|
|
379
|
+
handlePress: togglePress
|
|
380
|
+
} = useAccordionItemState(itemKey);
|
|
381
|
+
const handlePress = () => {
|
|
382
|
+
togglePress();
|
|
383
|
+
onSelected?.(!isExpanded);
|
|
384
|
+
};
|
|
385
|
+
const { onContentLayout, heightInterpolation, rotationInterpolation } = useAccordionItemAnimation(isExpanded, disableAnimation);
|
|
386
|
+
const baseStyles = useBaseStyles(variant, isDisabled);
|
|
387
|
+
const triggerStyles = useTriggerStyles(variant, isCompact);
|
|
388
|
+
const titleTextStyle = useTitleTextStyle(isCompact);
|
|
389
|
+
const subtitleTextStyle = useSubtitleTextStyle();
|
|
390
|
+
const contentContainerStyle = useContentContainerStyle(isCompact, variant);
|
|
391
|
+
const foregroundColor = useForegroundColor();
|
|
392
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { style: [baseStyles, baseStyle] }, /* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { style: headingStyle }, /* @__PURE__ */ import_react7.default.createElement(
|
|
393
|
+
import_react_native5.Pressable,
|
|
394
|
+
{
|
|
395
|
+
style: [triggerStyles, triggerStyle],
|
|
396
|
+
onPress: handlePress,
|
|
397
|
+
disabled: isDisabled,
|
|
398
|
+
accessibilityRole: "button",
|
|
399
|
+
accessibilityState: { expanded: isExpanded, disabled: isDisabled }
|
|
400
|
+
},
|
|
401
|
+
startContent && /* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { style: [styles.startContent, startContentStyle] }, startContent),
|
|
402
|
+
/* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { style: styles.titleWrapper }, typeof title === "string" ? /* @__PURE__ */ import_react7.default.createElement(import_react_native5.Text, { style: [titleTextStyle, titleStyle] }, title) : title, subtitle && (typeof subtitle === "string" ? /* @__PURE__ */ import_react7.default.createElement(import_react_native5.Text, { style: [subtitleTextStyle, subtitleStyle] }, subtitle) : subtitle)),
|
|
403
|
+
!hideIndicator && /* @__PURE__ */ import_react7.default.createElement(
|
|
404
|
+
import_react_native5.Animated.View,
|
|
405
|
+
{
|
|
406
|
+
style: [
|
|
407
|
+
styles.indicator,
|
|
408
|
+
indicatorStyle,
|
|
409
|
+
{ transform: [{ rotate: rotationInterpolation }] }
|
|
410
|
+
]
|
|
411
|
+
},
|
|
412
|
+
indicator || /* @__PURE__ */ import_react7.default.createElement(ChevronRightIcon, { color: foregroundColor })
|
|
413
|
+
)
|
|
414
|
+
)), /* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { style: styles.hiddenMeasure, pointerEvents: "none" }, /* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { onLayout: onContentLayout, style: [contentContainerStyle, contentStyle] }, children)), /* @__PURE__ */ import_react7.default.createElement(
|
|
415
|
+
import_react_native5.Animated.View,
|
|
416
|
+
{
|
|
417
|
+
style: [
|
|
418
|
+
styles.contentOverflow,
|
|
419
|
+
disableAnimation ? { height: isExpanded ? void 0 : 0 } : { height: heightInterpolation }
|
|
420
|
+
]
|
|
421
|
+
},
|
|
422
|
+
/* @__PURE__ */ import_react7.default.createElement(import_react_native5.View, { style: [contentContainerStyle, contentStyle] }, children)
|
|
423
|
+
));
|
|
424
|
+
};
|
|
425
|
+
AccordionItem.displayName = "AccordionItem";
|
|
426
|
+
|
|
427
|
+
// src/components/accordion/accordion.utils.ts
|
|
428
|
+
var import_react8 = __toESM(require("react"), 1);
|
|
429
|
+
var getItemKey = (value, fallback) => {
|
|
430
|
+
if (value === null || value === void 0) return String(fallback);
|
|
431
|
+
if (typeof value === "string" || typeof value === "number") return String(value);
|
|
432
|
+
return String(fallback);
|
|
433
|
+
};
|
|
434
|
+
var normalizeElementKey = (value) => {
|
|
435
|
+
if (typeof value !== "string") return value;
|
|
436
|
+
return value.startsWith(".$") ? value.slice(2) : value.startsWith(".") ? value.slice(1) : value;
|
|
437
|
+
};
|
|
438
|
+
var isAccordionItem = (value) => import_react8.default.isValidElement(value) && (value.type === AccordionItem || typeof value.type === "function" && value.type.displayName === "AccordionItem");
|
|
439
|
+
var buildAccordionContextParams = (props) => {
|
|
440
|
+
return {
|
|
441
|
+
variant: props.variant || "light",
|
|
442
|
+
hideIndicator: Boolean(props.hideIndicator),
|
|
443
|
+
disableAnimation: Boolean(props.disableAnimation),
|
|
444
|
+
isCompact: Boolean(props.isCompact),
|
|
445
|
+
showDivider: Boolean(props.showDivider),
|
|
446
|
+
expandedKeys: props.expandedKeys,
|
|
447
|
+
defaultExpandedKeys: props.defaultExpandedKeys || [],
|
|
448
|
+
disabledKeys: props.disabledKeys || [],
|
|
449
|
+
selectionMode: props.selectionMode || "toggle",
|
|
450
|
+
onSelectionChange: props.onSelectionChange
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
// src/components/divider/divider.tsx
|
|
455
|
+
var import_react10 = __toESM(require("react"), 1);
|
|
456
|
+
var import_react_native7 = require("react-native");
|
|
457
|
+
|
|
458
|
+
// src/components/divider/divider.style.ts
|
|
459
|
+
var import_react_native6 = require("react-native");
|
|
460
|
+
var styles2 = import_react_native6.StyleSheet.create({
|
|
461
|
+
horizontal: {
|
|
462
|
+
height: 1,
|
|
463
|
+
width: "100%"
|
|
464
|
+
},
|
|
465
|
+
vertical: {
|
|
466
|
+
width: 1,
|
|
467
|
+
alignSelf: "stretch"
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
// src/components/divider/divider.hook.ts
|
|
472
|
+
var import_react9 = require("react");
|
|
473
|
+
var import_core4 = require("@xaui/core");
|
|
474
|
+
var useDividerColor = (themeColor, customColor) => {
|
|
475
|
+
const theme = useXUITheme();
|
|
476
|
+
const dividerColor = (0, import_react9.useMemo)(() => {
|
|
477
|
+
if (customColor) {
|
|
478
|
+
return customColor;
|
|
479
|
+
}
|
|
480
|
+
const safeThemeColor = (0, import_core4.getSafeThemeColor)(themeColor);
|
|
481
|
+
return theme.colors[safeThemeColor].main;
|
|
482
|
+
}, [customColor, themeColor, theme]);
|
|
483
|
+
return dividerColor;
|
|
484
|
+
};
|
|
485
|
+
var useDividerSize = (size, orientation) => {
|
|
486
|
+
const sizeStyles = (0, import_react9.useMemo)(() => {
|
|
487
|
+
if (orientation === "horizontal") {
|
|
488
|
+
return {
|
|
489
|
+
height: size
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
return {
|
|
493
|
+
width: size
|
|
494
|
+
};
|
|
495
|
+
}, [size, orientation]);
|
|
496
|
+
return sizeStyles;
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// src/components/divider/divider.tsx
|
|
500
|
+
var Divider = ({
|
|
501
|
+
size = 1,
|
|
502
|
+
themeColor = "default",
|
|
503
|
+
color,
|
|
504
|
+
orientation = "horizontal"
|
|
505
|
+
}) => {
|
|
506
|
+
const dividerColor = useDividerColor(themeColor, color);
|
|
507
|
+
const sizeStyles = useDividerSize(size, orientation);
|
|
508
|
+
return /* @__PURE__ */ import_react10.default.createElement(
|
|
509
|
+
import_react_native7.View,
|
|
510
|
+
{
|
|
511
|
+
style: [
|
|
512
|
+
orientation === "horizontal" ? styles2.horizontal : styles2.vertical,
|
|
513
|
+
sizeStyles,
|
|
514
|
+
{ backgroundColor: dividerColor }
|
|
515
|
+
]
|
|
516
|
+
}
|
|
517
|
+
);
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// src/components/accordion/accordion.tsx
|
|
521
|
+
var Accordion = (props) => {
|
|
522
|
+
const {
|
|
523
|
+
children,
|
|
524
|
+
variant = "light",
|
|
525
|
+
showDivider = false,
|
|
526
|
+
fullWidth = true,
|
|
527
|
+
containerStyle,
|
|
528
|
+
itemStyle
|
|
529
|
+
} = props;
|
|
530
|
+
const { containerStyles, dividerColor } = useAccordionStyles({
|
|
531
|
+
variant,
|
|
532
|
+
fullWidth
|
|
533
|
+
});
|
|
534
|
+
const contextParams = buildAccordionContextParams(props);
|
|
535
|
+
const contextValue = useAccordionContextValue(contextParams);
|
|
536
|
+
const childrenArray = import_react11.default.Children.toArray(children);
|
|
537
|
+
return /* @__PURE__ */ import_react11.default.createElement(AccordionContext.Provider, { value: contextValue }, /* @__PURE__ */ import_react11.default.createElement(import_react_native8.View, { style: [containerStyles, containerStyle] }, childrenArray.map((child, index) => {
|
|
538
|
+
const isLast = index === childrenArray.length - 1;
|
|
539
|
+
const showBottomDivider = (showDivider || variant === "bordered") && !isLast && variant !== "splitted";
|
|
540
|
+
const resolvedChildKey = isAccordionItem(child) ? getItemKey(child.props.itemKey ?? normalizeElementKey(child.key), index) : getItemKey(
|
|
541
|
+
import_react11.default.isValidElement(child) ? normalizeElementKey(child.key) : void 0,
|
|
542
|
+
index
|
|
543
|
+
);
|
|
544
|
+
return /* @__PURE__ */ import_react11.default.createElement(import_react_native8.View, { key: resolvedChildKey, style: itemStyle }, isAccordionItem(child) ? import_react11.default.cloneElement(child, { itemKey: resolvedChildKey }) : child, showBottomDivider && /* @__PURE__ */ import_react11.default.createElement(Divider, { color: dividerColor, size: 2 }));
|
|
545
|
+
})));
|
|
546
|
+
};
|
|
547
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
548
|
+
0 && (module.exports = {
|
|
549
|
+
Accordion,
|
|
550
|
+
AccordionItem
|
|
551
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
type AccordionVariant = 'light' | 'bordered' | 'splitted';
|
|
5
|
+
type AccordionSelectionMode = 'toggle' | 'multiple';
|
|
6
|
+
type AccordionEvents = {
|
|
7
|
+
onSelectionChange?: (selectedKeys: string[]) => void;
|
|
8
|
+
};
|
|
9
|
+
type AccordionProps = {
|
|
10
|
+
/**
|
|
11
|
+
* List of AccordionItem components
|
|
12
|
+
*/
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Visual variant of the accordion
|
|
16
|
+
* @default 'light'
|
|
17
|
+
*/
|
|
18
|
+
variant?: AccordionVariant;
|
|
19
|
+
/**
|
|
20
|
+
* Selection behavior mode
|
|
21
|
+
* - toggle: Only one accordion item can be expanded at a time
|
|
22
|
+
* - multiple: Multiple accordion items can be expanded simultaneously
|
|
23
|
+
* @default 'toggle'
|
|
24
|
+
*/
|
|
25
|
+
selectionMode?: AccordionSelectionMode;
|
|
26
|
+
/**
|
|
27
|
+
* Show dividers between accordion items
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
showDivider?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Hide the collapse/expand indicator
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
hideIndicator?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the accordion should take full width
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
fullWidth?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Controlled expanded keys
|
|
43
|
+
*/
|
|
44
|
+
expandedKeys?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Default expanded keys for uncontrolled mode
|
|
47
|
+
* Items with these keys will be expanded by default
|
|
48
|
+
*/
|
|
49
|
+
defaultExpandedKeys?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Keys of disabled accordion items
|
|
52
|
+
*/
|
|
53
|
+
disabledKeys?: string[];
|
|
54
|
+
/**
|
|
55
|
+
* Disable animations
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
disableAnimation?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Make the accordion items more compact
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
isCompact?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Custom styles for the container
|
|
66
|
+
*/
|
|
67
|
+
containerStyle?: ViewStyle;
|
|
68
|
+
/**
|
|
69
|
+
* Custom styles for individual items
|
|
70
|
+
*/
|
|
71
|
+
itemStyle?: ViewStyle;
|
|
72
|
+
} & AccordionEvents;
|
|
73
|
+
|
|
74
|
+
declare const Accordion: React.FC<AccordionProps>;
|
|
75
|
+
|
|
76
|
+
type AccordionItemEvents = {
|
|
77
|
+
onSelected?: (isSelected: boolean) => void;
|
|
78
|
+
};
|
|
79
|
+
type AccordionItemProps = {
|
|
80
|
+
/**
|
|
81
|
+
* Unique key for the accordion item
|
|
82
|
+
*/
|
|
83
|
+
itemKey?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Content to display when accordion item is expanded
|
|
86
|
+
*/
|
|
87
|
+
children: ReactNode;
|
|
88
|
+
/**
|
|
89
|
+
* Title displayed in the accordion header
|
|
90
|
+
*/
|
|
91
|
+
title: ReactNode;
|
|
92
|
+
/**
|
|
93
|
+
* Optional subtitle displayed below the title
|
|
94
|
+
*/
|
|
95
|
+
subtitle?: ReactNode;
|
|
96
|
+
/**
|
|
97
|
+
* Content displayed at the start of the header (left side)
|
|
98
|
+
*/
|
|
99
|
+
startContent?: ReactNode;
|
|
100
|
+
/**
|
|
101
|
+
* Custom indicator for the expanded/collapsed state
|
|
102
|
+
* @default ChevronRight icon
|
|
103
|
+
*/
|
|
104
|
+
indicator?: ReactNode;
|
|
105
|
+
/**
|
|
106
|
+
* Custom styles for the base container
|
|
107
|
+
*/
|
|
108
|
+
baseStyle?: ViewStyle;
|
|
109
|
+
/**
|
|
110
|
+
* Custom styles for the header container
|
|
111
|
+
*/
|
|
112
|
+
headingStyle?: ViewStyle;
|
|
113
|
+
/**
|
|
114
|
+
* Custom styles for the trigger button
|
|
115
|
+
*/
|
|
116
|
+
triggerStyle?: ViewStyle;
|
|
117
|
+
/**
|
|
118
|
+
* Custom styles for the title text
|
|
119
|
+
*/
|
|
120
|
+
titleStyle?: TextStyle;
|
|
121
|
+
/**
|
|
122
|
+
* Custom styles for the subtitle text
|
|
123
|
+
*/
|
|
124
|
+
subtitleStyle?: TextStyle;
|
|
125
|
+
/**
|
|
126
|
+
* Custom styles for the content container
|
|
127
|
+
*/
|
|
128
|
+
contentStyle?: ViewStyle;
|
|
129
|
+
/**
|
|
130
|
+
* Custom styles for the start content container
|
|
131
|
+
*/
|
|
132
|
+
startContentStyle?: ViewStyle;
|
|
133
|
+
/**
|
|
134
|
+
* Custom styles for the indicator
|
|
135
|
+
*/
|
|
136
|
+
indicatorStyle?: ViewStyle;
|
|
137
|
+
} & AccordionItemEvents;
|
|
138
|
+
|
|
139
|
+
declare const AccordionItem: React.FC<AccordionItemProps>;
|
|
140
|
+
|
|
141
|
+
export { Accordion, AccordionItem, type AccordionItemProps, type AccordionProps, type AccordionSelectionMode, type AccordionVariant };
|