@xaui/native 0.0.16 → 0.0.17

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.
Files changed (59) hide show
  1. package/dist/accordion/index.cjs +1 -1
  2. package/dist/accordion/index.js +5 -4
  3. package/dist/alert/index.js +3 -2
  4. package/dist/autocomplete/index.cjs +5 -11
  5. package/dist/autocomplete/index.js +3 -2
  6. package/dist/avatar/index.js +3 -2
  7. package/dist/badge/index.js +3 -2
  8. package/dist/bottom-sheet/index.cjs +9 -20
  9. package/dist/bottom-sheet/index.js +3 -2
  10. package/dist/button/index.js +3 -2
  11. package/dist/carousel/index.cjs +458 -0
  12. package/dist/carousel/index.d.cts +147 -0
  13. package/dist/carousel/index.d.ts +147 -0
  14. package/dist/carousel/index.js +7 -0
  15. package/dist/checkbox/index.js +2 -1
  16. package/dist/chip/index.cjs +2 -8
  17. package/dist/chip/index.js +3 -2
  18. package/dist/{chunk-QLEQYKG5.js → chunk-6PXMB5CH.js} +3 -9
  19. package/dist/{chunk-EI5OMBFE.js → chunk-DBKVHMSA.js} +6 -15
  20. package/dist/chunk-DXXNBF5P.js +7 -0
  21. package/dist/chunk-EW5YLICE.js +382 -0
  22. package/dist/{chunk-7OFTYKK4.js → chunk-JJOVGRNI.js} +1 -1
  23. package/dist/{chunk-4LFRYVSR.js → chunk-K2HSVISE.js} +1 -1
  24. package/dist/{chunk-NBRASCX4.js → chunk-MZL77KV5.js} +5 -12
  25. package/dist/{chunk-2T6FKPJW.js → chunk-OXVIVNIJ.js} +1 -1
  26. package/dist/{chunk-ZYTBRHLJ.js → chunk-PWCUULAL.js} +1 -1
  27. package/dist/{chunk-GNJIET26.js → chunk-RIVFFZRO.js} +1 -1
  28. package/dist/{chunk-GAOI4KIV.js → chunk-S3MGBM3G.js} +10 -21
  29. package/dist/chunk-STUNTRKJ.js +405 -0
  30. package/dist/{chunk-II4QINLG.js → chunk-TJ2FPLLZ.js} +2 -2
  31. package/dist/{chunk-XJKA22BK.js → chunk-UGDGCMGC.js} +1 -1
  32. package/dist/{chunk-MKHBEJLO.js → chunk-VUVE6PK7.js} +1 -1
  33. package/dist/{chunk-NMZUPH3R.js → chunk-XUYIAA3A.js} +3 -9
  34. package/dist/core/index.js +5 -3
  35. package/dist/datepicker/index.js +3 -2
  36. package/dist/divider/index.js +3 -2
  37. package/dist/fab/index.js +4 -3
  38. package/dist/fab-menu/index.cjs +4 -13
  39. package/dist/fab-menu/index.js +5 -4
  40. package/dist/index.cjs +994 -257
  41. package/dist/index.d.cts +2 -0
  42. package/dist/index.d.ts +2 -0
  43. package/dist/index.js +24 -13
  44. package/dist/indicator/index.js +3 -2
  45. package/dist/menu/index.cjs +8 -7
  46. package/dist/menu/index.js +15 -9
  47. package/dist/progress/index.js +2 -1
  48. package/dist/segment-button/index.cjs +492 -0
  49. package/dist/segment-button/index.d.cts +141 -0
  50. package/dist/segment-button/index.d.ts +141 -0
  51. package/dist/segment-button/index.js +10 -0
  52. package/dist/select/index.js +2 -1
  53. package/dist/switch/index.js +2 -1
  54. package/dist/typography/index.js +3 -2
  55. package/dist/view/index.cjs +153 -78
  56. package/dist/view/index.d.cts +77 -1
  57. package/dist/view/index.d.ts +77 -1
  58. package/dist/view/index.js +125 -52
  59. package/package.json +11 -1
