rnnovaui 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/Card/UICard.js +931 -0
- package/src/components/Card/index.js +6 -0
- package/src/components/index.js +6 -0
- package/src/index.js +4 -0
package/package.json
CHANGED
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import React, { memo, useCallback, useMemo, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ActivityIndicator,
|
|
5
|
+
Animated,
|
|
6
|
+
Easing,
|
|
7
|
+
Image,
|
|
8
|
+
Pressable,
|
|
9
|
+
StyleSheet,
|
|
10
|
+
Text,
|
|
11
|
+
View,
|
|
12
|
+
} from "react-native";
|
|
13
|
+
|
|
14
|
+
import { useUITheme } from "../../theme";
|
|
15
|
+
|
|
16
|
+
const CARD_VARIANTS = {
|
|
17
|
+
default: "default",
|
|
18
|
+
elevated: "elevated",
|
|
19
|
+
outlined: "outlined",
|
|
20
|
+
filled: "filled",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const CARD_RADIUS = {
|
|
24
|
+
none: "none",
|
|
25
|
+
sm: "sm",
|
|
26
|
+
md: "md",
|
|
27
|
+
lg: "lg",
|
|
28
|
+
xl: "xl",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const BADGE_POSITIONS = {
|
|
32
|
+
topLeft: "topLeft",
|
|
33
|
+
topCenter: "topCenter",
|
|
34
|
+
topRight: "topRight",
|
|
35
|
+
|
|
36
|
+
centerLeft: "centerLeft",
|
|
37
|
+
center: "center",
|
|
38
|
+
centerRight: "centerRight",
|
|
39
|
+
|
|
40
|
+
bottomLeft: "bottomLeft",
|
|
41
|
+
bottomCenter: "bottomCenter",
|
|
42
|
+
bottomRight: "bottomRight",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const FALLBACK_COLORS = {
|
|
46
|
+
card: "#FFFFFF",
|
|
47
|
+
surface: "#F8F8F8",
|
|
48
|
+
border: "#E5E5E5",
|
|
49
|
+
|
|
50
|
+
primary: "#FF5A1F",
|
|
51
|
+
primarySoft: "#FFF0EA",
|
|
52
|
+
|
|
53
|
+
success: "#16A34A",
|
|
54
|
+
danger: "#DC2626",
|
|
55
|
+
warning: "#D97706",
|
|
56
|
+
info: "#2563EB",
|
|
57
|
+
|
|
58
|
+
white: "#FFFFFF",
|
|
59
|
+
black: "#111111",
|
|
60
|
+
|
|
61
|
+
text: "#111111",
|
|
62
|
+
textSecondary: "#525252",
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
function UICardComponent({
|
|
66
|
+
children,
|
|
67
|
+
|
|
68
|
+
header = null,
|
|
69
|
+
content = null,
|
|
70
|
+
footer = null,
|
|
71
|
+
|
|
72
|
+
image = null,
|
|
73
|
+
imageSource = null,
|
|
74
|
+
|
|
75
|
+
imageHeight = 190,
|
|
76
|
+
imageResizeMode = "cover",
|
|
77
|
+
|
|
78
|
+
imageStyle,
|
|
79
|
+
|
|
80
|
+
badges = [],
|
|
81
|
+
|
|
82
|
+
badgeGap = 8,
|
|
83
|
+
|
|
84
|
+
badgeStyle,
|
|
85
|
+
|
|
86
|
+
badgeTextStyle,
|
|
87
|
+
|
|
88
|
+
badgeContainerStyle,
|
|
89
|
+
|
|
90
|
+
variant = "default",
|
|
91
|
+
|
|
92
|
+
radius = "lg",
|
|
93
|
+
|
|
94
|
+
padding = 16,
|
|
95
|
+
|
|
96
|
+
gap = 12,
|
|
97
|
+
|
|
98
|
+
style,
|
|
99
|
+
|
|
100
|
+
headerStyle,
|
|
101
|
+
contentStyle,
|
|
102
|
+
footerStyle,
|
|
103
|
+
|
|
104
|
+
imageOverlay = null,
|
|
105
|
+
|
|
106
|
+
imageOverlayStyle,
|
|
107
|
+
|
|
108
|
+
pressable = false,
|
|
109
|
+
|
|
110
|
+
disabled = false,
|
|
111
|
+
|
|
112
|
+
loading = false,
|
|
113
|
+
|
|
114
|
+
onPress,
|
|
115
|
+
onLongPress,
|
|
116
|
+
onPressIn,
|
|
117
|
+
onPressOut,
|
|
118
|
+
|
|
119
|
+
pressAnimation = true,
|
|
120
|
+
|
|
121
|
+
pressScale = 0.985,
|
|
122
|
+
|
|
123
|
+
pressAnimationDuration = 120,
|
|
124
|
+
|
|
125
|
+
testID,
|
|
126
|
+
|
|
127
|
+
accessibilityLabel,
|
|
128
|
+
accessibilityHint,
|
|
129
|
+
|
|
130
|
+
...props
|
|
131
|
+
}) {
|
|
132
|
+
const { theme } = useUITheme();
|
|
133
|
+
|
|
134
|
+
const colors = theme?.colors || {};
|
|
135
|
+
|
|
136
|
+
const scale = useRef(new Animated.Value(1)).current;
|
|
137
|
+
|
|
138
|
+
const animationRef = useRef(null);
|
|
139
|
+
|
|
140
|
+
const isDisabled = disabled || loading;
|
|
141
|
+
|
|
142
|
+
const safeVariant = CARD_VARIANTS[variant] ? variant : CARD_VARIANTS.default;
|
|
143
|
+
|
|
144
|
+
const resolvedRadius = CARD_RADIUS[radius] ? radius : CARD_RADIUS.lg;
|
|
145
|
+
|
|
146
|
+
const radiusValue = getRadiusValue(resolvedRadius, theme);
|
|
147
|
+
|
|
148
|
+
const cardColors = useMemo(
|
|
149
|
+
() => getCardColors(safeVariant, colors),
|
|
150
|
+
[safeVariant, colors],
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const stopAnimation = useCallback(() => {
|
|
154
|
+
if (animationRef.current) {
|
|
155
|
+
animationRef.current.stop();
|
|
156
|
+
|
|
157
|
+
animationRef.current = null;
|
|
158
|
+
}
|
|
159
|
+
}, []);
|
|
160
|
+
|
|
161
|
+
const animateScale = useCallback(
|
|
162
|
+
(targetScale) => {
|
|
163
|
+
if (!pressAnimation || !pressable || isDisabled) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
stopAnimation();
|
|
168
|
+
|
|
169
|
+
const animation = Animated.timing(scale, {
|
|
170
|
+
toValue: targetScale,
|
|
171
|
+
|
|
172
|
+
duration: pressAnimationDuration,
|
|
173
|
+
|
|
174
|
+
easing: Easing.out(Easing.quad),
|
|
175
|
+
|
|
176
|
+
useNativeDriver: true,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
animationRef.current = animation;
|
|
180
|
+
|
|
181
|
+
animation.start(() => {
|
|
182
|
+
animationRef.current = null;
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
[
|
|
186
|
+
pressAnimation,
|
|
187
|
+
pressable,
|
|
188
|
+
isDisabled,
|
|
189
|
+
stopAnimation,
|
|
190
|
+
scale,
|
|
191
|
+
pressAnimationDuration,
|
|
192
|
+
],
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const handlePressIn = useCallback(
|
|
196
|
+
(event) => {
|
|
197
|
+
if (!pressable || isDisabled) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
animateScale(pressScale);
|
|
202
|
+
|
|
203
|
+
onPressIn?.(event);
|
|
204
|
+
},
|
|
205
|
+
[pressable, isDisabled, animateScale, pressScale, onPressIn],
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const handlePressOut = useCallback(
|
|
209
|
+
(event) => {
|
|
210
|
+
if (!pressable || isDisabled) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
animateScale(1);
|
|
215
|
+
|
|
216
|
+
onPressOut?.(event);
|
|
217
|
+
},
|
|
218
|
+
[pressable, isDisabled, animateScale, onPressOut],
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
const handlePress = useCallback(
|
|
222
|
+
(event) => {
|
|
223
|
+
if (!pressable || isDisabled) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
onPress?.(event);
|
|
228
|
+
},
|
|
229
|
+
[pressable, isDisabled, onPress],
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
const handleLongPress = useCallback(
|
|
233
|
+
(event) => {
|
|
234
|
+
if (!pressable || isDisabled) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
onLongPress?.(event);
|
|
239
|
+
},
|
|
240
|
+
[pressable, isDisabled, onLongPress],
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
const cardStyle = useMemo(
|
|
244
|
+
() => [
|
|
245
|
+
styles.card,
|
|
246
|
+
|
|
247
|
+
{
|
|
248
|
+
backgroundColor: cardColors.background,
|
|
249
|
+
|
|
250
|
+
borderColor: cardColors.border,
|
|
251
|
+
|
|
252
|
+
borderWidth: cardColors.borderWidth,
|
|
253
|
+
|
|
254
|
+
borderRadius: radiusValue,
|
|
255
|
+
|
|
256
|
+
opacity: isDisabled ? 0.55 : 1,
|
|
257
|
+
|
|
258
|
+
transform: [
|
|
259
|
+
{
|
|
260
|
+
scale,
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
cardColors.shadow,
|
|
266
|
+
|
|
267
|
+
style,
|
|
268
|
+
],
|
|
269
|
+
[cardColors, radiusValue, isDisabled, scale, style],
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const renderImage = Boolean(image || imageSource);
|
|
273
|
+
|
|
274
|
+
const renderBody = Boolean(header || content || children || footer);
|
|
275
|
+
|
|
276
|
+
const cardContent = (
|
|
277
|
+
<>
|
|
278
|
+
{renderImage ? (
|
|
279
|
+
<View
|
|
280
|
+
style={[
|
|
281
|
+
styles.imageSection,
|
|
282
|
+
|
|
283
|
+
{
|
|
284
|
+
height: imageHeight,
|
|
285
|
+
|
|
286
|
+
borderTopLeftRadius: radiusValue,
|
|
287
|
+
|
|
288
|
+
borderTopRightRadius: radiusValue,
|
|
289
|
+
},
|
|
290
|
+
]}
|
|
291
|
+
>
|
|
292
|
+
{image || (
|
|
293
|
+
<Image
|
|
294
|
+
source={imageSource}
|
|
295
|
+
resizeMode={imageResizeMode}
|
|
296
|
+
style={[styles.image, imageStyle]}
|
|
297
|
+
/>
|
|
298
|
+
)}
|
|
299
|
+
|
|
300
|
+
{imageOverlay ? (
|
|
301
|
+
<View
|
|
302
|
+
pointerEvents="none"
|
|
303
|
+
style={[styles.imageOverlay, imageOverlayStyle]}
|
|
304
|
+
>
|
|
305
|
+
{imageOverlay}
|
|
306
|
+
</View>
|
|
307
|
+
) : null}
|
|
308
|
+
|
|
309
|
+
{badges.length > 0 ? (
|
|
310
|
+
<View pointerEvents="box-none" style={styles.badgeLayer}>
|
|
311
|
+
{badges.map((badge, index) => (
|
|
312
|
+
<CardBadge
|
|
313
|
+
key={
|
|
314
|
+
badge.id ||
|
|
315
|
+
badge.key ||
|
|
316
|
+
`${badge.position || "topLeft"}-${index}`
|
|
317
|
+
}
|
|
318
|
+
badge={badge}
|
|
319
|
+
index={index}
|
|
320
|
+
gap={badgeGap}
|
|
321
|
+
defaultStyle={badgeStyle}
|
|
322
|
+
defaultTextStyle={badgeTextStyle}
|
|
323
|
+
defaultContainerStyle={badgeContainerStyle}
|
|
324
|
+
colors={colors}
|
|
325
|
+
/>
|
|
326
|
+
))}
|
|
327
|
+
</View>
|
|
328
|
+
) : null}
|
|
329
|
+
</View>
|
|
330
|
+
) : null}
|
|
331
|
+
|
|
332
|
+
{renderBody ? (
|
|
333
|
+
<View
|
|
334
|
+
style={[
|
|
335
|
+
styles.body,
|
|
336
|
+
|
|
337
|
+
{
|
|
338
|
+
padding,
|
|
339
|
+
gap,
|
|
340
|
+
},
|
|
341
|
+
]}
|
|
342
|
+
>
|
|
343
|
+
{header ? (
|
|
344
|
+
<View style={[styles.header, headerStyle]}>{header}</View>
|
|
345
|
+
) : null}
|
|
346
|
+
|
|
347
|
+
{content ? (
|
|
348
|
+
<View style={[styles.content, contentStyle]}>{content}</View>
|
|
349
|
+
) : null}
|
|
350
|
+
|
|
351
|
+
{children ? (
|
|
352
|
+
<View
|
|
353
|
+
style={[
|
|
354
|
+
styles.content,
|
|
355
|
+
|
|
356
|
+
contentStyle,
|
|
357
|
+
|
|
358
|
+
{
|
|
359
|
+
marginTop: header || content ? 0 : undefined,
|
|
360
|
+
},
|
|
361
|
+
]}
|
|
362
|
+
>
|
|
363
|
+
{children}
|
|
364
|
+
</View>
|
|
365
|
+
) : null}
|
|
366
|
+
|
|
367
|
+
{footer ? (
|
|
368
|
+
<View style={[styles.footer, footerStyle]}>{footer}</View>
|
|
369
|
+
) : null}
|
|
370
|
+
</View>
|
|
371
|
+
) : null}
|
|
372
|
+
|
|
373
|
+
{loading ? (
|
|
374
|
+
<View
|
|
375
|
+
pointerEvents="none"
|
|
376
|
+
style={[
|
|
377
|
+
styles.loadingOverlay,
|
|
378
|
+
{
|
|
379
|
+
borderRadius: radiusValue,
|
|
380
|
+
},
|
|
381
|
+
]}
|
|
382
|
+
>
|
|
383
|
+
<ActivityIndicator
|
|
384
|
+
size="small"
|
|
385
|
+
color={colors.primary || FALLBACK_COLORS.primary}
|
|
386
|
+
/>
|
|
387
|
+
</View>
|
|
388
|
+
) : null}
|
|
389
|
+
</>
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
if (!pressable) {
|
|
393
|
+
return (
|
|
394
|
+
<Animated.View
|
|
395
|
+
{...props}
|
|
396
|
+
testID={testID}
|
|
397
|
+
style={cardStyle}
|
|
398
|
+
accessibilityLabel={accessibilityLabel}
|
|
399
|
+
>
|
|
400
|
+
{cardContent}
|
|
401
|
+
</Animated.View>
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return (
|
|
406
|
+
<Animated.View {...props} testID={testID} style={cardStyle}>
|
|
407
|
+
<Pressable
|
|
408
|
+
disabled={isDisabled}
|
|
409
|
+
onPress={handlePress}
|
|
410
|
+
onLongPress={handleLongPress}
|
|
411
|
+
onPressIn={handlePressIn}
|
|
412
|
+
onPressOut={handlePressOut}
|
|
413
|
+
accessibilityRole="button"
|
|
414
|
+
accessibilityLabel={accessibilityLabel}
|
|
415
|
+
accessibilityHint={accessibilityHint}
|
|
416
|
+
accessibilityState={{
|
|
417
|
+
disabled: isDisabled,
|
|
418
|
+
|
|
419
|
+
busy: loading,
|
|
420
|
+
}}
|
|
421
|
+
style={styles.pressable}
|
|
422
|
+
>
|
|
423
|
+
{cardContent}
|
|
424
|
+
</Pressable>
|
|
425
|
+
</Animated.View>
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/*
|
|
430
|
+
* --------------------------------------------------
|
|
431
|
+
* CARD BADGE
|
|
432
|
+
* --------------------------------------------------
|
|
433
|
+
*/
|
|
434
|
+
|
|
435
|
+
const CardBadge = memo(function CardBadge({
|
|
436
|
+
badge,
|
|
437
|
+
index,
|
|
438
|
+
gap,
|
|
439
|
+
defaultStyle,
|
|
440
|
+
defaultTextStyle,
|
|
441
|
+
defaultContainerStyle,
|
|
442
|
+
colors,
|
|
443
|
+
}) {
|
|
444
|
+
const position = BADGE_POSITIONS[badge.position] ? badge.position : "topLeft";
|
|
445
|
+
|
|
446
|
+
const badgeColors = getBadgeColors(badge, colors);
|
|
447
|
+
|
|
448
|
+
const positionStyle = getBadgePosition(position, index, gap);
|
|
449
|
+
|
|
450
|
+
const badgeContent = badge.content ?? badge.label ?? badge.text ?? "";
|
|
451
|
+
|
|
452
|
+
return (
|
|
453
|
+
<View
|
|
454
|
+
pointerEvents="none"
|
|
455
|
+
style={[
|
|
456
|
+
styles.badge,
|
|
457
|
+
|
|
458
|
+
positionStyle,
|
|
459
|
+
|
|
460
|
+
{
|
|
461
|
+
backgroundColor: badgeColors.background,
|
|
462
|
+
|
|
463
|
+
borderColor: badgeColors.border,
|
|
464
|
+
|
|
465
|
+
borderWidth: badgeColors.borderWidth,
|
|
466
|
+
},
|
|
467
|
+
|
|
468
|
+
defaultStyle,
|
|
469
|
+
|
|
470
|
+
badge.style,
|
|
471
|
+
|
|
472
|
+
defaultContainerStyle,
|
|
473
|
+
]}
|
|
474
|
+
>
|
|
475
|
+
{badge.icon ? <View style={styles.badgeIcon}>{badge.icon}</View> : null}
|
|
476
|
+
|
|
477
|
+
{badgeContent ? (
|
|
478
|
+
<Text
|
|
479
|
+
numberOfLines={1}
|
|
480
|
+
style={[
|
|
481
|
+
styles.badgeText,
|
|
482
|
+
|
|
483
|
+
{
|
|
484
|
+
color: badgeColors.text,
|
|
485
|
+
|
|
486
|
+
fontSize: badge.fontSize || 12,
|
|
487
|
+
|
|
488
|
+
lineHeight: badge.lineHeight || 16,
|
|
489
|
+
|
|
490
|
+
fontWeight: badge.fontWeight || "600",
|
|
491
|
+
},
|
|
492
|
+
|
|
493
|
+
defaultTextStyle,
|
|
494
|
+
|
|
495
|
+
badge.textStyle,
|
|
496
|
+
]}
|
|
497
|
+
>
|
|
498
|
+
{badgeContent}
|
|
499
|
+
</Text>
|
|
500
|
+
) : null}
|
|
501
|
+
</View>
|
|
502
|
+
);
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
CardBadge.displayName = "CardBadge";
|
|
506
|
+
|
|
507
|
+
/*
|
|
508
|
+
* --------------------------------------------------
|
|
509
|
+
* CARD COLORS
|
|
510
|
+
* --------------------------------------------------
|
|
511
|
+
*/
|
|
512
|
+
|
|
513
|
+
function getCardColors(variant, colors) {
|
|
514
|
+
const background = colors.card || colors.surface || FALLBACK_COLORS.card;
|
|
515
|
+
|
|
516
|
+
const border = colors.border || FALLBACK_COLORS.border;
|
|
517
|
+
|
|
518
|
+
switch (variant) {
|
|
519
|
+
case CARD_VARIANTS.elevated:
|
|
520
|
+
return {
|
|
521
|
+
background,
|
|
522
|
+
|
|
523
|
+
border: "transparent",
|
|
524
|
+
|
|
525
|
+
borderWidth: 0,
|
|
526
|
+
|
|
527
|
+
shadow: styles.elevated,
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
case CARD_VARIANTS.outlined:
|
|
531
|
+
return {
|
|
532
|
+
background,
|
|
533
|
+
|
|
534
|
+
border,
|
|
535
|
+
|
|
536
|
+
borderWidth: 1,
|
|
537
|
+
|
|
538
|
+
shadow: styles.noShadow,
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
case CARD_VARIANTS.filled:
|
|
542
|
+
return {
|
|
543
|
+
background: colors.surface || FALLBACK_COLORS.surface,
|
|
544
|
+
|
|
545
|
+
border: "transparent",
|
|
546
|
+
|
|
547
|
+
borderWidth: 0,
|
|
548
|
+
|
|
549
|
+
shadow: styles.noShadow,
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
case CARD_VARIANTS.default:
|
|
553
|
+
default:
|
|
554
|
+
return {
|
|
555
|
+
background,
|
|
556
|
+
|
|
557
|
+
border: "transparent",
|
|
558
|
+
|
|
559
|
+
borderWidth: 0,
|
|
560
|
+
|
|
561
|
+
shadow: styles.noShadow,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/*
|
|
567
|
+
* --------------------------------------------------
|
|
568
|
+
* BADGE COLORS
|
|
569
|
+
* --------------------------------------------------
|
|
570
|
+
*/
|
|
571
|
+
|
|
572
|
+
function getBadgeColors(badge, colors) {
|
|
573
|
+
const type = badge.variant || badge.type || "primary";
|
|
574
|
+
|
|
575
|
+
switch (type) {
|
|
576
|
+
case "success":
|
|
577
|
+
return {
|
|
578
|
+
background:
|
|
579
|
+
badge.backgroundColor || colors.success || FALLBACK_COLORS.success,
|
|
580
|
+
|
|
581
|
+
border: badge.borderColor || colors.success || FALLBACK_COLORS.success,
|
|
582
|
+
|
|
583
|
+
borderWidth: badge.borderWidth ?? 0,
|
|
584
|
+
|
|
585
|
+
text: badge.textColor || colors.onSuccess || FALLBACK_COLORS.white,
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
case "danger":
|
|
589
|
+
return {
|
|
590
|
+
background:
|
|
591
|
+
badge.backgroundColor || colors.danger || FALLBACK_COLORS.danger,
|
|
592
|
+
|
|
593
|
+
border: badge.borderColor || colors.danger || FALLBACK_COLORS.danger,
|
|
594
|
+
|
|
595
|
+
borderWidth: badge.borderWidth ?? 0,
|
|
596
|
+
|
|
597
|
+
text: badge.textColor || colors.onDanger || FALLBACK_COLORS.white,
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
case "warning":
|
|
601
|
+
return {
|
|
602
|
+
background:
|
|
603
|
+
badge.backgroundColor || colors.warning || FALLBACK_COLORS.warning,
|
|
604
|
+
|
|
605
|
+
border: badge.borderColor || colors.warning || FALLBACK_COLORS.warning,
|
|
606
|
+
|
|
607
|
+
borderWidth: badge.borderWidth ?? 0,
|
|
608
|
+
|
|
609
|
+
text: badge.textColor || colors.onWarning || FALLBACK_COLORS.white,
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
case "info":
|
|
613
|
+
return {
|
|
614
|
+
background:
|
|
615
|
+
badge.backgroundColor || colors.info || FALLBACK_COLORS.info,
|
|
616
|
+
|
|
617
|
+
border: badge.borderColor || colors.info || FALLBACK_COLORS.info,
|
|
618
|
+
|
|
619
|
+
borderWidth: badge.borderWidth ?? 0,
|
|
620
|
+
|
|
621
|
+
text: badge.textColor || colors.onInfo || FALLBACK_COLORS.white,
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
case "soft":
|
|
625
|
+
return {
|
|
626
|
+
background:
|
|
627
|
+
badge.backgroundColor ||
|
|
628
|
+
colors.primarySoft ||
|
|
629
|
+
FALLBACK_COLORS.primarySoft,
|
|
630
|
+
|
|
631
|
+
border: badge.borderColor || "transparent",
|
|
632
|
+
|
|
633
|
+
borderWidth: badge.borderWidth ?? 0,
|
|
634
|
+
|
|
635
|
+
text: badge.textColor || colors.primary || FALLBACK_COLORS.primary,
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
case "custom":
|
|
639
|
+
return {
|
|
640
|
+
background: badge.backgroundColor || FALLBACK_COLORS.primary,
|
|
641
|
+
|
|
642
|
+
border: badge.borderColor || "transparent",
|
|
643
|
+
|
|
644
|
+
borderWidth: badge.borderWidth ?? 0,
|
|
645
|
+
|
|
646
|
+
text: badge.textColor || FALLBACK_COLORS.white,
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
case "primary":
|
|
650
|
+
default:
|
|
651
|
+
return {
|
|
652
|
+
background:
|
|
653
|
+
badge.backgroundColor || colors.primary || FALLBACK_COLORS.primary,
|
|
654
|
+
|
|
655
|
+
border: badge.borderColor || colors.primary || FALLBACK_COLORS.primary,
|
|
656
|
+
|
|
657
|
+
borderWidth: badge.borderWidth ?? 0,
|
|
658
|
+
|
|
659
|
+
text: badge.textColor || colors.onPrimary || FALLBACK_COLORS.white,
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/*
|
|
665
|
+
* --------------------------------------------------
|
|
666
|
+
* BADGE POSITION
|
|
667
|
+
* --------------------------------------------------
|
|
668
|
+
*/
|
|
669
|
+
|
|
670
|
+
function getBadgePosition(position, index, gap) {
|
|
671
|
+
const offset = index * (28 + gap);
|
|
672
|
+
|
|
673
|
+
switch (position) {
|
|
674
|
+
case BADGE_POSITIONS.topCenter:
|
|
675
|
+
return {
|
|
676
|
+
top: 12 + offset,
|
|
677
|
+
|
|
678
|
+
alignSelf: "center",
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
case BADGE_POSITIONS.topRight:
|
|
682
|
+
return {
|
|
683
|
+
top: 12 + offset,
|
|
684
|
+
|
|
685
|
+
right: 12,
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
case BADGE_POSITIONS.centerLeft:
|
|
689
|
+
return {
|
|
690
|
+
left: 12 + offset,
|
|
691
|
+
|
|
692
|
+
top: "50%",
|
|
693
|
+
|
|
694
|
+
transform: [
|
|
695
|
+
{
|
|
696
|
+
translateY: -12,
|
|
697
|
+
},
|
|
698
|
+
],
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
case BADGE_POSITIONS.center:
|
|
702
|
+
return {
|
|
703
|
+
top: "50%",
|
|
704
|
+
|
|
705
|
+
left: "50%",
|
|
706
|
+
|
|
707
|
+
transform: [
|
|
708
|
+
{
|
|
709
|
+
translateX: -50,
|
|
710
|
+
},
|
|
711
|
+
|
|
712
|
+
{
|
|
713
|
+
translateY: -12,
|
|
714
|
+
},
|
|
715
|
+
],
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
case BADGE_POSITIONS.centerRight:
|
|
719
|
+
return {
|
|
720
|
+
right: 12 + offset,
|
|
721
|
+
|
|
722
|
+
top: "50%",
|
|
723
|
+
|
|
724
|
+
transform: [
|
|
725
|
+
{
|
|
726
|
+
translateY: -12,
|
|
727
|
+
},
|
|
728
|
+
],
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
case BADGE_POSITIONS.bottomLeft:
|
|
732
|
+
return {
|
|
733
|
+
bottom: 12,
|
|
734
|
+
|
|
735
|
+
left: 12 + offset,
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
case BADGE_POSITIONS.bottomCenter:
|
|
739
|
+
return {
|
|
740
|
+
bottom: 12 + offset,
|
|
741
|
+
|
|
742
|
+
alignSelf: "center",
|
|
743
|
+
};
|
|
744
|
+
|
|
745
|
+
case BADGE_POSITIONS.bottomRight:
|
|
746
|
+
return {
|
|
747
|
+
bottom: 12,
|
|
748
|
+
|
|
749
|
+
right: 12 + offset,
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
case BADGE_POSITIONS.topLeft:
|
|
753
|
+
default:
|
|
754
|
+
return {
|
|
755
|
+
top: 12 + offset,
|
|
756
|
+
|
|
757
|
+
left: 12,
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/*
|
|
763
|
+
* --------------------------------------------------
|
|
764
|
+
* RADIUS
|
|
765
|
+
* --------------------------------------------------
|
|
766
|
+
*/
|
|
767
|
+
|
|
768
|
+
function getRadiusValue(radius, theme) {
|
|
769
|
+
const themeRadius = theme?.radius || {};
|
|
770
|
+
|
|
771
|
+
switch (radius) {
|
|
772
|
+
case CARD_RADIUS.none:
|
|
773
|
+
return 0;
|
|
774
|
+
|
|
775
|
+
case CARD_RADIUS.sm:
|
|
776
|
+
return themeRadius.sm ?? 8;
|
|
777
|
+
|
|
778
|
+
case CARD_RADIUS.md:
|
|
779
|
+
return themeRadius.md ?? 12;
|
|
780
|
+
|
|
781
|
+
case CARD_RADIUS.xl:
|
|
782
|
+
return themeRadius.xl ?? 20;
|
|
783
|
+
|
|
784
|
+
case CARD_RADIUS.lg:
|
|
785
|
+
default:
|
|
786
|
+
return themeRadius.lg ?? 16;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const styles = StyleSheet.create({
|
|
791
|
+
card: {
|
|
792
|
+
width: "100%",
|
|
793
|
+
|
|
794
|
+
overflow: "hidden",
|
|
795
|
+
|
|
796
|
+
position: "relative",
|
|
797
|
+
},
|
|
798
|
+
|
|
799
|
+
pressable: {
|
|
800
|
+
width: "100%",
|
|
801
|
+
},
|
|
802
|
+
|
|
803
|
+
imageSection: {
|
|
804
|
+
width: "100%",
|
|
805
|
+
|
|
806
|
+
position: "relative",
|
|
807
|
+
|
|
808
|
+
overflow: "hidden",
|
|
809
|
+
},
|
|
810
|
+
|
|
811
|
+
image: {
|
|
812
|
+
width: "100%",
|
|
813
|
+
|
|
814
|
+
height: "100%",
|
|
815
|
+
},
|
|
816
|
+
|
|
817
|
+
imageOverlay: {
|
|
818
|
+
...StyleSheet.absoluteFillObject,
|
|
819
|
+
|
|
820
|
+
justifyContent: "center",
|
|
821
|
+
|
|
822
|
+
alignItems: "center",
|
|
823
|
+
},
|
|
824
|
+
|
|
825
|
+
badgeLayer: {
|
|
826
|
+
...StyleSheet.absoluteFillObject,
|
|
827
|
+
|
|
828
|
+
pointerEvents: "box-none",
|
|
829
|
+
},
|
|
830
|
+
|
|
831
|
+
badge: {
|
|
832
|
+
position: "absolute",
|
|
833
|
+
|
|
834
|
+
minHeight: 26,
|
|
835
|
+
|
|
836
|
+
paddingHorizontal: 10,
|
|
837
|
+
|
|
838
|
+
paddingVertical: 5,
|
|
839
|
+
|
|
840
|
+
borderRadius: 999,
|
|
841
|
+
|
|
842
|
+
flexDirection: "row",
|
|
843
|
+
|
|
844
|
+
alignItems: "center",
|
|
845
|
+
|
|
846
|
+
justifyContent: "center",
|
|
847
|
+
|
|
848
|
+
maxWidth: "80%",
|
|
849
|
+
|
|
850
|
+
zIndex: 10,
|
|
851
|
+
|
|
852
|
+
elevation: 3,
|
|
853
|
+
},
|
|
854
|
+
|
|
855
|
+
badgeText: {
|
|
856
|
+
includeFontPadding: false,
|
|
857
|
+
|
|
858
|
+
textAlign: "center",
|
|
859
|
+
|
|
860
|
+
flexShrink: 1,
|
|
861
|
+
},
|
|
862
|
+
|
|
863
|
+
badgeIcon: {
|
|
864
|
+
marginRight: 5,
|
|
865
|
+
|
|
866
|
+
alignItems: "center",
|
|
867
|
+
|
|
868
|
+
justifyContent: "center",
|
|
869
|
+
},
|
|
870
|
+
|
|
871
|
+
body: {
|
|
872
|
+
width: "100%",
|
|
873
|
+
},
|
|
874
|
+
|
|
875
|
+
header: {
|
|
876
|
+
width: "100%",
|
|
877
|
+
},
|
|
878
|
+
|
|
879
|
+
content: {
|
|
880
|
+
width: "100%",
|
|
881
|
+
},
|
|
882
|
+
|
|
883
|
+
footer: {
|
|
884
|
+
width: "100%",
|
|
885
|
+
},
|
|
886
|
+
|
|
887
|
+
loadingOverlay: {
|
|
888
|
+
...StyleSheet.absoluteFillObject,
|
|
889
|
+
|
|
890
|
+
alignItems: "center",
|
|
891
|
+
|
|
892
|
+
justifyContent: "center",
|
|
893
|
+
|
|
894
|
+
backgroundColor: "rgba(0,0,0,0.08)",
|
|
895
|
+
|
|
896
|
+
zIndex: 100,
|
|
897
|
+
},
|
|
898
|
+
|
|
899
|
+
elevated: {
|
|
900
|
+
shadowColor: "#000000",
|
|
901
|
+
|
|
902
|
+
shadowOffset: {
|
|
903
|
+
width: 0,
|
|
904
|
+
height: 4,
|
|
905
|
+
},
|
|
906
|
+
|
|
907
|
+
shadowOpacity: 0.12,
|
|
908
|
+
|
|
909
|
+
shadowRadius: 10,
|
|
910
|
+
|
|
911
|
+
elevation: 4,
|
|
912
|
+
},
|
|
913
|
+
|
|
914
|
+
noShadow: {
|
|
915
|
+
shadowOpacity: 0,
|
|
916
|
+
|
|
917
|
+
elevation: 0,
|
|
918
|
+
},
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
export const UICard = memo(UICardComponent);
|
|
922
|
+
|
|
923
|
+
UICard.displayName = "UICard";
|
|
924
|
+
|
|
925
|
+
export {
|
|
926
|
+
CARD_VARIANTS as UICardVariants,
|
|
927
|
+
CARD_RADIUS as UICardRadius,
|
|
928
|
+
BADGE_POSITIONS as UICardBadgePositions,
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
export default UICard;
|
package/src/components/index.js
CHANGED