@croacroa/react-native-template 1.0.0

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 (109) hide show
  1. package/.env.example +18 -0
  2. package/.eslintrc.js +55 -0
  3. package/.github/workflows/ci.yml +184 -0
  4. package/.github/workflows/eas-build.yml +55 -0
  5. package/.github/workflows/eas-update.yml +50 -0
  6. package/.gitignore +62 -0
  7. package/.prettierrc +11 -0
  8. package/.storybook/main.ts +28 -0
  9. package/.storybook/preview.tsx +30 -0
  10. package/CHANGELOG.md +106 -0
  11. package/CONTRIBUTING.md +377 -0
  12. package/README.md +399 -0
  13. package/__tests__/components/Button.test.tsx +74 -0
  14. package/__tests__/hooks/useAuth.test.tsx +499 -0
  15. package/__tests__/services/api.test.ts +535 -0
  16. package/__tests__/utils/cn.test.ts +39 -0
  17. package/app/(auth)/_layout.tsx +36 -0
  18. package/app/(auth)/home.tsx +117 -0
  19. package/app/(auth)/profile.tsx +152 -0
  20. package/app/(auth)/settings.tsx +147 -0
  21. package/app/(public)/_layout.tsx +21 -0
  22. package/app/(public)/forgot-password.tsx +127 -0
  23. package/app/(public)/login.tsx +120 -0
  24. package/app/(public)/onboarding.tsx +5 -0
  25. package/app/(public)/register.tsx +139 -0
  26. package/app/_layout.tsx +97 -0
  27. package/app/index.tsx +21 -0
  28. package/app.config.ts +72 -0
  29. package/assets/images/.gitkeep +7 -0
  30. package/assets/images/adaptive-icon.png +0 -0
  31. package/assets/images/favicon.png +0 -0
  32. package/assets/images/icon.png +0 -0
  33. package/assets/images/notification-icon.png +0 -0
  34. package/assets/images/splash.png +0 -0
  35. package/babel.config.js +10 -0
  36. package/components/ErrorBoundary.tsx +169 -0
  37. package/components/forms/FormInput.tsx +78 -0
  38. package/components/forms/index.ts +1 -0
  39. package/components/onboarding/OnboardingScreen.tsx +370 -0
  40. package/components/onboarding/index.ts +2 -0
  41. package/components/ui/AnimatedButton.tsx +156 -0
  42. package/components/ui/AnimatedCard.tsx +108 -0
  43. package/components/ui/Avatar.tsx +316 -0
  44. package/components/ui/Badge.tsx +416 -0
  45. package/components/ui/BottomSheet.tsx +307 -0
  46. package/components/ui/Button.stories.tsx +115 -0
  47. package/components/ui/Button.tsx +104 -0
  48. package/components/ui/Card.stories.tsx +84 -0
  49. package/components/ui/Card.tsx +32 -0
  50. package/components/ui/Checkbox.tsx +261 -0
  51. package/components/ui/Input.stories.tsx +106 -0
  52. package/components/ui/Input.tsx +117 -0
  53. package/components/ui/Modal.tsx +98 -0
  54. package/components/ui/OptimizedImage.tsx +369 -0
  55. package/components/ui/Select.tsx +240 -0
  56. package/components/ui/Skeleton.tsx +180 -0
  57. package/components/ui/index.ts +18 -0
  58. package/constants/config.ts +54 -0
  59. package/docs/adr/001-state-management.md +79 -0
  60. package/docs/adr/002-styling-approach.md +130 -0
  61. package/docs/adr/003-data-fetching.md +155 -0
  62. package/docs/adr/004-auth-adapter-pattern.md +144 -0
  63. package/docs/adr/README.md +78 -0
  64. package/eas.json +47 -0
  65. package/global.css +10 -0
  66. package/hooks/index.ts +25 -0
  67. package/hooks/useApi.ts +236 -0
  68. package/hooks/useAuth.tsx +290 -0
  69. package/hooks/useBiometrics.ts +295 -0
  70. package/hooks/useDeepLinking.ts +256 -0
  71. package/hooks/useNotifications.ts +138 -0
  72. package/hooks/useOffline.ts +69 -0
  73. package/hooks/usePerformance.ts +434 -0
  74. package/hooks/useTheme.tsx +85 -0
  75. package/hooks/useUpdates.ts +358 -0
  76. package/i18n/index.ts +77 -0
  77. package/i18n/locales/en.json +101 -0
  78. package/i18n/locales/fr.json +101 -0
  79. package/jest.config.js +32 -0
  80. package/maestro/README.md +113 -0
  81. package/maestro/config.yaml +35 -0
  82. package/maestro/flows/login.yaml +62 -0
  83. package/maestro/flows/navigation.yaml +68 -0
  84. package/maestro/flows/offline.yaml +60 -0
  85. package/maestro/flows/register.yaml +94 -0
  86. package/metro.config.js +6 -0
  87. package/nativewind-env.d.ts +1 -0
  88. package/package.json +170 -0
  89. package/scripts/init.ps1 +162 -0
  90. package/scripts/init.sh +174 -0
  91. package/services/analytics.ts +428 -0
  92. package/services/api.ts +340 -0
  93. package/services/authAdapter.ts +333 -0
  94. package/services/index.ts +22 -0
  95. package/services/queryClient.ts +97 -0
  96. package/services/sentry.ts +131 -0
  97. package/services/storage.ts +82 -0
  98. package/stores/appStore.ts +54 -0
  99. package/stores/index.ts +2 -0
  100. package/stores/notificationStore.ts +40 -0
  101. package/tailwind.config.js +47 -0
  102. package/tsconfig.json +26 -0
  103. package/types/index.ts +42 -0
  104. package/types/user.ts +63 -0
  105. package/utils/accessibility.ts +446 -0
  106. package/utils/cn.ts +14 -0
  107. package/utils/index.ts +43 -0
  108. package/utils/toast.ts +113 -0
  109. package/utils/validation.ts +67 -0