@@ -0,0 +1,382 @@
1
+ import {
2
+ useBorderRadiusStyles
3
+ } from "./chunk-MZL77KV5.js";
4
+
5
+ // src/components/carousel/carousel.tsx
6
+ import React3, { useState, useRef, useCallback, useEffect } from "react";
7
+ import { View as View2 } from "react-native";
8
+ import Animated2, {
9
+ useAnimatedScrollHandler,
10
+ useSharedValue,
11
+ useAnimatedRef
12
+ } from "react-native-reanimated";
13
+
14
+ // src/components/carousel/carousel.style.ts
15
+ import { StyleSheet } from "react-native";
16
+ var styles = StyleSheet.create({
17
+ scrollContent: {
18
+ flexDirection: "row",
19
+ alignItems: "center"
20
+ },
21
+ item: {
22
+ overflow: "hidden"
23
+ },
24
+ indicatorContainer: {
25
+ flexDirection: "row",
26
+ justifyContent: "center",
27
+ alignItems: "center",
28
+ paddingVertical: 12,
29
+ gap: 8
30
+ },
31
+ indicator: {
32
+ width: 8,
33
+ height: 8,
34
+ borderRadius: 4,
35
+ backgroundColor: "#CAC4D0"
36
+ },
37
+ activeIndicator: {
38
+ width: 24,
39
+ borderRadius: 4,
40
+ backgroundColor: "#49454F"
41
+ }
42
+ });
43
+
44
+ // src/components/carousel/carousel.hook.ts
45
+ import { useMemo } from "react";
46
+ var HERO_PEEK_WIDTH = 56;
47
+ function computeMultiBrowseLayout(config) {
48
+ const { preferredItemWidth, itemSpacing } = config;
49
+ return {
50
+ computedItemWidth: preferredItemWidth,
51
+ snapInterval: preferredItemWidth + itemSpacing,
52
+ pagingEnabled: false
53
+ };
54
+ }
55
+ function computeUncontainedLayout(config) {
56
+ const { preferredItemWidth, itemSpacing } = config;
57
+ return {
58
+ computedItemWidth: preferredItemWidth,
59
+ snapInterval: preferredItemWidth + itemSpacing,
60
+ pagingEnabled: false
61
+ };
62
+ }
63
+ function computeHeroLayout(config) {
64
+ const { containerWidth, contentPadding, itemSpacing } = config;
65
+ const availableWidth = containerWidth - 2 * contentPadding;
66
+ const largeItemWidth = availableWidth - HERO_PEEK_WIDTH - itemSpacing;
67
+ return {
68
+ computedItemWidth: Math.max(largeItemWidth, 0),
69
+ snapInterval: Math.max(largeItemWidth + itemSpacing, 1),
70
+ pagingEnabled: false
71
+ };
72
+ }
73
+ function computeFullScreenLayout(config) {
74
+ const { containerWidth } = config;
75
+ return {
76
+ computedItemWidth: containerWidth,
77
+ snapInterval: containerWidth,
78
+ pagingEnabled: true
79
+ };
80
+ }
81
+ function useCarouselLayout(config) {
82
+ return useMemo(() => {
83
+ const layoutMap = {
84
+ "multi-browse": computeMultiBrowseLayout,
85
+ uncontained: computeUncontainedLayout,
86
+ hero: computeHeroLayout,
87
+ "full-screen": computeFullScreenLayout
88
+ };
89
+ const compute = layoutMap[config.layout] ?? computeMultiBrowseLayout;
90
+ return compute(config);
91
+ }, [
92
+ config.layout,
93
+ config.containerWidth,
94
+ config.preferredItemWidth,
95
+ config.itemSpacing,
96
+ config.contentPadding
97
+ ]);
98
+ }
99
+
100
+ // src/components/carousel/carousel-item.tsx
101
+ import React from "react";
102
+ import { View } from "react-native";
103
+ var CarouselItem = ({
104
+ children,
105
+ width,
106
+ height,
107
+ radius,
108
+ spacing,
109
+ isLast,
110
+ customStyle
111
+ }) => /* @__PURE__ */ React.createElement(
112
+ View,
113
+ {
114
+ style: [
115
+ styles.item,
116
+ {
117
+ width,
118
+ height,
119
+ borderRadius: radius,
120
+ marginRight: isLast ? 0 : spacing
121
+ },
122
+ customStyle
123
+ ]
124
+ },
125
+ children
126
+ );
127
+
128
+ // src/components/carousel/animated-carousel-item.tsx
129
+ import React2 from "react";
130
+ import Animated, {
131
+ useAnimatedStyle,
132
+ interpolate,
133
+ Extrapolation
134
+ } from "react-native-reanimated";
135
+ var AnimatedCarouselItem = ({
136
+ children,
137
+ index,
138
+ scrollX,
139
+ width,
140
+ height,
141
+ radius,
142
+ spacing,
143
+ isLast,
144
+ customStyle,
145
+ layout,
146
+ snapInterval,
147
+ containerWidth,
148
+ contentPadding
149
+ }) => {
150
+ const animatedStyle = useAnimatedStyle(() => {
151
+ const inputRange = [
152
+ (index - 1) * snapInterval,
153
+ index * snapInterval,
154
+ (index + 1) * snapInterval
155
+ ];
156
+ if (layout === "multi-browse") {
157
+ const scale = interpolate(
158
+ scrollX.value,
159
+ inputRange,
160
+ [0.85, 1, 0.85],
161
+ Extrapolation.CLAMP
162
+ );
163
+ const opacity = interpolate(
164
+ scrollX.value,
165
+ inputRange,
166
+ [0.6, 1, 0.6],
167
+ Extrapolation.CLAMP
168
+ );
169
+ return {
170
+ transform: [{ scale }],
171
+ opacity
172
+ };
173
+ }
174
+ if (layout === "hero") {
175
+ const centerOffset = containerWidth / 2 - contentPadding - width / 2;
176
+ const itemPosition = index * snapInterval + contentPadding;
177
+ const inputRangeHero = [
178
+ itemPosition - centerOffset - snapInterval,
179
+ itemPosition - centerOffset,
180
+ itemPosition - centerOffset + snapInterval
181
+ ];
182
+ const scale = interpolate(
183
+ scrollX.value,
184
+ inputRangeHero,
185
+ [0.9, 1, 0.9],
186
+ Extrapolation.CLAMP
187
+ );
188
+ const opacity = interpolate(
189
+ scrollX.value,
190
+ inputRangeHero,
191
+ [0.5, 1, 0.5],
192
+ Extrapolation.CLAMP
193
+ );
194
+ const translateX = interpolate(
195
+ scrollX.value,
196
+ inputRangeHero,
197
+ [-10, 0, 10],
198
+ Extrapolation.CLAMP
199
+ );
200
+ return {
201
+ transform: [{ scale }, { translateX }],
202
+ opacity
203
+ };
204
+ }
205
+ return {};
206
+ }, [index, snapInterval, layout, containerWidth, contentPadding, width]);
207
+ return /* @__PURE__ */ React2.createElement(
208
+ Animated.View,
209
+ {
210
+ style: [
211
+ styles.item,
212
+ {
213
+ width,
214
+ height,
215
+ borderRadius: radius,
216
+ marginRight: isLast ? 0 : spacing
217
+ },
218
+ customStyle,
219
+ animatedStyle
220
+ ]
221
+ },
222
+ children
223
+ );
224
+ };
225
+
226
+ // src/components/carousel/carousel.tsx
227
+ var DEFAULT_ITEM_WIDTH = 196;
228
+ var DEFAULT_ITEM_HEIGHT = 205;
229
+ var DEFAULT_ITEM_SPACING = 8;
230
+ var DEFAULT_ITEM_SPACING_MULTI_BROWSE = 4;
231
+ var DEFAULT_CONTENT_PADDING = 16;
232
+ var DEFAULT_AUTO_PLAY_INTERVAL = 3e3;
233
+ function Carousel({
234
+ data,
235
+ renderItem,
236
+ keyExtractor,
237
+ layout = "multi-browse",
238
+ itemWidth = DEFAULT_ITEM_WIDTH,
239
+ itemHeight = DEFAULT_ITEM_HEIGHT,
240
+ itemSpacing,
241
+ contentPadding = DEFAULT_CONTENT_PADDING,
242
+ radius = "lg",
243
+ showIndicator = false,
244
+ autoPlay = false,
245
+ autoPlayInterval = DEFAULT_AUTO_PLAY_INTERVAL,
246
+ initialIndex = 0,
247
+ onActiveItemChange,
248
+ customAppearance
249
+ }) {
250
+ const [containerWidth, setContainerWidth] = useState(0);
251
+ const [activeIndex, setActiveIndex] = useState(initialIndex);
252
+ const scrollRef = useAnimatedRef();
253
+ const onActiveItemChangeRef = useRef(onActiveItemChange);
254
+ onActiveItemChangeRef.current = onActiveItemChange;
255
+ const scrollX = useSharedValue(0);
256
+ const { borderRadius } = useBorderRadiusStyles(radius);
257
+ const defaultSpacing = layout === "multi-browse" ? DEFAULT_ITEM_SPACING_MULTI_BROWSE : DEFAULT_ITEM_SPACING;
258
+ const resolvedSpacing = itemSpacing ?? defaultSpacing;
259
+ const isFullScreen = layout === "full-screen";
260
+ const effectivePadding = isFullScreen ? 0 : contentPadding;
261
+ const effectiveSpacing = isFullScreen ? 0 : resolvedSpacing;
262
+ const { computedItemWidth, snapInterval, pagingEnabled } = useCarouselLayout({
263
+ layout,
264
+ containerWidth,
265
+ preferredItemWidth: itemWidth,
266
+ itemSpacing: effectiveSpacing,
267
+ contentPadding: effectivePadding
268
+ });
269
+ const handleLayout = useCallback((event) => {
270
+ setContainerWidth(event.nativeEvent.layout.width);
271
+ }, []);
272
+ const scrollHandler = useAnimatedScrollHandler({
273
+ onScroll: (event) => {
274
+ scrollX.value = event.contentOffset.x;
275
+ }
276
+ });
277
+ const handleMomentumScrollEnd = useCallback(
278
+ (event) => {
279
+ if (snapInterval <= 0) return;
280
+ const offsetX = event.nativeEvent.contentOffset.x;
281
+ const newIndex = Math.round(offsetX / snapInterval);
282
+ const clampedIndex = Math.max(0, Math.min(newIndex, data.length - 1));
283
+ setActiveIndex(clampedIndex);
284
+ onActiveItemChangeRef.current?.(clampedIndex);
285
+ },
286
+ [snapInterval, data.length]
287
+ );
288
+ useEffect(() => {
289
+ if (!autoPlay || data.length <= 1) return;
290
+ if (containerWidth <= 0 || snapInterval <= 0) return;
291
+ const timer = setInterval(() => {
292
+ setActiveIndex((prev) => {
293
+ const nextIndex = (prev + 1) % data.length;
294
+ scrollRef.current?.scrollTo({ x: nextIndex * snapInterval, animated: true });
295
+ onActiveItemChangeRef.current?.(nextIndex);
296
+ return nextIndex;
297
+ });
298
+ }, autoPlayInterval);
299
+ return () => clearInterval(timer);
300
+ }, [autoPlay, autoPlayInterval, data.length, snapInterval, containerWidth]);
301
+ if (containerWidth <= 0) {
302
+ return /* @__PURE__ */ React3.createElement(View2, { style: customAppearance?.container, onLayout: handleLayout });
303
+ }
304
+ const shouldAnimate = layout === "multi-browse" || layout === "hero";
305
+ return /* @__PURE__ */ React3.createElement(View2, { style: customAppearance?.container, onLayout: handleLayout }, /* @__PURE__ */ React3.createElement(
306
+ Animated2.ScrollView,
307
+ {
308
+ ref: scrollRef,
309
+ horizontal: true,
310
+ showsHorizontalScrollIndicator: false,
311
+ snapToInterval: pagingEnabled ? void 0 : snapInterval,
312
+ pagingEnabled,
313
+ decelerationRate: "fast",
314
+ contentContainerStyle: [
315
+ styles.scrollContent,
316
+ { paddingHorizontal: effectivePadding }
317
+ ],
318
+ onScroll: scrollHandler,
319
+ scrollEventThrottle: 16,
320
+ onMomentumScrollEnd: handleMomentumScrollEnd,
321
+ contentOffset: { x: initialIndex * snapInterval, y: 0 }
322
+ },
323
+ data.map((item, index) => {
324
+ const content = renderItem({ item, index });
325
+ if (shouldAnimate) {
326
+ return /* @__PURE__ */ React3.createElement(
327
+ AnimatedCarouselItem,
328
+ {
329
+ key: keyExtractor ? keyExtractor(item, index) : String(index),
330
+ index,
331
+ scrollX,
332
+ width: computedItemWidth,
333
+ height: itemHeight,
334
+ radius: borderRadius,
335
+ spacing: effectiveSpacing,
336
+ isLast: index === data.length - 1,
337
+ customStyle: customAppearance?.item,
338
+ layout,
339
+ snapInterval,
340
+ containerWidth,
341
+ contentPadding: effectivePadding
342
+ },
343
+ content
344
+ );
345
+ }
346
+ return /* @__PURE__ */ React3.createElement(
347
+ CarouselItem,
348
+ {
349
+ key: keyExtractor ? keyExtractor(item, index) : String(index),
350
+ width: computedItemWidth,
351
+ height: itemHeight,
352
+ radius: borderRadius,
353
+ spacing: effectiveSpacing,
354
+ isLast: index === data.length - 1,
355
+ customStyle: customAppearance?.item
356
+ },
357
+ content
358
+ );
359
+ })
360
+ ), showIndicator && data.length > 1 && /* @__PURE__ */ React3.createElement(
361
+ View2,
362
+ {
363
+ style: [styles.indicatorContainer, customAppearance?.indicatorContainer]
364
+ },
365
+ data.map((_, index) => /* @__PURE__ */ React3.createElement(
366
+ View2,
367
+ {
368
+ key: `indicator-${String(index)}`,
369
+ style: [
370
+ styles.indicator,
371
+ customAppearance?.indicator,
372
+ activeIndex === index && styles.activeIndicator,
373
+ activeIndex === index && customAppearance?.activeIndicator
374
+ ]
375
+ }
376
+ ))
377
+ ));
378
+ }
379
+
380
+ export {
381
+ Carousel
382
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Portal,
3
3
  useXUITheme
4
- } from "./chunk-NBRASCX4.js";
4
+ } from "./chunk-MZL77KV5.js";
5
5
 
