@umituz/react-native-design-system 4.28.11 → 4.28.12

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 (47) hide show
  1. package/package.json +31 -8
  2. package/src/atoms/AtomicAvatar.tsx +69 -40
  3. package/src/atoms/AtomicSpinner.tsx +24 -22
  4. package/src/atoms/AtomicText.tsx +32 -27
  5. package/src/atoms/AtomicTextArea.tsx +17 -15
  6. package/src/atoms/EmptyState.tsx +44 -41
  7. package/src/atoms/button/AtomicButton.tsx +8 -9
  8. package/src/atoms/card/AtomicCard.tsx +26 -8
  9. package/src/atoms/datepicker/components/DatePickerButton.tsx +8 -8
  10. package/src/atoms/datepicker/components/DatePickerModal.tsx +7 -7
  11. package/src/atoms/fab/styles/fabStyles.ts +0 -21
  12. package/src/atoms/icon/index.ts +6 -20
  13. package/src/atoms/picker/components/PickerModal.tsx +24 -4
  14. package/src/atoms/skeleton/AtomicSkeleton.tsx +9 -11
  15. package/src/carousel/Carousel.tsx +43 -20
  16. package/src/carousel/carouselCalculations.ts +12 -9
  17. package/src/carousel/index.ts +0 -1
  18. package/src/device/detection/iPadDetection.ts +5 -14
  19. package/src/device/infrastructure/services/DeviceFeatureService.ts +89 -9
  20. package/src/device/infrastructure/services/DeviceInfoService.ts +33 -0
  21. package/src/device/infrastructure/services/UserFriendlyIdService.ts +8 -6
  22. package/src/device/infrastructure/utils/__tests__/stringUtils.test.ts +56 -20
  23. package/src/device/infrastructure/utils/nativeModuleUtils.ts +16 -2
  24. package/src/device/infrastructure/utils/stringUtils.ts +51 -5
  25. package/src/filesystem/domain/utils/FileUtils.ts +5 -1
  26. package/src/image/domain/utils/ImageUtils.ts +6 -0
  27. package/src/layouts/AppHeader/AppHeader.tsx +13 -3
  28. package/src/layouts/Container/Container.tsx +19 -1
  29. package/src/layouts/FormLayout/FormLayout.tsx +20 -1
  30. package/src/layouts/Grid/Grid.tsx +34 -4
  31. package/src/layouts/ScreenHeader/ScreenHeader.tsx +4 -0
  32. package/src/layouts/ScreenLayout/ScreenLayout.tsx +42 -3
  33. package/src/molecules/SearchBar/SearchBar.tsx +27 -23
  34. package/src/molecules/action-footer/ActionFooter.tsx +32 -31
  35. package/src/molecules/alerts/AlertService.ts +60 -15
  36. package/src/molecules/avatar/Avatar.tsx +3 -3
  37. package/src/molecules/avatar/AvatarGroup.tsx +7 -7
  38. package/src/molecules/calendar/infrastructure/utils/DateUtilities.ts +12 -1
  39. package/src/molecules/calendar/presentation/components/CalendarDayCell.tsx +48 -32
  40. package/src/molecules/info-grid/InfoGrid.tsx +5 -3
  41. package/src/organisms/FormContainer.tsx +11 -1
  42. package/src/tanstack/domain/utils/ErrorHelpers.ts +2 -2
  43. package/src/tanstack/domain/utils/MetricsCalculator.ts +6 -1
  44. package/src/theme/core/colors/ColorUtils.ts +7 -4
  45. package/src/utils/formatters/stringFormatter.ts +18 -3
  46. package/src/utils/index.ts +6 -4
  47. package/src/utils/math/CalculationUtils.ts +10 -1
@@ -12,7 +12,7 @@ import type { SearchBarProps } from './types';
12
12
  import { calculateResponsiveSize } from '../../responsive';
13
13
  import { MISC_SIZES } from '../../constants';
14
14
 
