@xaui/native 0.0.27 → 0.0.28
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/LICENSE +21 -0
- package/README.md +105 -228
- package/dist/alert/index.cjs +92 -166
- package/dist/alert/index.js +2 -1
- package/dist/app-bar/index.cjs +24 -98
- package/dist/app-bar/index.js +2 -1
- package/dist/autocomplete/index.cjs +192 -281
- package/dist/autocomplete/index.js +36 -48
- package/dist/avatar/index.cjs +59 -133
- package/dist/avatar/index.js +2 -1
- package/dist/badge/index.cjs +26 -99
- package/dist/badge/index.js +2 -1
- package/dist/bottom-sheet/index.cjs +5 -456
- package/dist/bottom-sheet/index.js +4 -363
- package/dist/bottom-tab-bar/index.cjs +93 -167
- package/dist/bottom-tab-bar/index.js +2 -2
- package/dist/button/index.cjs +73 -525
- package/dist/button/index.js +3 -2
- package/dist/card/index.cjs +76 -169
- package/dist/card/index.js +2 -2
- package/dist/carousel/index.cjs +68 -145
- package/dist/carousel/index.js +1 -1
- package/dist/chart/index.cjs +132 -173
- package/dist/checkbox/index.cjs +70 -143
- package/dist/checkbox/index.js +2 -1
- package/dist/chip/index.cjs +89 -164
- package/dist/chip/index.js +2 -1
- package/dist/chunk-BD72HIPR.cjs +75 -0
- package/dist/chunk-DHSTKO3K.cjs +19 -0
- package/dist/{chunk-CZFDZPAS.js → chunk-DXXNBF5P.js} +5 -0
- package/dist/{chunk-UI5L26KD.js → chunk-F7WH4DMG.js} +1 -1
- package/dist/chunk-GBHQCAKW.js +19 -0
- package/dist/chunk-HC2SSHNU.js +368 -0
- package/dist/chunk-HSPTLUFA.cjs +7 -0
- package/dist/chunk-JEGEPGVU.js +287 -0
- package/dist/chunk-KTLGDLCB.cjs +287 -0
- package/dist/{chunk-GHCVNQET.js → chunk-LTKYHG5V.js} +5 -12
- package/dist/{chunk-ULJSCNPE.js → chunk-LUBWRVI2.js} +1 -1
- package/dist/chunk-OQ2BLOOG.cjs +138 -0
- package/dist/chunk-QMYWIWSX.cjs +384 -0
- package/dist/chunk-XFPPR2VB.cjs +368 -0
- package/dist/core/index.cjs +22 -168
- package/dist/core/index.d.cts +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +5 -3
- package/dist/datepicker/index.cjs +239 -320
- package/dist/datepicker/index.js +2 -1
- package/dist/divider/index.cjs +5 -145
- package/dist/divider/index.js +3 -2
- package/dist/drawer/index.cjs +39 -112
- package/dist/drawer/index.js +2 -1
- package/dist/expansion-panel/index.cjs +91 -230
- package/dist/expansion-panel/index.js +3 -2
- package/dist/fab/index.cjs +6 -722
- package/dist/fab/index.js +4 -3
- package/dist/fab-menu/index.cjs +81 -814
- package/dist/fab-menu/index.js +4 -3
- package/dist/feature-discovery/index.cjs +72 -139
- package/dist/feature-discovery/index.js +2 -2
- package/dist/index.cjs +1 -18
- package/dist/indicator/index.cjs +5 -445
- package/dist/indicator/index.js +3 -2
- package/dist/input/index.cjs +214 -282
- package/dist/input/index.js +2 -2
- package/dist/list/index.cjs +71 -146
- package/dist/list/index.js +2 -1
- package/dist/menu/index.cjs +59 -127
- package/dist/menu/index.js +2 -2
- package/dist/menubox/index.cjs +60 -132
- package/dist/menubox/index.js +2 -1
- package/dist/pager/index.cjs +42 -80
- package/dist/progress/index.cjs +43 -114
- package/dist/progress/index.js +2 -1
- package/dist/radio/index.cjs +82 -154
- package/dist/radio/index.js +2 -1
- package/dist/segment-button/index.cjs +60 -147
- package/dist/segment-button/index.js +2 -2
- package/dist/select/index.cjs +149 -224
- package/dist/select/index.js +10 -22
- package/dist/skeleton/index.cjs +23 -94
- package/dist/skeleton/index.js +2 -2
- package/dist/slider/index.cjs +77 -156
- package/dist/slider/index.js +2 -1
- package/dist/snackbar/index.cjs +420 -0
- package/dist/snackbar/index.d.cts +175 -0
- package/dist/snackbar/index.d.ts +175 -0
- package/dist/snackbar/index.js +420 -0
- package/dist/stepper/index.cjs +121 -195
- package/dist/stepper/index.js +2 -1
- package/dist/switch/index.cjs +48 -121
- package/dist/switch/index.js +2 -1
- package/dist/tabs/index.cjs +67 -151
- package/dist/tabs/index.js +2 -1
- package/dist/timepicker/index.cjs +135 -593
- package/dist/timepicker/index.js +24 -383
- package/dist/toolbar/index.cjs +59 -128
- package/dist/toolbar/index.js +2 -1
- package/dist/typography/index.cjs +37 -92
- package/dist/typography/index.d.cts +1 -1
- package/dist/typography/index.d.ts +1 -1
- package/dist/typography/index.js +20 -1
- package/dist/view/index.cjs +178 -223
- package/package.json +6 -1
- package/dist/chunk-3XSXTM3G.js +0 -661
- package/dist/chunk-4KSZLONZ.js +0 -79
- package/dist/chunk-I4V5Y5GD.js +0 -76
- package/dist/chunk-URBEEDFX.js +0 -79
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Portal,
|
|
3
|
+
useXUITheme
|
|
4
|
+
} from "./chunk-LTKYHG5V.js";
|
|
5
|
+
|
|
6
|
+
// src/components/bottom-sheet/bottom-sheet.tsx
|
|
7
|
+
import React from "react";
|
|
8
|
+
import { Animated as Animated3, Pressable, View } from "react-native";
|
|
9
|
+
|
|
10
|
+
// src/components/bottom-sheet/bottom-sheet.hook.ts
|
|
11
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
12
|
+
import { Animated as Animated2, Dimensions, PanResponder } from "react-native";
|
|
13
|
+
import { getSafeThemeColor } from "@xaui/core";
|
|
14
|
+
|
|
15
|
+
// src/components/bottom-sheet/bottom-sheet.animation.ts
|
|
16
|
+
import { Animated, Easing } from "react-native";
|
|
17
|
+
var SPRING_CONFIG = {
|
|
18
|
+
useNativeDriver: true,
|
|
19
|
+
speed: 14,
|
|
20
|
+
bounciness: 4
|
|
21
|
+
};
|
|
22
|
+
var TIMING_CONFIG = {
|
|
23
|
+
duration: 280,
|
|
24
|
+
easing: Easing.bezier(0.2, 0, 0, 1),
|
|
25
|
+
useNativeDriver: true
|
|
26
|
+
};
|
|
27
|
+
var runOpenAnimation = (translateY, backdropOpacity, targetTranslateY) => {
|
|
28
|
+
const animation = Animated.parallel([
|
|
29
|
+
Animated.spring(translateY, {
|
|
30
|
+
...SPRING_CONFIG,
|
|
31
|
+
toValue: targetTranslateY
|
|
32
|
+
}),
|
|
33
|
+
Animated.timing(backdropOpacity, {
|
|
34
|
+
...TIMING_CONFIG,
|
|
35
|
+
toValue: 1
|
|
36
|
+
})
|
|
37
|
+
]);
|
|
38
|
+
animation.start();
|
|
39
|
+
return animation;
|
|
40
|
+
};
|
|
41
|
+
var runCloseAnimation = (translateY, backdropOpacity, screenHeight, onComplete) => {
|
|
42
|
+
const animation = Animated.parallel([
|
|
43
|
+
Animated.timing(translateY, {
|
|
44
|
+
...TIMING_CONFIG,
|
|
45
|
+
toValue: screenHeight
|
|
46
|
+
}),
|
|
47
|
+
Animated.timing(backdropOpacity, {
|
|
48
|
+
...TIMING_CONFIG,
|
|
49
|
+
toValue: 0
|
|
50
|
+
})
|
|
51
|
+
]);
|
|
52
|
+
animation.start(({ finished }) => {
|
|
53
|
+
if (finished && onComplete) {
|
|
54
|
+
onComplete();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return animation;
|
|
58
|
+
};
|
|
59
|
+
var runSnapAnimation = (translateY, targetTranslateY) => {
|
|
60
|
+
const animation = Animated.spring(translateY, {
|
|
61
|
+
...SPRING_CONFIG,
|
|
62
|
+
toValue: targetTranslateY
|
|
63
|
+
});
|
|
64
|
+
animation.start();
|
|
65
|
+
return animation;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/components/bottom-sheet/bottom-sheet.hook.ts
|
|
69
|
+
var DISMISS_VELOCITY_THRESHOLD = 0.5;
|
|
70
|
+
var DISMISS_DISTANCE_FRACTION = 0.3;
|
|
71
|
+
var SCREEN_HEIGHT = Dimensions.get("window").height;
|
|
72
|
+
var getTranslateYForSnap = (snapFraction) => SCREEN_HEIGHT * (1 - snapFraction);
|
|
73
|
+
var useBottomSheetAnimation = ({
|
|
74
|
+
isOpen,
|
|
75
|
+
snapPoints,
|
|
76
|
+
initialSnapIndex,
|
|
77
|
+
enableSwipeToDismiss,
|
|
78
|
+
disableAnimation,
|
|
79
|
+
onClose,
|
|
80
|
+
onSnapChange
|
|
81
|
+
}) => {
|
|
82
|
+
const [shouldRender, setShouldRender] = useState(false);
|
|
83
|
+
const currentSnapIndex = useRef(initialSnapIndex);
|
|
84
|
+
const animationRef = useRef(null);
|
|
85
|
+
const translateY = useRef(new Animated2.Value(SCREEN_HEIGHT)).current;
|
|
86
|
+
const backdropOpacity = useRef(new Animated2.Value(0)).current;
|
|
87
|
+
const sortedSnapPoints = useMemo(
|
|
88
|
+
() => [...snapPoints].sort((a, b) => a - b),
|
|
89
|
+
[snapPoints]
|
|
90
|
+
);
|
|
91
|
+
const snapTranslateValues = useMemo(
|
|
92
|
+
() => sortedSnapPoints.map(getTranslateYForSnap),
|
|
93
|
+
[sortedSnapPoints]
|
|
94
|
+
);
|
|
95
|
+
const open = useCallback(() => {
|
|
96
|
+
setShouldRender(true);
|
|
97
|
+
const targetIndex = Math.min(initialSnapIndex, sortedSnapPoints.length - 1);
|
|
98
|
+
currentSnapIndex.current = targetIndex;
|
|
99
|
+
if (disableAnimation) {
|
|
100
|
+
translateY.setValue(snapTranslateValues[targetIndex]);
|
|
101
|
+
backdropOpacity.setValue(1);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
translateY.setValue(SCREEN_HEIGHT);
|
|
105
|
+
backdropOpacity.setValue(0);
|
|
106
|
+
animationRef.current?.stop();
|
|
107
|
+
animationRef.current = runOpenAnimation(
|
|
108
|
+
translateY,
|
|
109
|
+
backdropOpacity,
|
|
110
|
+
snapTranslateValues[targetIndex]
|
|
111
|
+
);
|
|
112
|
+
}, [
|
|
113
|
+
initialSnapIndex,
|
|
114
|
+
sortedSnapPoints,
|
|
115
|
+
snapTranslateValues,
|
|
116
|
+
disableAnimation,
|
|
117
|
+
translateY,
|
|
118
|
+
backdropOpacity
|
|
119
|
+
]);
|
|
120
|
+
const close = useCallback(() => {
|
|
121
|
+
if (disableAnimation) {
|
|
122
|
+
translateY.setValue(SCREEN_HEIGHT);
|
|
123
|
+
backdropOpacity.setValue(0);
|
|
124
|
+
setShouldRender(false);
|
|
125
|
+
onClose?.();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
animationRef.current?.stop();
|
|
129
|
+
animationRef.current = runCloseAnimation(
|
|
130
|
+
translateY,
|
|
131
|
+
backdropOpacity,
|
|
132
|
+
SCREEN_HEIGHT,
|
|
133
|
+
() => {
|
|
134
|
+
setShouldRender(false);
|
|
135
|
+
onClose?.();
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
}, [disableAnimation, translateY, backdropOpacity, onClose]);
|
|
139
|
+
const snapTo = useCallback(
|
|
140
|
+
(index) => {
|
|
141
|
+
const clampedIndex = Math.max(0, Math.min(index, sortedSnapPoints.length - 1));
|
|
142
|
+
currentSnapIndex.current = clampedIndex;
|
|
143
|
+
onSnapChange?.(clampedIndex);
|
|
144
|
+
if (disableAnimation) {
|
|
145
|
+
translateY.setValue(snapTranslateValues[clampedIndex]);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
animationRef.current?.stop();
|
|
149
|
+
animationRef.current = runSnapAnimation(
|
|
150
|
+
translateY,
|
|
151
|
+
snapTranslateValues[clampedIndex]
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
[
|
|
155
|
+
sortedSnapPoints,
|
|
156
|
+
snapTranslateValues,
|
|
157
|
+
disableAnimation,
|
|
158
|
+
translateY,
|
|
159
|
+
onSnapChange
|
|
160
|
+
]
|
|
161
|
+
);
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (isOpen) {
|
|
164
|
+
open();
|
|
165
|
+
} else if (shouldRender) {
|
|
166
|
+
close();
|
|
167
|
+
}
|
|
168
|
+
}, [isOpen]);
|
|
169
|
+
const panResponder = useMemo(
|
|
170
|
+
() => PanResponder.create({
|
|
171
|
+
onStartShouldSetPanResponder: () => true,
|
|
172
|
+
onMoveShouldSetPanResponder: (_, gestureState) => Math.abs(gestureState.dy) > 5,
|
|
173
|
+
onPanResponderMove: (_, gestureState) => {
|
|
174
|
+
const currentTranslate = snapTranslateValues[currentSnapIndex.current];
|
|
175
|
+
const newTranslateY = currentTranslate + gestureState.dy;
|
|
176
|
+
const maxExpanded = snapTranslateValues[snapTranslateValues.length - 1];
|
|
177
|
+
const clamped = Math.max(maxExpanded, newTranslateY);
|
|
178
|
+
translateY.setValue(clamped);
|
|
179
|
+
},
|
|
180
|
+
onPanResponderRelease: (_, gestureState) => {
|
|
181
|
+
const currentTranslate = snapTranslateValues[currentSnapIndex.current];
|
|
182
|
+
const finalPosition = currentTranslate + gestureState.dy;
|
|
183
|
+
if (enableSwipeToDismiss && (gestureState.vy > DISMISS_VELOCITY_THRESHOLD || finalPosition > SCREEN_HEIGHT * (1 - sortedSnapPoints[0] * DISMISS_DISTANCE_FRACTION))) {
|
|
184
|
+
close();
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (gestureState.vy < -DISMISS_VELOCITY_THRESHOLD) {
|
|
188
|
+
const nextIndex = Math.min(
|
|
189
|
+
currentSnapIndex.current + 1,
|
|
190
|
+
sortedSnapPoints.length - 1
|
|
191
|
+
);
|
|
192
|
+
snapTo(nextIndex);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (gestureState.vy > DISMISS_VELOCITY_THRESHOLD) {
|
|
196
|
+
const prevIndex = Math.max(currentSnapIndex.current - 1, 0);
|
|
197
|
+
if (prevIndex === currentSnapIndex.current && enableSwipeToDismiss) {
|
|
198
|
+
close();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
snapTo(prevIndex);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
let closestIndex = 0;
|
|
205
|
+
let minDistance = Infinity;
|
|
206
|
+
snapTranslateValues.forEach((snapVal, index) => {
|
|
207
|
+
const distance = Math.abs(finalPosition - snapVal);
|
|
208
|
+
if (distance < minDistance) {
|
|
209
|
+
minDistance = distance;
|
|
210
|
+
closestIndex = index;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
snapTo(closestIndex);
|
|
214
|
+
}
|
|
215
|
+
}),
|
|
216
|
+
[
|
|
217
|
+
snapTranslateValues,
|
|
218
|
+
sortedSnapPoints,
|
|
219
|
+
enableSwipeToDismiss,
|
|
220
|
+
translateY,
|
|
221
|
+
close,
|
|
222
|
+
snapTo
|
|
223
|
+
]
|
|
224
|
+
);
|
|
225
|
+
return {
|
|
226
|
+
shouldRender,
|
|
227
|
+
translateY,
|
|
228
|
+
backdropOpacity,
|
|
229
|
+
panResponder,
|
|
230
|
+
close,
|
|
231
|
+
snapTo,
|
|
232
|
+
screenHeight: SCREEN_HEIGHT
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
var useBottomSheetStyles = (themeColor, radius) => {
|
|
236
|
+
const theme = useXUITheme();
|
|
237
|
+
const safeThemeColor = getSafeThemeColor(themeColor);
|
|
238
|
+
const colorScheme = theme.colors[safeThemeColor];
|
|
239
|
+
const sheetStyles = useMemo(
|
|
240
|
+
() => ({
|
|
241
|
+
backgroundColor: colorScheme.background ?? theme.colors.background ?? "#ffffff",
|
|
242
|
+
borderTopLeftRadius: theme.borderRadius[radius],
|
|
243
|
+
borderTopRightRadius: theme.borderRadius[radius]
|
|
244
|
+
}),
|
|
245
|
+
[theme, colorScheme, radius]
|
|
246
|
+
);
|
|
247
|
+
const handleIndicatorColor = useMemo(
|
|
248
|
+
() => theme.mode === "dark" ? `${colorScheme.main}60` : `${colorScheme.main}40`,
|
|
249
|
+
[theme, colorScheme]
|
|
250
|
+
);
|
|
251
|
+
return { sheetStyles, handleIndicatorColor };
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
// src/components/bottom-sheet/bottom-sheet.style.ts
|
|
255
|
+
import { StyleSheet } from "react-native";
|
|
256
|
+
var styles = StyleSheet.create({
|
|
257
|
+
backdrop: {
|
|
258
|
+
position: "absolute",
|
|
259
|
+
top: 0,
|
|
260
|
+
left: 0,
|
|
261
|
+
right: 0,
|
|
262
|
+
bottom: 0,
|
|
263
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)"
|
|
264
|
+
},
|
|
265
|
+
container: {
|
|
266
|
+
position: "absolute",
|
|
267
|
+
left: 0,
|
|
268
|
+
right: 0,
|
|
269
|
+
bottom: 0
|
|
270
|
+
},
|
|
271
|
+
sheet: {
|
|
272
|
+
overflow: "hidden"
|
|
273
|
+
},
|
|
274
|
+
handle: {
|
|
275
|
+
alignItems: "center",
|
|
276
|
+
justifyContent: "center",
|
|
277
|
+
paddingVertical: 10
|
|
278
|
+
},
|
|
279
|
+
handleIndicator: {
|
|
280
|
+
width: 36,
|
|
281
|
+
height: 4,
|
|
282
|
+
borderRadius: 2
|
|
283
|
+
},
|
|
284
|
+
content: {
|
|
285
|
+
flex: 1
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// src/components/bottom-sheet/bottom-sheet.tsx
|
|
290
|
+
var BottomSheet = ({
|
|
291
|
+
children,
|
|
292
|
+
isOpen,
|
|
293
|
+
snapPoints = [0.4, 0.9],
|
|
294
|
+
initialSnapIndex = 0,
|
|
295
|
+
themeColor = "default",
|
|
296
|
+
radius = "lg",
|
|
297
|
+
showBackdrop = true,
|
|
298
|
+
closeOnBackdropPress = true,
|
|
299
|
+
enableSwipeToDismiss = true,
|
|
300
|
+
showHandle = true,
|
|
301
|
+
disableAnimation = false,
|
|
302
|
+
style,
|
|
303
|
+
handleContent,
|
|
304
|
+
onClose,
|
|
305
|
+
onSnapChange
|
|
306
|
+
}) => {
|
|
307
|
+
const {
|
|
308
|
+
shouldRender,
|
|
309
|
+
translateY,
|
|
310
|
+
backdropOpacity,
|
|
311
|
+
panResponder,
|
|
312
|
+
close,
|
|
313
|
+
screenHeight
|
|
314
|
+
} = useBottomSheetAnimation({
|
|
315
|
+
isOpen,
|
|
316
|
+
snapPoints,
|
|
317
|
+
initialSnapIndex,
|
|
318
|
+
enableSwipeToDismiss,
|
|
319
|
+
disableAnimation,
|
|
320
|
+
onClose,
|
|
321
|
+
onSnapChange
|
|
322
|
+
});
|
|
323
|
+
const { sheetStyles, handleIndicatorColor } = useBottomSheetStyles(
|
|
324
|
+
themeColor,
|
|
325
|
+
radius
|
|
326
|
+
);
|
|
327
|
+
if (!shouldRender) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
const handleBackdropPress = () => {
|
|
331
|
+
if (closeOnBackdropPress) {
|
|
332
|
+
close();
|
|
333
|
+
}
|
|
334
|
+
};
|
|
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(
|
|
336
|
+
Animated3.View,
|
|
337
|
+
{
|
|
338
|
+
style: [
|
|
339
|
+
styles.container,
|
|
340
|
+
{
|
|
341
|
+
height: screenHeight,
|
|
342
|
+
transform: [{ translateY }]
|
|
343
|
+
}
|
|
344
|
+
]
|
|
345
|
+
},
|
|
346
|
+
/* @__PURE__ */ React.createElement(
|
|
347
|
+
View,
|
|
348
|
+
{
|
|
349
|
+
style: [styles.sheet, { height: screenHeight }, sheetStyles, style],
|
|
350
|
+
...panResponder.panHandlers
|
|
351
|
+
},
|
|
352
|
+
showHandle && /* @__PURE__ */ React.createElement(View, { style: styles.handle }, handleContent ?? /* @__PURE__ */ React.createElement(
|
|
353
|
+
View,
|
|
354
|
+
{
|
|
355
|
+
style: [
|
|
356
|
+
styles.handleIndicator,
|
|
357
|
+
{ backgroundColor: handleIndicatorColor }
|
|
358
|
+
]
|
|
359
|
+
}
|
|
360
|
+
)),
|
|
361
|
+
/* @__PURE__ */ React.createElement(View, { style: styles.content }, children)
|
|
362
|
+
)
|
|
363
|
+
));
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
export {
|
|
367
|
+
BottomSheet
|
|
368
|
+
};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ActivityIndicator
|
|
3
|
+
} from "./chunk-F7WH4DMG.js";
|
|
4
|
+
import {
|
|
5
|
+
useXUITheme
|
|
6
|
+
} from "./chunk-LTKYHG5V.js";
|
|
7
|
+
|
|
8
|
+
// src/components/fab/fab.tsx
|
|
9
|
+
import React from "react";
|
|
10
|
+
import { Pressable, Text, View, Animated as Animated2 } from "react-native";
|
|
11
|
+
|
|
12
|
+
// src/components/fab/fab.style.ts
|
|
13
|
+
import { StyleSheet } from "react-native";
|
|
14
|
+
var styles = StyleSheet.create({
|
|
15
|
+
container: {
|
|
16
|
+
alignSelf: "flex-start"
|
|
17
|
+
},
|
|
18
|
+
fab: {
|
|
19
|
+
flexDirection: "row",
|
|
20
|
+
alignItems: "center",
|
|
21
|
+
justifyContent: "center",
|
|
22
|
+
overflow: "hidden"
|
|
23
|
+
},
|
|
24
|
+
contentContainer: {
|
|
25
|
+
flexDirection: "row",
|
|
26
|
+
alignItems: "center",
|
|
27
|
+
justifyContent: "center",
|
|
28
|
+
gap: 12
|
|
29
|
+
},
|
|
30
|
+
label: {
|
|
31
|
+
fontWeight: "500"
|
|
32
|
+
},
|
|
33
|
+
disabled: {
|
|
34
|
+
opacity: 0.5
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// src/components/fab/fab.hook.ts
|
|
39
|
+
import { useMemo } from "react";
|
|
40
|
+
import { getSafeThemeColor } from "@xaui/core";
|
|
41
|
+
function useFabSizeStyles(size) {
|
|
42
|
+
const theme = useXUITheme();
|
|
43
|
+
const sizeStyles = useMemo(() => {
|
|
44
|
+
const sizes = {
|
|
45
|
+
sm: {
|
|
46
|
+
width: 40,
|
|
47
|
+
height: 40,
|
|
48
|
+
borderRadius: theme.borderRadius.lg,
|
|
49
|
+
iconSize: 24,
|
|
50
|
+
fontSize: theme.fontSizes.sm
|
|
51
|
+
},
|
|
52
|
+
md: {
|
|
53
|
+
width: 56,
|
|
54
|
+
height: 56,
|
|
55
|
+
borderRadius: theme.borderRadius.xl,
|
|
56
|
+
iconSize: 24,
|
|
57
|
+
fontSize: theme.fontSizes.md
|
|
58
|
+
},
|
|
59
|
+
lg: {
|
|
60
|
+
width: 96,
|
|
61
|
+
height: 96,
|
|
62
|
+
borderRadius: theme.borderRadius["2xl"],
|
|
63
|
+
iconSize: 36,
|
|
64
|
+
fontSize: theme.fontSizes.lg
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return sizes[size];
|
|
68
|
+
}, [size, theme]);
|
|
69
|
+
const extendedSizeStyles = useMemo(() => {
|
|
70
|
+
const sizes = {
|
|
71
|
+
sm: {
|
|
72
|
+
height: 40,
|
|
73
|
+
borderRadius: theme.borderRadius.lg,
|
|
74
|
+
paddingHorizontal: theme.spacing.md,
|
|
75
|
+
iconSize: 20,
|
|
76
|
+
fontSize: theme.fontSizes.sm
|
|
77
|
+
},
|
|
78
|
+
md: {
|
|
79
|
+
height: 56,
|
|
80
|
+
borderRadius: theme.borderRadius.xl,
|
|
81
|
+
paddingHorizontal: theme.spacing.lg,
|
|
82
|
+
iconSize: 24,
|
|
83
|
+
fontSize: theme.fontSizes.md
|
|
84
|
+
},
|
|
85
|
+
lg: {
|
|
86
|
+
height: 80,
|
|
87
|
+
borderRadius: theme.borderRadius["2xl"],
|
|
88
|
+
paddingHorizontal: theme.spacing.xl,
|
|
89
|
+
iconSize: 28,
|
|
90
|
+
fontSize: theme.fontSizes.lg
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return sizes[size];
|
|
94
|
+
}, [size, theme]);
|
|
95
|
+
return { sizeStyles, extendedSizeStyles };
|
|
96
|
+
}
|
|
97
|
+
function useFabVariantStyles(themeColor, variant, elevation = 0) {
|
|
98
|
+
const theme = useXUITheme();
|
|
99
|
+
const safeThemeColor = getSafeThemeColor(themeColor);
|
|
100
|
+
const colorScheme = theme.colors[safeThemeColor];
|
|
101
|
+
const variantStyles = useMemo(() => {
|
|
102
|
+
const variantMap = {
|
|
103
|
+
solid: {
|
|
104
|
+
backgroundColor: colorScheme.main,
|
|
105
|
+
borderWidth: 0
|
|
106
|
+
},
|
|
107
|
+
flat: {
|
|
108
|
+
backgroundColor: colorScheme.background,
|
|
109
|
+
borderWidth: 0
|
|
110
|
+
},
|
|
111
|
+
outlined: {
|
|
112
|
+
backgroundColor: "transparent",
|
|
113
|
+
borderWidth: theme.borderWidth.md,
|
|
114
|
+
borderColor: colorScheme.main
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const baseStyle = variantMap[variant];
|
|
118
|
+
const shouldApplyElevation = variant !== "outlined";
|
|
119
|
+
const shadowStyles = elevation === 0 ? {} : elevation === 1 ? theme.shadows.sm : elevation === 2 ? theme.shadows.md : elevation === 3 ? theme.shadows.lg : theme.shadows.xl;
|
|
120
|
+
return {
|
|
121
|
+
...baseStyle,
|
|
122
|
+
...shouldApplyElevation ? shadowStyles : {},
|
|
123
|
+
...shouldApplyElevation && elevation > 0 ? { elevation } : {}
|
|
124
|
+
};
|
|
125
|
+
}, [variant, colorScheme, theme, elevation]);
|
|
126
|
+
return variantStyles;
|
|
127
|
+
}
|
|
128
|
+
function useFabIconColor(themeColor, variant) {
|
|
129
|
+
const theme = useXUITheme();
|
|
130
|
+
const safeThemeColor = getSafeThemeColor(themeColor);
|
|
131
|
+
const colorScheme = theme.colors[safeThemeColor];
|
|
132
|
+
const iconColor = useMemo(() => {
|
|
133
|
+
if (variant === "solid") {
|
|
134
|
+
return colorScheme.foreground;
|
|
135
|
+
}
|
|
136
|
+
return colorScheme.main;
|
|
137
|
+
}, [variant, colorScheme]);
|
|
138
|
+
return { iconColor };
|
|
139
|
+
}
|
|
140
|
+
function useFabRadiusValue(radius, fallback) {
|
|
141
|
+
const theme = useXUITheme();
|
|
142
|
+
return useMemo(() => {
|
|
143
|
+
if (!radius) return fallback;
|
|
144
|
+
const radiusMap = {
|
|
145
|
+
none: theme.borderRadius.none,
|
|
146
|
+
sm: theme.borderRadius.sm,
|
|
147
|
+
md: theme.borderRadius.md,
|
|
148
|
+
lg: theme.borderRadius.lg,
|
|
149
|
+
full: theme.borderRadius.full
|
|
150
|
+
};
|
|
151
|
+
return radiusMap[radius];
|
|
152
|
+
}, [fallback, radius, theme]);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/components/fab/fab.animation.ts
|
|
156
|
+
import { Animated } from "react-native";
|
|
157
|
+
var runFabPressInAnimation = (animatedScale, animatedOpacity) => {
|
|
158
|
+
Animated.parallel([
|
|
159
|
+
Animated.spring(animatedScale, {
|
|
160
|
+
toValue: 0.92,
|
|
161
|
+
useNativeDriver: true,
|
|
162
|
+
speed: 50,
|
|
163
|
+
bounciness: 0
|
|
164
|
+
}),
|
|
165
|
+
Animated.timing(animatedOpacity, {
|
|
166
|
+
toValue: 0.85,
|
|
167
|
+
duration: 100,
|
|
168
|
+
useNativeDriver: true
|
|
169
|
+
})
|
|
170
|
+
]).start();
|
|
171
|
+
};
|
|
172
|
+
var runFabPressOutAnimation = (animatedScale, animatedOpacity) => {
|
|
173
|
+
Animated.parallel([
|
|
174
|
+
Animated.spring(animatedScale, {
|
|
175
|
+
toValue: 1,
|
|
176
|
+
useNativeDriver: true,
|
|
177
|
+
speed: 50,
|
|
178
|
+
bounciness: 0
|
|
179
|
+
}),
|
|
180
|
+
Animated.timing(animatedOpacity, {
|
|
181
|
+
toValue: 1,
|
|
182
|
+
duration: 100,
|
|
183
|
+
useNativeDriver: true
|
|
184
|
+
})
|
|
185
|
+
]).start();
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// src/components/fab/fab.tsx
|
|
189
|
+
var Fab = ({
|
|
190
|
+
icon,
|
|
191
|
+
label,
|
|
192
|
+
themeColor = "primary",
|
|
193
|
+
variant = "solid",
|
|
194
|
+
size = "md",
|
|
195
|
+
radius,
|
|
196
|
+
isDisabled = false,
|
|
197
|
+
isLoading = false,
|
|
198
|
+
elevation = 0,
|
|
199
|
+
customAppearance,
|
|
200
|
+
onPress,
|
|
201
|
+
onLongPress,
|
|
202
|
+
onPressIn,
|
|
203
|
+
onPressOut
|
|
204
|
+
}) => {
|
|
205
|
+
const animatedScale = React.useRef(new Animated2.Value(1)).current;
|
|
206
|
+
const animatedOpacity = React.useRef(new Animated2.Value(1)).current;
|
|
207
|
+
const { sizeStyles, extendedSizeStyles } = useFabSizeStyles(size);
|
|
208
|
+
const variantStyles = useFabVariantStyles(themeColor, variant, elevation);
|
|
209
|
+
const { iconColor } = useFabIconColor(themeColor, variant);
|
|
210
|
+
const isExtended = !!label;
|
|
211
|
+
const resolvedRadius = useFabRadiusValue(
|
|
212
|
+
radius,
|
|
213
|
+
isExtended ? extendedSizeStyles.borderRadius : sizeStyles.borderRadius
|
|
214
|
+
);
|
|
215
|
+
const handlePressIn = (event) => {
|
|
216
|
+
if (!isDisabled && !isLoading) {
|
|
217
|
+
runFabPressInAnimation(animatedScale, animatedOpacity);
|
|
218
|
+
}
|
|
219
|
+
onPressIn?.(event);
|
|
220
|
+
};
|
|
221
|
+
const handlePressOut = (event) => {
|
|
222
|
+
if (!isDisabled && !isLoading) {
|
|
223
|
+
runFabPressOutAnimation(animatedScale, animatedOpacity);
|
|
224
|
+
}
|
|
225
|
+
onPressOut?.(event);
|
|
226
|
+
};
|
|
227
|
+
const fabDimensionStyles = isExtended ? {
|
|
228
|
+
height: extendedSizeStyles.height,
|
|
229
|
+
borderRadius: resolvedRadius,
|
|
230
|
+
paddingHorizontal: extendedSizeStyles.paddingHorizontal
|
|
231
|
+
} : {
|
|
232
|
+
width: sizeStyles.width,
|
|
233
|
+
height: sizeStyles.height,
|
|
234
|
+
borderRadius: resolvedRadius
|
|
235
|
+
};
|
|
236
|
+
return /* @__PURE__ */ React.createElement(View, { style: [styles.container, customAppearance?.container] }, /* @__PURE__ */ React.createElement(
|
|
237
|
+
Pressable,
|
|
238
|
+
{
|
|
239
|
+
onPress: isDisabled || isLoading ? void 0 : onPress,
|
|
240
|
+
onLongPress: isDisabled || isLoading ? void 0 : onLongPress,
|
|
241
|
+
onPressIn: handlePressIn,
|
|
242
|
+
onPressOut: handlePressOut,
|
|
243
|
+
disabled: isDisabled || isLoading
|
|
244
|
+
},
|
|
245
|
+
/* @__PURE__ */ React.createElement(
|
|
246
|
+
Animated2.View,
|
|
247
|
+
{
|
|
248
|
+
style: [
|
|
249
|
+
styles.fab,
|
|
250
|
+
fabDimensionStyles,
|
|
251
|
+
variantStyles,
|
|
252
|
+
isDisabled && styles.disabled,
|
|
253
|
+
{
|
|
254
|
+
transform: [{ scale: animatedScale }],
|
|
255
|
+
opacity: animatedOpacity
|
|
256
|
+
},
|
|
257
|
+
customAppearance?.fab
|
|
258
|
+
]
|
|
259
|
+
},
|
|
260
|
+
isLoading ? /* @__PURE__ */ React.createElement(
|
|
261
|
+
ActivityIndicator,
|
|
262
|
+
{
|
|
263
|
+
variant: "circular",
|
|
264
|
+
themeColor: variant === "solid" ? void 0 : themeColor,
|
|
265
|
+
color: variant === "solid" ? iconColor : void 0,
|
|
266
|
+
size: isExtended ? extendedSizeStyles.iconSize : sizeStyles.iconSize
|
|
267
|
+
}
|
|
268
|
+
) : /* @__PURE__ */ React.createElement(View, { style: styles.contentContainer }, icon, isExtended && /* @__PURE__ */ React.createElement(
|
|
269
|
+
Text,
|
|
270
|
+
{
|
|
271
|
+
style: [
|
|
272
|
+
styles.label,
|
|
273
|
+
{
|
|
274
|
+
fontSize: isExtended ? extendedSizeStyles.fontSize : sizeStyles.fontSize,
|
|
275
|
+
color: iconColor
|
|
276
|
+
}
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
label
|
|
280
|
+
))
|
|
281
|
+
)
|
|
282
|
+
));
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
export {
|
|
286
|
+
Fab
|
|
287
|
+
};
|