6
6
  // src/components/datepicker/datepicker.tsx
7
7
  import React7, { useCallback as useCallback5, useMemo as useMemo6, useRef as useRef6 } from "react";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useXUITheme
3
- } from "./chunk-NBRASCX4.js";
3
+ } from "./chunk-MZL77KV5.js";
4
4
 
5
5
  // src/components/avatar/avatar.tsx
6
6
  import React from "react";
@@ -1,9 +1,3 @@
1
- // src/core/theme-context.tsx
2
- import React3, { createContext as createContext2 } from "react";
3
- import { useColorScheme } from "react-native";
4
- import { defaultTheme } from "@xaui/core/theme";
5
- import { colors } from "@xaui/core/palette";
6
-
7
1
  // src/core/portal/portal.tsx
8
2
  import { useContext, useEffect, useLayoutEffect, useRef } from "react";
9
3
 
@@ -57,6 +51,10 @@ var PortalHost = ({ children }) => {
57
51
  };
58
52
 
59
53
  // src/core/theme-context.tsx
54
+ import React3, { createContext as createContext2 } from "react";
55
+ import { useColorScheme } from "react-native";
56
+ import { defaultTheme } from "@xaui/core/theme";
57
+ import { colors } from "@xaui/core/palette";
60
58
  var XUIThemeContext = createContext2(null);