15
- export const SearchBar: React.FC<SearchBarProps> = ({
15
+ export const SearchBar: React.FC<SearchBarProps> = React.memo(({
16
16
  value,
17
17
  onChangeText,
18
18
  onSubmit,
@@ -22,8 +22,8 @@ export const SearchBar: React.FC<SearchBarProps> = ({
22
22
  placeholder = 'Search...',
23
23
  loading = false,
24
24
  disabled = false,
25
- containerStyle,
26
- inputStyle,
25
+ containerStyle: propContainerStyle,
26
+ inputStyle: propInputStyle,
27
27
  testID,
28
28
  }) => {
29
29
  const tokens = useAppDesignTokens();
@@ -42,19 +42,30 @@ export const SearchBar: React.FC<SearchBarProps> = ({
42
42
 
43
43
  const spacingMultiplier = tokens.spacingMultiplier;
44
44
 
45
+ const containerStyle = useMemo(() => [
46
+ styles.container,
47
+ {
48
+ backgroundColor: tokens.colors.surfaceVariant,
49
+ borderColor: tokens.colors.border,
50
+ height: calculateResponsiveSize(MISC_SIZES.searchInputHeight, spacingMultiplier),
51
+ paddingHorizontal: calculateResponsiveSize(tokens.spacing.md, spacingMultiplier),
52
+ borderRadius: calculateResponsiveSize(MISC_SIZES.searchBorderRadius, spacingMultiplier),
53
+ },
54
+ propContainerStyle,
55
+ ], [tokens.colors.surfaceVariant, tokens.colors.border, spacingMultiplier, propContainerStyle]);
56
+
57
+ const inputTextStyle = useMemo(() => [
58
+ styles.input,
59
+ {
60
+ color: tokens.colors.textPrimary,
61
+ fontSize: tokens.typography.bodyMedium.responsiveFontSize,
62
+ },
63
+ propInputStyle,
64
+ ], [styles.input, tokens.colors.textPrimary, tokens.typography.bodyMedium.responsiveFontSize, propInputStyle]);
65
+
45
66
  return (
46
67
  <View
47
- style={[
48
- styles.container,
49
- {
50
- backgroundColor: tokens.colors.surfaceVariant,
51
- borderColor: tokens.colors.border,
52
- height: calculateResponsiveSize(MISC_SIZES.searchInputHeight, spacingMultiplier),
53
- paddingHorizontal: calculateResponsiveSize(tokens.spacing.md, spacingMultiplier),
54
- borderRadius: calculateResponsiveSize(MISC_SIZES.searchBorderRadius, spacingMultiplier),
55
- },
56
- containerStyle,
57
- ]}
68
+ style={containerStyle}
58
69
  testID={testID}
59
70
  >
60
71
  <View style={styles.searchIcon}>
@@ -77,14 +88,7 @@ export const SearchBar: React.FC<SearchBarProps> = ({
77
88
  returnKeyType="search"
78
89
  autoCapitalize="none"
79
90
  autoCorrect={false}
80
- style={[
81
- styles.input,
82
- {
83
- color: tokens.colors.textPrimary,
84
- fontSize: tokens.typography.bodyMedium.responsiveFontSize,
85
- },
86
- inputStyle,
87
- ]}
91
+ style={inputTextStyle}
88
92
  />
89
93
 
90
94
  {(loading || showClear) && (
@@ -116,7 +120,7 @@ export const SearchBar: React.FC<SearchBarProps> = ({
116
120
  )}
117
121
  </View>
118
122
  );
119
- };
123
+ });
120
124
 
121
125
  const styles = StyleSheet.create({
122
126
  container: {
@@ -58,38 +58,39 @@ export const ActionFooter = React.memo<ActionFooterProps>(({
58
58
  const tokens = useAppDesignTokens();
59
59
  const spacingMultiplier = tokens.spacingMultiplier;
60
60
 
61
- const baseStyles = createStyles(spacingMultiplier);
62
-
63
61
  const themedStyles = useMemo(
64
- () => ({
65
- container: {
66
- ...baseStyles.container,
67
- paddingVertical: tokens.spacing.md,
68
- gap: tokens.spacing.md,
69
- },
70
- backButton: {
71
- ...baseStyles.backButton,
72
- borderRadius: tokens.borders.radius.lg,
73
- backgroundColor: tokens.colors.surface,
74
- borderColor: tokens.colors.outlineVariant,
75
- },
76
- actionButton: {
77
- ...baseStyles.actionButton,
78
- borderRadius: tokens.borders.radius.lg,
79
- },
80
- actionContent: {
81
- ...baseStyles.actionContent,
82
- backgroundColor: tokens.colors.primary,
83
- gap: tokens.spacing.sm,
84
- paddingHorizontal: tokens.spacing.lg,
85
- },
86
- actionText: {
87
- ...baseStyles.actionText,
88
- color: tokens.colors.onPrimary,
89
- fontSize: calculateResponsiveSize(18, spacingMultiplier),
90
- },
91
- }),
92
- [baseStyles, tokens, spacingMultiplier],
62
+ () => {
63
+ const baseStyles = createStyles(spacingMultiplier);
64
+ return {
65
+ container: {
66
+ ...baseStyles.container,
67
+ paddingVertical: tokens.spacing.md,
68
+ gap: tokens.spacing.md,
69
+ },
70
+ backButton: {
71
+ ...baseStyles.backButton,
72
+ borderRadius: tokens.borders.radius.lg,
73
+ backgroundColor: tokens.colors.surface,
74
+ borderColor: tokens.colors.outlineVariant,
75
+ },
76
+ actionButton: {
77
+ ...baseStyles.actionButton,
78
+ borderRadius: tokens.borders.radius.lg,
79
+ },
80
+ actionContent: {
81
+ ...baseStyles.actionContent,
82
+ backgroundColor: tokens.colors.primary,
83
+ gap: tokens.spacing.sm,
84
+ paddingHorizontal: tokens.spacing.lg,
85
+ },
86
+ actionText: {
87
+ ...baseStyles.actionText,
88
+ color: tokens.colors.onPrimary,
89
+ fontSize: calculateResponsiveSize(18, spacingMultiplier),
90
+ },
91
+ };
92
+ },
93
+ [tokens, spacingMultiplier],
93
94
  );
94
95
 
95
96
  const handleBackPress = useCallback(() => {
@@ -7,6 +7,12 @@ import { Alert, AlertType, AlertMode, AlertOptions, AlertPosition } from './Aler
7
7
  import { useAlertStore } from './AlertStore';
8
8
 
9
9
  export class AlertService {
10
+ // Debouncing state
11
+ private static lastAlertTime = 0;
12
+ private static debounceDelay = 300; // ms
13
+ private static pendingAlertTimeout: ReturnType<typeof setTimeout> | null = null;
14
+ private static pendingAlert: { type: AlertType; mode: AlertMode; title: string; message?: string; options?: AlertOptions } | null = null;
15
+
10
16
  /**
11
17
  * Creates a base Alert object with defaults
12
18
  */
@@ -59,38 +65,71 @@ export class AlertService {
59
65
  return this.createAlert(AlertType.INFO, AlertMode.TOAST, title, message, options);
60
66
  }
61
67
 
68
+ /**
69
+ * Add alert with debouncing to prevent spam
70
+ */
71
+ private static addAlertDebounced(type: AlertType, mode: AlertMode, title: string, message?: string, options?: AlertOptions): string {
72
+ const now = Date.now();
73
+ const timeSinceLastAlert = now - this.lastAlertTime;
74
+
75
+ // Clear any pending alert
76
+ if (this.pendingAlertTimeout) {
77
+ clearTimeout(this.pendingAlertTimeout);
78
+ this.pendingAlertTimeout = null;
79
+ }
80
+
81
+ // If enough time has passed, show immediately
82
+ if (timeSinceLastAlert >= this.debounceDelay) {
83
+ const alert = this.createAlert(type, mode, title, message, options);
84
+ useAlertStore.getState().addAlert(alert);
85
+ this.lastAlertTime = now;
86
+ return alert.id;
87
+ }
88
+
89
+ // Otherwise, debounce and show the latest alert after delay
90
+ this.pendingAlert = { type, mode, title, message, options };
91
+ this.pendingAlertTimeout = setTimeout(() => {
92
+ if (this.pendingAlert) {
93
+ const alert = this.createAlert(
94
+ this.pendingAlert.type,
95
+ this.pendingAlert.mode,
96
+ this.pendingAlert.title,
97
+ this.pendingAlert.message,
98
+ this.pendingAlert.options
99
+ );
100
+ useAlertStore.getState().addAlert(alert);
101
+ this.lastAlertTime = Date.now();
102
+ this.pendingAlert = null;
103
+ this.pendingAlertTimeout = null;
104
+ }
105
+ }, this.debounceDelay);
106
+
107
+ // Return a placeholder ID (the real alert will be shown after debounce)
108
+ return `pending-${Date.now()}`;
109
+ }
110
+
62
111
  /**
63
112
  * Convenience methods to show alerts directly from outside React components
64
113
  * These access the Zustand store directly without requiring hooks
65
114
  */
66
115
  static success(title: string, message?: string, options?: AlertOptions): string {
67
- const alert = this.createSuccessAlert(title, message, options);
68
- useAlertStore.getState().addAlert(alert);
69
- return alert.id;
116
+ return this.addAlertDebounced(AlertType.SUCCESS, AlertMode.TOAST, title, message, options);
70
117
  }
71
118
 
72
119
  static error(title: string, message?: string, options?: AlertOptions): string {
73
- const alert = this.createErrorAlert(title, message, options);
74
- useAlertStore.getState().addAlert(alert);
75
- return alert.id;
120
+ return this.addAlertDebounced(AlertType.ERROR, AlertMode.TOAST, title, message, options);
76
121
  }
77
122
 
78
123
  static warning(title: string, message?: string, options?: AlertOptions): string {
79
- const alert = this.createWarningAlert(title, message, options);
80
- useAlertStore.getState().addAlert(alert);
81
- return alert.id;
124
+ return this.addAlertDebounced(AlertType.WARNING, AlertMode.TOAST, title, message, options);
82
125
  }
83
126
 
84
127
  static info(title: string, message?: string, options?: AlertOptions): string {
85
- const alert = this.createInfoAlert(title, message, options);
86
- useAlertStore.getState().addAlert(alert);
87
- return alert.id;
128
+ return this.addAlertDebounced(AlertType.INFO, AlertMode.TOAST, title, message, options);
88
129
  }
89
130
 
90
131
  static show(type: AlertType, mode: AlertMode, title: string, message?: string, options?: AlertOptions): string {
91
- const alert = this.createAlert(type, mode, title, message, options);
92
- useAlertStore.getState().addAlert(alert);
93
- return alert.id;
132
+ return this.addAlertDebounced(type, mode, title, message, options);
94
133
  }
95
134
 
96
135
  static dismiss(id: string): void {
@@ -98,6 +137,12 @@ export class AlertService {
98
137
  }
99
138
 
100
139
  static clear(): void {
140
+ // Clear any pending alert
141
+ if (this.pendingAlertTimeout) {
142
+ clearTimeout(this.pendingAlertTimeout);
143
+ this.pendingAlertTimeout = null;
144
+ this.pendingAlert = null;
145
+ }
101
146
  useAlertStore.getState().clearAlerts();
102
147
  }
103
148
  }
@@ -48,7 +48,7 @@ const AvatarContent: React.FC<AvatarContentProps> = React.memo(({
48
48
  icon,
49
49
  config,
50
50
  borderRadius,
51
- imageStyle,
51
+ imageStyle: propImageStyle,
52
52
  }) => {
53
53
  const tokens = useAppDesignTokens();
54
54
 
@@ -59,8 +59,8 @@ const AvatarContent: React.FC<AvatarContentProps> = React.memo(({
59
59
  height: config.size,
60
60
  borderRadius,
61
61
  },
62
- imageStyle,
63
- ], [config.size, borderRadius, imageStyle]);
62
+ propImageStyle,
63
+ ], [config.size, borderRadius, propImageStyle]);
64
64
 
65
65
  const initialsStyle = useMemo(() => [
66
66
  styles.initials,
@@ -58,13 +58,13 @@ const AvatarItem = React.memo<{
58
58
  spacing: number;
59
59
  avatarStyle: any;
60
60
  }>(({ item, index, size, shape, spacing, avatarStyle }) => {
61
- const wrapperStyle = useMemo(
62
- () => [
63
- styles.avatarWrapper,
64
- index > 0 && { marginLeft: spacing },
65
- ],
66
- [index, spacing]
67
- );
61
+ const wrapperStyle = useMemo(() => {
62
+ const baseStyle = [styles.avatarWrapper];
63
+ if (index > 0) {
64
+ baseStyle.push({ marginLeft: spacing });
65
+ }
66
+ return baseStyle;
67
+ }, [index, spacing]);
68
68
 
69
69
  return (
70
70
  <View style={wrapperStyle}>
@@ -96,7 +96,18 @@ export class DateUtilities {
96
96
  const year = parts[0] ?? 0;
97
97
  const month = parts[1] ?? 1;
98
98
  const day = parts[2] ?? 1;
99
- return new Date(year, month - 1, day);
99
+
100
+ const date = new Date(year, month - 1, day);
101
+
102
+ // Validate the date is not invalid
103
+ if (isNaN(date.getTime())) {
104
+ if (__DEV__) {
105
+ console.warn(`[DateUtilities] Invalid date string: ${dateString}`);
106
+ }
107
+ throw new Error(`Invalid date string: ${dateString}`);
108
+ }
109
+
110
+ return date;
100
111
  }
101
112
 
102
113
  /**
@@ -2,7 +2,7 @@
2
2
  * Calendar Day Cell Component
3
3
  */
4
4
 
5
- import React from 'react';
5
+ import React, { useMemo } from 'react';
6
6
  import { TouchableOpacity, View, StyleProp, ViewStyle } from 'react-native';
7
7
  import { AtomicText } from '../../../../atoms';
8
8
  import { useAppDesignTokens } from '../../../../theme/hooks/useAppDesignTokens';
@@ -38,22 +38,34 @@ export const CalendarDayCell: React.FC<CalendarDayCellProps> = React.memo(({
38
38
  const visibleEvents = day.events.slice(0, maxEventIndicators);
39
39
  const hiddenEventCount = Math.max(0, eventCount - maxEventIndicators);
40
40
 
41
+ const cellStyle = useMemo(() => [
42
+ calendarStyles.dayCell,
43
+ {
44
+ backgroundColor: isSelected ? tokens.colors.primary : 'transparent',
45
+ borderColor: isSelected
46
+ ? tokens.colors.primary
47
+ : day.isToday
48
+ ? tokens.colors.primary
49
+ : tokens.colors.border,
50
+ borderWidth: isSelected ? 2 : day.isToday ? 2 : 1,
51
+ opacity: day.isDisabled ? 0.4 : 1,
52
+ },
53
+ dayStyle,
54
+ ], [isSelected, day.isToday, day.isDisabled, tokens.colors.primary, tokens.colors.border, dayStyle]);
55
+
56
+ const dayTextStyle = useMemo(() => [
57
+ calendarStyles.dayText,
58
+ day.isToday && !isSelected && { fontWeight: 'bold' as const },
59
+ ], [day.isToday, isSelected]);
60
+
61
+ const todayDotStyle = useMemo(() => [
62
+ calendarStyles.eventDot,
63
+ { backgroundColor: tokens.colors.success },
64
+ ], [calendarStyles.eventDot, tokens.colors.success]);
65
+
41
66
  return (
42
67
  <TouchableOpacity
43
- style={[
44
- calendarStyles.dayCell,
45
- {
46
- backgroundColor: isSelected ? tokens.colors.primary : 'transparent',
47
- borderColor: isSelected
48
- ? tokens.colors.primary
49
- : day.isToday
50
- ? tokens.colors.primary
51
- : tokens.colors.border,
52
- borderWidth: isSelected ? 2 : day.isToday ? 2 : 1,
53
- opacity: day.isDisabled ? 0.4 : 1,
54
- },
55
- dayStyle,
56
- ]}
68
+ style={cellStyle}
57
69
  onPress={() => !day.isDisabled && onDateSelect(day.date)}
58
70
  disabled={day.isDisabled}
59
71
  testID={testID ? `${testID}-day-${index}` : undefined}
@@ -64,31 +76,35 @@ export const CalendarDayCell: React.FC<CalendarDayCellProps> = React.memo(({
64
76
  <AtomicText
65
77
  type="bodyMedium"
66
78
  color={isSelected ? 'inverse' : day.isCurrentMonth ? 'primary' : 'secondary'}
67
- style={[calendarStyles.dayText, day.isToday && !isSelected && { fontWeight: 'bold' }]}
79
+ style={dayTextStyle}
68
80
  >
69
81
  {day.date.getDate()}
70
82
  </AtomicText>
71
83
 
72
84
  <View style={calendarStyles.eventIndicators}>
73
85
  {day.isToday && eventCount === 0 && (
74
- <View style={[calendarStyles.eventDot, { backgroundColor: tokens.colors.success }]} />
86
+ <View style={todayDotStyle} />
75
87
  )}
76
88
 
77
- {visibleEvents.map((event) => (
78
- <View
79
- key={event.id}
80
- style={[
81
- calendarStyles.eventDot,
82
- {
83
- backgroundColor: event.color
84
- ? event.color
85
- : event.isCompleted
86
- ? tokens.colors.success
87
- : tokens.colors.primary,
88
- },
89
- ]}
90
- />
91
- ))}
89
+ {visibleEvents.map((event) => {
90
+ const eventDotStyle = useMemo(() => [
91
+ calendarStyles.eventDot,
92
+ {
93
+ backgroundColor: event.color
94
+ ? event.color
95
+ : event.isCompleted
96
+ ? tokens.colors.success
97
+ : tokens.colors.primary,
98
+ },
99
+ ], [event.color, event.isCompleted, tokens.colors.success, tokens.colors.primary]);
100
+
101
+ return (
102
+ <View
103
+ key={event.id}
104
+ style={eventDotStyle}
105
+ />
106
+ );
107
+ })}
92
108
 
93
109
  {showEventCount && hiddenEventCount > 0 && (
94
110
  <AtomicText type="bodySmall" color="secondary" style={calendarStyles.moreEventsText}>
@@ -8,7 +8,7 @@ import type { InfoGridProps } from './types';
8
8
  import { calculateResponsiveSize } from '../../responsive';
9
9
  import { INFO_GRID_ICONS } from '../../constants';
10
10
 
11
- export const InfoGrid: React.FC<InfoGridProps> = ({
11
+ export const InfoGrid: React.FC<InfoGridProps> = React.memo(({
12
12
  title,
13
13
  headerIcon,
14
14
  items,
@@ -73,6 +73,8 @@ export const InfoGrid: React.FC<InfoGridProps> = ({
73
73
  },
74
74
  }), [tokens, columns, spacingMultiplier]);
75
75
 
76
+ const memoizedItemStyle = useMemo(() => itemStyle, [itemStyle]);
77
+
76
78
  return (
77
79
  <View style={[styles.container, style]}>
78
80
  {(title || headerIcon) && (
@@ -88,7 +90,7 @@ export const InfoGrid: React.FC<InfoGridProps> = ({
88
90
 
89
91
  <View style={styles.grid}>
90
92
  {items.map((item) => (
91
- <View key={item.text} style={[styles.item, itemStyle]}>
93
+ <View key={item.text} style={[styles.item, memoizedItemStyle]}>
92
94
  {item.icon && (
93
95
  <View style={styles.iconContainer}>
94
96
  <AtomicIcon name={item.icon} size="xs" color="primary" />
@@ -102,4 +104,4 @@ export const InfoGrid: React.FC<InfoGridProps> = ({
102
104
  </View>
103
105
  </View>
104
106
  );
105
- };
107
+ });
@@ -97,6 +97,9 @@ export const FormContainer: React.FC<FormContainerProps> = ({
97
97
  showsVerticalScrollIndicator = false,
98
98
  testID,
99
99
  showBorder = true,
100
+ accessibilityLabel,
101
+ accessibilityHint,
102
+ accessible,
100
103
  }) => {
101
104
  const tokens = useAppDesignTokens();
102
105
  const insets = useSafeAreaInsets();
@@ -138,7 +141,14 @@ export const FormContainer: React.FC<FormContainerProps> = ({
138
141
  );
139
142
 
140
143
  return (
141
- <View style={[styles.container, containerStyle]} testID={testID}>
144
+ <View
145
+ style={[styles.container, containerStyle]}
146
+ testID={testID}
147
+ accessibilityLabel={accessibilityLabel}
148
+ accessibilityHint={accessibilityHint}
149
+ accessible={accessible !== false}
150
+ accessibilityRole="form"
151
+ >
142
152
  <View style={styles.surface}>
143
153
  <ScrollView
144
154
  style={styles.scrollView}
@@ -146,8 +146,8 @@ export function getErrorCode(error: unknown): string | null {
146
146
  /**
147
147
  * Log error in development
148
148
  */
149
- export function logError(_context: string, _error: unknown): void {
149
+ export function logError(context: string, error: unknown): void {
150
150
  if (__DEV__) {
151
-
151
+ console.error(`[${context}]`, error);
152
152
  }
153
153
  }
@@ -22,7 +22,12 @@ export class MetricsCalculator {
22
22
  * Calculates fetch time for a query
23
23
  */
24
24
  static calculateFetchTime(query: Query): number {
25
- return Date.now() - (query.state.dataUpdatedAt ?? Date.now());
25
+ const now = Date.now();
26
+ const updatedAt = query.state.dataUpdatedAt ?? now;
27
+ const fetchTime = now - updatedAt;
28
+
29
+ // Ensure non-negative (handles cases where dataUpdatedAt is in the future)
30
+ return Math.max(0, fetchTime);
26
31
  }
27
32
 
28
33
  /**
@@ -34,10 +34,13 @@ export const withAlpha = (hexColor: string, alpha: number): string => {
34
34
  return hexColor;
35
35
  }
36
36
 
37
- // Convert 3-digit hex to 6-digit
38
- const hex = hexColor.length === 4
39
- ? hexColor.split('').map(c => c + c).join('')
40
- : hexColor;
37
+ let hex = hexColor;
38
+
39
+ // Convert 3-digit hex to 6-digit (e.g., #RGB #RRGGBB)
40
+ if (hex.length === 4) {
41
+ // Remove # and double each character, then add # back
42
+ hex = '#' + hex.slice(1).split('').map(c => c + c).join('');
43
+ }
41
44
 
42
45
  const alphaHex = Math.round(alpha * 255)
43
46
  .toString(16)
@@ -22,10 +22,19 @@ export function formatFileSize(bytes: number, options: FileSizeFormatOptions = {
22
22
  const { decimals = 1, locale = 'en-US' } = options;
23
23
 
24
24
  if (bytes === 0) return '0 Bytes';
25
+ if (bytes < 0) {
26
+ if (__DEV__) {
27
+ console.warn(`[formatFileSize] File size cannot be negative (received: ${bytes}), treating as 0`);
28
+ }
29
+ return '0 Bytes';
30
+ }
25
31
 
26
32
  const k = 1024;
27
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
28
- const i = Math.floor(Math.log(bytes) / Math.log(k));
33
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB']; // Added EB for safety
34
+ const i = Math.min(
35
+ Math.floor(Math.log(bytes) / Math.log(k)),
36
+ sizes.length - 1 // Prevent array out of bounds
37
+ );
29
38
 
30
39
  return `${formatNumber(bytes / Math.pow(k, i), { decimals, locale })} ${sizes[i]}`;
31
40
  }
@@ -130,10 +139,16 @@ export function formatPhone(phone: string, options: PhoneFormatOptions = {}): st
130
139
  * @returns Truncated text
131
140
  */
132
141
  export function truncateText(text: string, maxLength: number, suffix: string = '...'): string {
133
- if (!text || text.length <= maxLength) {
142
+ if (!text) return '';
143
+ if (text.length <= maxLength) {
134
144
  return text;
135
145
  }
136
146
 
147
+ // Ensure we don't end up with negative slice length
148
+ if (maxLength <= suffix.length) {
149
+ return suffix.slice(0, maxLength);
150
+ }
151
+
137
152
  return text.slice(0, maxLength - suffix.length) + suffix;
138
153
  }
139
154
 
@@ -118,10 +118,9 @@ export {
118
118
  type AsyncOperationState,
119
119
  type AsyncOperationActions,
120
120
  type AsyncOperationReturn,
121
+ type ErrorHandler as AsyncErrorHandler,
121
122
  } from './hooks';
122
123
 
123
- export type { ErrorHandler as AsyncErrorHandler } from './hooks';
124
-
125
124
  // =============================================================================
126
125
  // ERROR HANDLING
127
126
  // =============================================================================
@@ -130,8 +129,11 @@ export {
130
129
  DesignSystemError,
131
130
  ErrorCodes,
132
131
  ErrorCategory,
133
- type ErrorCode,
134
- type ErrorMetadata,
132
+ } from './errors';
133
+
134
+ export type {
135
+ ErrorCode,
136
+ ErrorMetadata,
135
137
  } from './errors';
136
138
 
137
139
  export { ErrorHandler } from './errors/ErrorHandler';
@@ -109,5 +109,14 @@ export function mapRange(
109
109
  outMin: number,
110
110
  outMax: number
111
111
  ): number {
112
- return ((value - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
112
+ const range = inMax - inMin;
113
+ if (range === 0) {
114
+ // When input range is zero, return output minimum
115
+ // This prevents division by zero (Infinity/NaN)
116
+ if (__DEV__) {
117
+ console.warn(`[mapRange] Input range is zero (inMin=${inMin}, inMax=${inMax}), returning outMin=${outMin}`);
118
+ }
119
+ return outMin;
120
+ }
121
+ return ((value - inMin) * (outMax - outMin)) / range + outMin;
113
122
  }