@@ -0,0 +1,316 @@
1
+ import { View, Text } from "react-native";
2
+ import { Image } from "expo-image";
3
+ import { Ionicons } from "@expo/vector-icons";
4
+ import { useTheme } from "@/hooks/useTheme";
5
+ import { cn } from "@/utils/cn";
6
+
7
+ type AvatarSize = "xs" | "sm" | "md" | "lg" | "xl" | "2xl";
8
+
9
+ interface AvatarProps {
10
+ /**
11
+ * Image source URL
12
+ */
13
+ source?: string | null;
14
+
15
+ /**
16
+ * User's name (used for initials fallback)
17
+ */
18
+ name?: string;
19
+
20
+ /**
21
+ * Size variant
22
+ */
23
+ size?: AvatarSize;
24
+
25
+ /**
26
+ * Custom size in pixels (overrides size variant)
27
+ */
28
+ customSize?: number;
29
+
30
+ /**
31
+ * Whether to show online indicator
32
+ */
33
+ showOnlineIndicator?: boolean;
34
+
35
+ /**
36
+ * Whether the user is online
37
+ */
38
+ isOnline?: boolean;
39
+
40
+ /**
41
+ * Additional class name
42
+ */
43
+ className?: string;
44
+
45
+ /**
46
+ * Border color class
47
+ */
48
+ borderClassName?: string;
49
+ }
50
+
51
+ const sizeConfig: Record<
52
+ AvatarSize,
53
+ { container: number; text: string; icon: number; indicator: number }
54
+ > = {
55
+ xs: { container: 24, text: "text-xs", icon: 12, indicator: 6 },
56
+ sm: { container: 32, text: "text-sm", icon: 16, indicator: 8 },
57
+ md: { container: 40, text: "text-base", icon: 20, indicator: 10 },
58
+ lg: { container: 48, text: "text-lg", icon: 24, indicator: 12 },
59
+ xl: { container: 64, text: "text-xl", icon: 32, indicator: 14 },
60
+ "2xl": { container: 80, text: "text-2xl", icon: 40, indicator: 16 },
61
+ };
62
+
63
+ /**
64
+ * Get initials from a name
65
+ */
66
+ function getInitials(name: string): string {
67
+ const parts = name.trim().split(/\s+/);
68
+ if (parts.length === 1) {
69
+ return parts[0].substring(0, 2).toUpperCase();
70
+ }
71
+ return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
72
+ }
73
+
74
+ /**
75
+ * Get a consistent color based on the name
76
+ */
77
+ function getAvatarColor(name: string): string {
78
+ const colors = [
79
+ "#ef4444", // red
80
+ "#f97316", // orange
81
+ "#f59e0b", // amber
82
+ "#84cc16", // lime
83
+ "#10b981", // emerald
84
+ "#14b8a6", // teal
85
+ "#06b6d4", // cyan
86
+ "#0ea5e9", // sky
87
+ "#3b82f6", // blue
88
+ "#6366f1", // indigo
89
+ "#8b5cf6", // violet
90
+ "#a855f7", // purple
91
+ "#d946ef", // fuchsia
92
+ "#ec4899", // pink
93
+ "#f43f5e", // rose
94
+ ];
95
+
96
+ let hash = 0;
97
+ for (let i = 0; i < name.length; i++) {
98
+ hash = name.charCodeAt(i) + ((hash << 5) - hash);
99
+ }
100
+
101
+ return colors[Math.abs(hash) % colors.length];
102
+ }
103
+
104
+ export function Avatar({
105
+ source,
106
+ name,
107
+ size = "md",
108
+ customSize,
109
+ showOnlineIndicator = false,
110
+ isOnline = false,
111
+ className,
112
+ borderClassName,
113
+ }: AvatarProps) {
114
+ const { isDark } = useTheme();
115
+ const config = sizeConfig[size];
116
+ const containerSize = customSize || config.container;
117
+
118
+ const initials = name ? getInitials(name) : "";
119
+ const backgroundColor = name
120
+ ? getAvatarColor(name)
121
+ : isDark
122
+ ? "#475569"
123
+ : "#cbd5e1";
124
+
125
+ const renderContent = () => {
126
+ // Image avatar
127
+ if (source) {
128
+ return (
129
+ <Image
130
+ source={{ uri: source }}
131
+ style={{
132
+ width: containerSize,
133
+ height: containerSize,
134
+ borderRadius: containerSize / 2,
135
+ }}
136
+ contentFit="cover"
137
+ transition={200}
138
+ placeholder={require("@/assets/images/icon.png")}
139
+ />
140
+ );
141
+ }
142
+
143
+ // Initials avatar
144
+ if (name) {
145
+ return (
146
+ <View
147
+ style={{
148
+ width: containerSize,
149
+ height: containerSize,
150
+ borderRadius: containerSize / 2,
151
+ backgroundColor,
152
+ }}
153
+ className="items-center justify-center"
154
+ >
155
+ <Text
156
+ className={cn(config.text, "font-semibold text-white")}
157
+ style={{
158
+ fontSize: customSize ? customSize * 0.4 : undefined,
159
+ }}
160
+ >
161
+ {initials}
162
+ </Text>
163
+ </View>
164
+ );
165
+ }
166
+
167
+ // Default placeholder
168
+ return (
169
+ <View
170
+ style={{
171
+ width: containerSize,
172
+ height: containerSize,
173
+ borderRadius: containerSize / 2,
174
+ }}
175
+ className={cn(
176
+ "items-center justify-center",
177
+ isDark ? "bg-gray-700" : "bg-gray-200"
178
+ )}
179
+ >
180
+ <Ionicons
181
+ name="person"
182
+ size={customSize ? customSize * 0.5 : config.icon}
183
+ color={isDark ? "#94a3b8" : "#64748b"}
184
+ />
185
+ </View>
186
+ );
187
+ };
188
+
189
+ return (
190
+ <View
191
+ className={cn("relative", className)}
192
+ style={{ width: containerSize, height: containerSize }}
193
+ >
194
+ <View
195
+ className={cn("overflow-hidden rounded-full", borderClassName)}
196
+ style={{
197
+ width: containerSize,
198
+ height: containerSize,
199
+ borderRadius: containerSize / 2,
200
+ }}
201
+ >
202
+ {renderContent()}
203
+ </View>
204
+
205
+ {/* Online indicator */}
206
+ {showOnlineIndicator && (
207
+ <View
208
+ style={{
209
+ width: config.indicator,
210
+ height: config.indicator,
211
+ borderRadius: config.indicator / 2,
212
+ borderWidth: 2,
213
+ position: "absolute",
214
+ bottom: 0,
215
+ right: 0,
216
+ }}
217
+ className={cn(
218
+ isOnline ? "bg-green-500" : "bg-gray-400",
219
+ isDark ? "border-background-dark" : "border-white"
220
+ )}
221
+ />
222
+ )}
223
+ </View>
224
+ );
225
+ }
226
+
227
+ /**
228
+ * Avatar Group component for displaying multiple avatars
229
+ */
230
+ interface AvatarGroupProps {
231
+ /**
232
+ * Array of avatar data
233
+ */
234
+ avatars: {
235
+ source?: string | null;
236
+ name?: string;
237
+ }[];
238
+
239
+ /**
240
+ * Maximum number of avatars to display
241
+ */
242
+ max?: number;
243
+
244
+ /**
245
+ * Size variant
246
+ */
247
+ size?: AvatarSize;
248
+
249
+ /**
250
+ * Additional class name
251
+ */
252
+ className?: string;
253
+ }
254
+
255
+ export function AvatarGroup({
256
+ avatars,
257
+ max = 4,
258
+ size = "md",
259
+ className,
260
+ }: AvatarGroupProps) {
261
+ const { isDark } = useTheme();
262
+ const config = sizeConfig[size];
263
+ const displayAvatars = avatars.slice(0, max);
264
+ const remainingCount = avatars.length - max;
265
+
266
+ return (
267
+ <View className={cn("flex-row items-center", className)}>
268
+ {displayAvatars.map((avatar, index) => (
269
+ <View
270
+ key={index}
271
+ style={{
272
+ marginLeft: index > 0 ? -config.container / 3 : 0,
273
+ zIndex: displayAvatars.length - index,
274
+ }}
275
+ >
276
+ <Avatar
277
+ source={avatar.source}
278
+ name={avatar.name}
279
+ size={size}
280
+ borderClassName={cn(
281
+ "border-2",
282
+ isDark ? "border-background-dark" : "border-white"
283
+ )}
284
+ />
285
+ </View>
286
+ ))}
287
+
288
+ {remainingCount > 0 && (
289
+ <View
290
+ style={{
291
+ marginLeft: -config.container / 3,
292
+ width: config.container,
293
+ height: config.container,
294
+ borderRadius: config.container / 2,
295
+ }}
296
+ className={cn(
297
+ "items-center justify-center border-2",
298
+ isDark
299
+ ? "bg-gray-700 border-background-dark"
300
+ : "bg-gray-200 border-white"
301
+ )}
302
+ >
303
+ <Text
304
+ className={cn(
305
+ config.text,
306
+ "font-medium",
307
+ isDark ? "text-text-dark" : "text-text-light"
308
+ )}
309
+ >
310
+ +{remainingCount}
311
+ </Text>
312
+ </View>
313
+ )}
314
+ </View>
315
+ );
316
+ }
@@ -0,0 +1,416 @@
1
+ import { View, Text, TouchableOpacity } from "react-native";
2
+ import { Ionicons } from "@expo/vector-icons";
3
+ import { useTheme } from "@/hooks/useTheme";
4
+ import { cn } from "@/utils/cn";
5
+
6
+ type BadgeVariant =
7
+ | "default"
8
+ | "primary"
9
+ | "secondary"
10
+ | "success"
11
+ | "warning"
12
+ | "error"
13
+ | "info";
14
+
15
+ type BadgeSize = "sm" | "md" | "lg";
16
+
17
+ interface BadgeProps {
18
+ /**
19
+ * Badge content
20
+ */
21
+ children: React.ReactNode;
22
+
23
+ /**
24
+ * Visual variant
25
+ */
26
+ variant?: BadgeVariant;
27
+
28
+ /**
29
+ * Size variant
30
+ */
31
+ size?: BadgeSize;
32
+
33
+ /**
34
+ * Icon name (Ionicons)
35
+ */
36
+ icon?: keyof typeof Ionicons.glyphMap;
37
+
38
+ /**
39
+ * Whether the badge is outlined
40
+ */
41
+ outlined?: boolean;
42
+
43
+ /**
44
+ * Whether to make it a pill shape
45
+ */
46
+ pill?: boolean;
47
+
48
+ /**
49
+ * Additional class name
50
+ */
51
+ className?: string;
52
+ }
53
+
54
+ const sizeStyles: Record<
55
+ BadgeSize,
56
+ { container: string; text: string; icon: number }
57
+ > = {
58
+ sm: { container: "px-2 py-0.5", text: "text-xs", icon: 12 },
59
+ md: { container: "px-2.5 py-1", text: "text-sm", icon: 14 },
60
+ lg: { container: "px-3 py-1.5", text: "text-base", icon: 16 },
61
+ };
62
+
63
+ const variantStyles: Record<
64
+ BadgeVariant,
65
+ {
66
+ bg: string;
67
+ bgDark: string;
68
+ text: string;
69
+ textDark: string;
70
+ border: string;
71
+ borderDark: string;
72
+ }
73
+ > = {
74
+ default: {
75
+ bg: "bg-gray-100",
76
+ bgDark: "bg-gray-800",
77
+ text: "text-gray-700",
78
+ textDark: "text-gray-300",
79
+ border: "border-gray-300",
80
+ borderDark: "border-gray-600",
81
+ },
82
+ primary: {
83
+ bg: "bg-primary-100",
84
+ bgDark: "bg-primary-900/30",
85
+ text: "text-primary-700",
86
+ textDark: "text-primary-400",
87
+ border: "border-primary-300",
88
+ borderDark: "border-primary-700",
89
+ },
90
+ secondary: {
91
+ bg: "bg-slate-100",
92
+ bgDark: "bg-slate-800",
93
+ text: "text-slate-700",
94
+ textDark: "text-slate-300",
95
+ border: "border-slate-300",
96
+ borderDark: "border-slate-600",
97
+ },
98
+ success: {
99
+ bg: "bg-green-100",
100
+ bgDark: "bg-green-900/30",
101
+ text: "text-green-700",
102
+ textDark: "text-green-400",
103
+ border: "border-green-300",
104
+ borderDark: "border-green-700",
105
+ },
106
+ warning: {
107
+ bg: "bg-yellow-100",
108
+ bgDark: "bg-yellow-900/30",
109
+ text: "text-yellow-700",
110
+ textDark: "text-yellow-400",
111
+ border: "border-yellow-300",
112
+ borderDark: "border-yellow-700",
113
+ },
114
+ error: {
115
+ bg: "bg-red-100",
116
+ bgDark: "bg-red-900/30",
117
+ text: "text-red-700",
118
+ textDark: "text-red-400",
119
+ border: "border-red-300",
120
+ borderDark: "border-red-700",
121
+ },
122
+ info: {
123
+ bg: "bg-blue-100",
124
+ bgDark: "bg-blue-900/30",
125
+ text: "text-blue-700",
126
+ textDark: "text-blue-400",
127
+ border: "border-blue-300",
128
+ borderDark: "border-blue-700",
129
+ },
130
+ };
131
+
132
+ export function Badge({
133
+ children,
134
+ variant = "default",
135
+ size = "md",
136
+ icon,
137
+ outlined = false,
138
+ pill = false,
139
+ className,
140
+ }: BadgeProps) {
141
+ const { isDark } = useTheme();
142
+ const sizeStyle = sizeStyles[size];
143
+ const variantStyle = variantStyles[variant];
144
+
145
+ return (
146
+ <View
147
+ className={cn(
148
+ "flex-row items-center self-start",
149
+ sizeStyle.container,
150
+ pill ? "rounded-full" : "rounded-md",
151
+ outlined
152
+ ? cn(
153
+ "border bg-transparent",
154
+ isDark ? variantStyle.borderDark : variantStyle.border
155
+ )
156
+ : isDark
157
+ ? variantStyle.bgDark
158
+ : variantStyle.bg,
159
+ className
160
+ )}
161
+ >
162
+ {icon && (
163
+ <Ionicons
164
+ name={icon}
165
+ size={sizeStyle.icon}
166
+ color={
167
+ isDark
168
+ ? getTextColor(variantStyle.textDark)
169
+ : getTextColor(variantStyle.text)
170
+ }
171
+ style={{ marginRight: 4 }}
172
+ />
173
+ )}
174
+ <Text
175
+ className={cn(
176
+ sizeStyle.text,
177
+ "font-medium",
178
+ isDark ? variantStyle.textDark : variantStyle.text
179
+ )}
180
+ >
181
+ {children}
182
+ </Text>
183
+ </View>
184
+ );
185
+ }
186
+
187
+ // Helper to extract color from class name
188
+ function getTextColor(className: string): string {
189
+ const colorMap: Record<string, string> = {
190
+ "text-gray-700": "#374151",
191
+ "text-gray-300": "#d1d5db",
192
+ "text-primary-700": "#047857",
193
+ "text-primary-400": "#34d399",
194
+ "text-slate-700": "#334155",
195
+ "text-slate-300": "#cbd5e1",
196
+ "text-green-700": "#15803d",
197
+ "text-green-400": "#4ade80",
198
+ "text-yellow-700": "#a16207",
199
+ "text-yellow-400": "#facc15",
200
+ "text-red-700": "#b91c1c",
201
+ "text-red-400": "#f87171",
202
+ "text-blue-700": "#1d4ed8",
203
+ "text-blue-400": "#60a5fa",
204
+ };
205
+ return colorMap[className] || "#6b7280";
206
+ }
207
+
208
+ /**
209
+ * Chip component (interactive badge)
210
+ */
211
+ interface ChipProps extends Omit<BadgeProps, "children"> {
212
+ /**
213
+ * Chip label
214
+ */
215
+ label: string;
216
+
217
+ /**
218
+ * Called when the chip is pressed
219
+ */
220
+ onPress?: () => void;
221
+
222
+ /**
223
+ * Whether the chip is selected
224
+ */
225
+ selected?: boolean;
226
+
227
+ /**
228
+ * Whether to show remove button
229
+ */
230
+ removable?: boolean;
231
+
232
+ /**
233
+ * Called when remove button is pressed
234
+ */
235
+ onRemove?: () => void;
236
+
237
+ /**
238
+ * Whether the chip is disabled
239
+ */
240
+ disabled?: boolean;
241
+ }
242
+
243
+ export function Chip({
244
+ label,
245
+ variant = "default",
246
+ size = "md",
247
+ icon,
248
+ onPress,
249
+ selected = false,
250
+ removable = false,
251
+ onRemove,
252
+ disabled = false,
253
+ pill = true,
254
+ className,
255
+ }: ChipProps) {
256
+ const { isDark } = useTheme();
257
+ const sizeStyle = sizeStyles[size];
258
+ const variantStyle = selected
259
+ ? variantStyles.primary
260
+ : variantStyles[variant];
261
+
262
+ const content = (
263
+ <View
264
+ className={cn(
265
+ "flex-row items-center",
266
+ sizeStyle.container,
267
+ pill ? "rounded-full" : "rounded-md",
268
+ selected
269
+ ? isDark
270
+ ? "bg-primary-600"
271
+ : "bg-primary-500"
272
+ : isDark
273
+ ? variantStyle.bgDark
274
+ : variantStyle.bg,
275
+ disabled && "opacity-50",
276
+ className
277
+ )}
278
+ >
279
+ {icon && (
280
+ <Ionicons
281
+ name={icon}
282
+ size={sizeStyle.icon}
283
+ color={
284
+ selected
285
+ ? "#ffffff"
286
+ : isDark
287
+ ? getTextColor(variantStyle.textDark)
288
+ : getTextColor(variantStyle.text)
289
+ }
290
+ style={{ marginRight: 4 }}
291
+ />
292
+ )}
293
+ <Text
294
+ className={cn(
295
+ sizeStyle.text,
296
+ "font-medium",
297
+ selected
298
+ ? "text-white"
299
+ : isDark
300
+ ? variantStyle.textDark
301
+ : variantStyle.text
302
+ )}
303
+ >
304
+ {label}
305
+ </Text>
306
+ {removable && (
307
+ <TouchableOpacity
308
+ onPress={onRemove}
309
+ hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
310
+ disabled={disabled}
311
+ className="ml-1"
312
+ >
313
+ <Ionicons
314
+ name="close-circle"
315
+ size={sizeStyle.icon + 2}
316
+ color={
317
+ selected
318
+ ? "#ffffff"
319
+ : isDark
320
+ ? getTextColor(variantStyle.textDark)
321
+ : getTextColor(variantStyle.text)
322
+ }
323
+ />
324
+ </TouchableOpacity>
325
+ )}
326
+ </View>
327
+ );
328
+
329
+ if (onPress) {
330
+ return (
331
+ <TouchableOpacity
332
+ onPress={onPress}
333
+ disabled={disabled}
334
+ activeOpacity={0.7}
335
+ >
336
+ {content}
337
+ </TouchableOpacity>
338
+ );
339
+ }
340
+
341
+ return content;
342
+ }
343
+
344
+ /**
345
+ * Count Badge (for notifications, cart items, etc.)
346
+ */
347
+ interface CountBadgeProps {
348
+ /**
349
+ * Count to display
350
+ */
351
+ count: number;
352
+
353
+ /**
354
+ * Maximum count to show before showing "99+"
355
+ */
356
+ max?: number;
357
+
358
+ /**
359
+ * Variant color
360
+ */
361
+ variant?: "primary" | "error" | "warning";
362
+
363
+ /**
364
+ * Size variant
365
+ */
366
+ size?: "sm" | "md";
367
+
368
+ /**
369
+ * Additional class name
370
+ */
371
+ className?: string;
372
+ }
373
+
374
+ export function CountBadge({
375
+ count,
376
+ max = 99,
377
+ variant = "error",
378
+ size = "sm",
379
+ className,
380
+ }: CountBadgeProps) {
381
+ if (count <= 0) return null;
382
+
383
+ const displayCount = count > max ? `${max}+` : count.toString();
384
+
385
+ const bgColors = {
386
+ primary: "bg-primary-500",
387
+ error: "bg-red-500",
388
+ warning: "bg-yellow-500",
389
+ };
390
+
391
+ const sizes = {
392
+ sm: { min: 18, text: "text-xs", px: 4 },
393
+ md: { min: 22, text: "text-sm", px: 6 },
394
+ };
395
+
396
+ const sizeConfig = sizes[size];
397
+
398
+ return (
399
+ <View
400
+ className={cn(
401
+ "items-center justify-center rounded-full",
402
+ bgColors[variant],
403
+ className
404
+ )}
405
+ style={{
406
+ minWidth: sizeConfig.min,
407
+ height: sizeConfig.min,
408
+ paddingHorizontal: sizeConfig.px,
409
+ }}
410
+ >
411
+ <Text className={cn(sizeConfig.text, "font-bold text-white")}>
412
+ {displayCount}
413
+ </Text>
414
+ </View>
415
+ );
416
+ }