61
59
  function XUIProvider({
62
60
  children,
@@ -128,9 +126,6 @@ function useBorderRadiusStyles(radius) {
128
126
  return borderRadius;
129
127
  }
130
128
 
131
- // src/core/index.ts
132
- import { defaultDarkTheme, defaultTheme as defaultTheme2 } from "@xaui/core/theme";
133
-
134
129
  export {
135
130
  Portal,
136
131
  PortalHost,
@@ -139,7 +134,5 @@ export {
139
134
  useXUITheme,
140
135
  useXUIColors,
141
136
  useXUIPalette,
142
- useBorderRadiusStyles,
143
- defaultDarkTheme,
144
- defaultTheme2 as defaultTheme
137
+ useBorderRadiusStyles
145
138
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useBorderRadiusStyles,
3
3
  useXUITheme
4
- } from "./chunk-NBRASCX4.js";
4
+ } from "./chunk-MZL77KV5.js";
5
5
 
6
6
  // src/components/alert/alert.tsx
7
7
  import React2, {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useXUITheme
3
- } from "./chunk-NBRASCX4.js";
3
+ } from "./chunk-MZL77KV5.js";
4
4
 
5
5
  // src/components/typography/typography.tsx
6
6
  import React, { useMemo as useMemo2 } from "react";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useXUITheme
3
- } from "./chunk-NBRASCX4.js";
3
+ } from "./chunk-MZL77KV5.js";
4
4
 
5
5
  // src/components/divider/divider.tsx
6
6
  import React from "react";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Portal,
3
3
  useXUITheme
4
- } from "./chunk-NBRASCX4.js";
4
+ } from "./chunk-MZL77KV5.js";
5
5
 
6
6
  // src/components/bottom-sheet/bottom-sheet.tsx
7
7
  import React from "react";
@@ -151,7 +151,13 @@ var useBottomSheetAnimation = ({
151
151
  snapTranslateValues[clampedIndex]
152
152
  );
153
153
  },
154
- [sortedSnapPoints, snapTranslateValues, disableAnimation, translateY, onSnapChange]
154
+ [
155
+ sortedSnapPoints,
156
+ snapTranslateValues,
157
+ disableAnimation,
158
+ translateY,
159
+ onSnapChange
160
+ ]
155
161
  );
156
162
  useEffect(() => {
157
163
  if (isOpen) {
@@ -326,19 +332,7 @@ var BottomSheet = ({
326
332
  close();
327
333
  }
328
334
  };
329
- return /* @__PURE__ */ React.createElement(Portal, null, showBackdrop && /* @__PURE__ */ React.createElement(
330
- Animated3.View,
331
- {
332
- style: [styles.backdrop, { opacity: backdropOpacity }]
333
- },
334
- /* @__PURE__ */ React.createElement(
335
- Pressable,
336
- {
337
- style: styles.backdrop,
338
- onPress: handleBackdropPress
339
- }
340
- )
341
- ), /* @__PURE__ */ React.createElement(
335
+ return /* @__PURE__ */ React.createElement(Portal, null, showBackdrop && /* @__PURE__ */ React.createElement(Animated3.View, { style: [styles.backdrop, { opacity: backdropOpacity }] }, /* @__PURE__ */ React.createElement(Pressable, { style: styles.backdrop, onPress: handleBackdropPress })), /* @__PURE__ */ React.createElement(
342
336
  Animated3.View,
343
337
  {
344
338
  style: [
@@ -352,12 +346,7 @@ var BottomSheet = ({
352
346
  /* @__PURE__ */ React.createElement(
353
347
  View,
354
348
  {
355
- style: [
356
- styles.sheet,
357
- { height: screenHeight },
358
- sheetStyles,
359
- style
360
- ],
349
+ style: [styles.sheet, { height: screenHeight }, sheetStyles, style],
361
350
  ...panResponder.panHandlers
362
351
  },
363
352
  showHandle && /* @__PURE__ */ React.createElement(View, { style: styles.handle }, handleContent ?? /* @__PURE__ */ React.createElement(