@umituz/react-native-design-system 2.6.12 → 2.6.14
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/device/detection/deviceDetection.ts +55 -29
- package/src/device/detection/iPadDetection.ts +11 -11
- package/src/device/detection/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/layouts/ScreenLayout/ScreenLayout.tsx +3 -5
- package/src/responsive/config.ts +3 -3
- package/src/responsive/gridUtils.ts +4 -4
- package/src/responsive/responsiveLayout.ts +15 -10
- package/src/responsive/responsiveModal.ts +7 -11
- package/src/responsive/responsiveSizing.ts +17 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-design-system",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.14",
|
|
4
4
|
"description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive and safe area utilities",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Device Detection Utilities
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Uses expo-device for primary device type detection (PHONE vs TABLET)
|
|
5
|
+
* and screen dimensions for secondary distinctions (small vs large phone).
|
|
6
|
+
*
|
|
7
|
+
* Benefits:
|
|
8
|
+
* - expo-device uses system-level detection on iOS (100% reliable)
|
|
9
|
+
* - Uses screen diagonal on Android (more accurate than pixels)
|
|
10
|
+
* - Future-proof: new devices automatically detected correctly
|
|
6
11
|
*/
|
|
7
12
|
|
|
8
13
|
import { Dimensions } from 'react-native';
|
|
14
|
+
import * as Device from 'expo-device';
|
|
15
|
+
import { DeviceType as ExpoDeviceType } from 'expo-device';
|
|
9
16
|
import { DEVICE_BREAKPOINTS, LAYOUT_CONSTANTS } from '../../responsive/config';
|
|
10
17
|
import { validateScreenDimensions } from '../../responsive/validation';
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
20
|
* Helper function for device detection with fallback
|
|
14
|
-
* @param operation - Operation to perform
|
|
15
|
-
* @param fallback - Fallback value if operation fails
|
|
16
|
-
* @returns Operation result or fallback
|
|
17
21
|
*/
|
|
18
22
|
const withDeviceDetectionFallback = <T>(
|
|
19
23
|
operation: () => T,
|
|
@@ -28,6 +32,7 @@ const withDeviceDetectionFallback = <T>(
|
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* Device type enum for conditional rendering
|
|
35
|
+
* Used for fine-grained phone size distinctions
|
|
31
36
|
*/
|
|
32
37
|
export enum DeviceType {
|
|
33
38
|
SMALL_PHONE = 'SMALL_PHONE',
|
|
@@ -38,8 +43,6 @@ export enum DeviceType {
|
|
|
38
43
|
|
|
39
44
|
/**
|
|
40
45
|
* Get current screen dimensions
|
|
41
|
-
* @returns Screen width and height
|
|
42
|
-
* @throws ResponsiveValidationError if dimensions are invalid
|
|
43
46
|
*/
|
|
44
47
|
export const getScreenDimensions = () => {
|
|
45
48
|
const { width, height } = Dimensions.get('window');
|
|
@@ -48,18 +51,40 @@ export const getScreenDimensions = () => {
|
|
|
48
51
|
validateScreenDimensions(width, height);
|
|
49
52
|
return { width, height };
|
|
50
53
|
} catch {
|
|
51
|
-
// Fallback to safe default dimensions
|
|
52
54
|
return { width: 414, height: 896 };
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
/**
|
|
57
|
-
* Check if current device is a
|
|
58
|
-
*
|
|
59
|
+
* Check if current device is a tablet
|
|
60
|
+
* Uses expo-device for accurate system-level detection
|
|
61
|
+
*/
|
|
62
|
+
export const isTablet = (): boolean => {
|
|
63
|
+
return withDeviceDetectionFallback(
|
|
64
|
+
() => Device.deviceType === ExpoDeviceType.TABLET,
|
|
65
|
+
false
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Check if current device is a phone
|
|
71
|
+
* Uses expo-device for accurate system-level detection
|
|
72
|
+
*/
|
|
73
|
+
export const isPhone = (): boolean => {
|
|
74
|
+
return withDeviceDetectionFallback(
|
|
75
|
+
() => Device.deviceType === ExpoDeviceType.PHONE,
|
|
76
|
+
true
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Check if current device is a small phone (iPhone SE, 13 mini)
|
|
82
|
+
* Uses width breakpoint within phone category
|
|
59
83
|
*/
|
|
60
84
|
export const isSmallPhone = (): boolean => {
|
|
61
85
|
return withDeviceDetectionFallback(
|
|
62
86
|
() => {
|
|
87
|
+
if (!isPhone()) return false;
|
|
63
88
|
const { width } = getScreenDimensions();
|
|
64
89
|
return width <= DEVICE_BREAKPOINTS.SMALL_PHONE;
|
|
65
90
|
},
|
|
@@ -68,14 +93,15 @@ export const isSmallPhone = (): boolean => {
|
|
|
68
93
|
};
|
|
69
94
|
|
|
70
95
|
/**
|
|
71
|
-
* Check if current device is a
|
|
72
|
-
*
|
|
96
|
+
* Check if current device is a large phone (Pro Max, Plus models)
|
|
97
|
+
* Uses width breakpoint within phone category
|
|
73
98
|
*/
|
|
74
|
-
export const
|
|
99
|
+
export const isLargePhone = (): boolean => {
|
|
75
100
|
return withDeviceDetectionFallback(
|
|
76
101
|
() => {
|
|
102
|
+
if (!isPhone()) return false;
|
|
77
103
|
const { width } = getScreenDimensions();
|
|
78
|
-
return width >= DEVICE_BREAKPOINTS.
|
|
104
|
+
return width >= DEVICE_BREAKPOINTS.MEDIUM_PHONE;
|
|
79
105
|
},
|
|
80
106
|
false
|
|
81
107
|
);
|
|
@@ -83,7 +109,6 @@ export const isTablet = (): boolean => {
|
|
|
83
109
|
|
|
84
110
|
/**
|
|
85
111
|
* Check if device is in landscape mode
|
|
86
|
-
* @returns true if device is in landscape orientation
|
|
87
112
|
*/
|
|
88
113
|
export const isLandscape = (): boolean => {
|
|
89
114
|
return withDeviceDetectionFallback(
|
|
@@ -96,47 +121,48 @@ export const isLandscape = (): boolean => {
|
|
|
96
121
|
};
|
|
97
122
|
|
|
98
123
|
/**
|
|
99
|
-
* Get current device type
|
|
100
|
-
*
|
|
124
|
+
* Get current device type with fine-grained phone distinctions
|
|
125
|
+
* Uses expo-device for PHONE vs TABLET, width for phone size variants
|
|
101
126
|
*/
|
|
102
127
|
export const getDeviceType = (): DeviceType => {
|
|
103
128
|
return withDeviceDetectionFallback(
|
|
104
129
|
() => {
|
|
130
|
+
// Use expo-device for primary detection
|
|
131
|
+
if (isTablet()) {
|
|
132
|
+
return DeviceType.TABLET;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// For phones, use width for size variants
|
|
105
136
|
const { width } = getScreenDimensions();
|
|
106
137
|
|
|
107
138
|
if (width <= DEVICE_BREAKPOINTS.SMALL_PHONE) {
|
|
108
139
|
return DeviceType.SMALL_PHONE;
|
|
109
140
|
} else if (width <= DEVICE_BREAKPOINTS.MEDIUM_PHONE) {
|
|
110
141
|
return DeviceType.MEDIUM_PHONE;
|
|
111
|
-
} else if (width <= DEVICE_BREAKPOINTS.LARGE_PHONE) {
|
|
112
|
-
return DeviceType.LARGE_PHONE;
|
|
113
142
|
}
|
|
114
143
|
|
|
115
|
-
return DeviceType.
|
|
144
|
+
return DeviceType.LARGE_PHONE;
|
|
116
145
|
},
|
|
117
146
|
DeviceType.MEDIUM_PHONE
|
|
118
147
|
);
|
|
119
148
|
};
|
|
120
149
|
|
|
121
150
|
/**
|
|
122
|
-
* Responsive spacing multiplier
|
|
123
|
-
* Returns a multiplier for spacing based on device size
|
|
124
|
-
*
|
|
125
|
-
* @returns Spacing multiplier (0.9-1.2)
|
|
151
|
+
* Responsive spacing multiplier based on device type
|
|
126
152
|
*/
|
|
127
153
|
export const getSpacingMultiplier = (): number => {
|
|
128
154
|
return withDeviceDetectionFallback(
|
|
129
155
|
() => {
|
|
130
|
-
|
|
156
|
+
if (isTablet()) {
|
|
157
|
+
return LAYOUT_CONSTANTS.SPACING_MULTIPLIER_TABLET;
|
|
158
|
+
}
|
|
131
159
|
|
|
132
|
-
if (
|
|
160
|
+
if (isSmallPhone()) {
|
|
133
161
|
return LAYOUT_CONSTANTS.SPACING_MULTIPLIER_SMALL;
|
|
134
|
-
} else if (width >= DEVICE_BREAKPOINTS.TABLET) {
|
|
135
|
-
return LAYOUT_CONSTANTS.SPACING_MULTIPLIER_TABLET;
|
|
136
162
|
}
|
|
137
163
|
|
|
138
164
|
return LAYOUT_CONSTANTS.SPACING_MULTIPLIER_STANDARD;
|
|
139
165
|
},
|
|
140
166
|
LAYOUT_CONSTANTS.SPACING_MULTIPLIER_STANDARD
|
|
141
167
|
);
|
|
142
|
-
};
|
|
168
|
+
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* iPad Device Detection Utilities
|
|
3
|
+
*
|
|
4
|
+
* Uses expo-device for system-level tablet detection,
|
|
5
|
+
* then uses screen dimensions for iPad-specific sub-categories.
|
|
3
6
|
*/
|
|
4
7
|
|
|
5
|
-
import { Dimensions
|
|
6
|
-
import { DEVICE_BREAKPOINTS } from '../../responsive/config';
|
|
8
|
+
import { Dimensions } from 'react-native';
|
|
7
9
|
import { IPAD_BREAKPOINTS } from './iPadBreakpoints';
|
|
10
|
+
import { isTablet, isLandscape } from './deviceDetection';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
|
-
* Detect if the current device is an iPad
|
|
13
|
+
* Detect if the current device is an iPad (or Android tablet)
|
|
14
|
+
* Uses expo-device for accurate system-level detection
|
|
11
15
|
*/
|
|
12
16
|
export function isIPad(): boolean {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const { width, height } = Dimensions.get('window');
|
|
16
|
-
const minDimension = Math.min(width, height);
|
|
17
|
-
return minDimension >= DEVICE_BREAKPOINTS.SMALL_TABLET;
|
|
17
|
+
return isTablet();
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -40,9 +40,9 @@ export function isIPadPro(): boolean {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* Check if device is in landscape orientation
|
|
43
|
+
* Check if tablet device is in landscape orientation
|
|
44
|
+
* Uses shared isLandscape detection for consistency
|
|
44
45
|
*/
|
|
45
46
|
export function isIPadLandscape(): boolean {
|
|
46
|
-
|
|
47
|
-
return width > height;
|
|
47
|
+
return isLandscape();
|
|
48
48
|
}
|
package/src/index.ts
CHANGED
|
@@ -29,8 +29,7 @@ import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
|
29
29
|
import type { Edge } from 'react-native-safe-area-context';
|
|
30
30
|
import { useAppDesignTokens } from '../../theme';
|
|
31
31
|
import { getResponsiveHorizontalPadding } from '../../responsive/responsiveLayout';
|
|
32
|
-
import {
|
|
33
|
-
import { DEVICE_BREAKPOINTS } from '../../responsive/config';
|
|
32
|
+
import { isTablet as checkIsTablet } from '../../device/detection';
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* NOTE: This component now works in conjunction with the SafeAreaProvider
|
|
@@ -162,11 +161,10 @@ export const ScreenLayout: React.FC<ScreenLayoutProps> = ({
|
|
|
162
161
|
// Automatically uses current theme from global store
|
|
163
162
|
const tokens = useAppDesignTokens();
|
|
164
163
|
const insets = useSafeAreaInsets();
|
|
165
|
-
const
|
|
166
|
-
const isTablet = screenWidth >= DEVICE_BREAKPOINTS.SMALL_TABLET;
|
|
164
|
+
const isTabletDevice = checkIsTablet();
|
|
167
165
|
|
|
168
166
|
// Only apply maxWidth for tablets - phones should fill full width
|
|
169
|
-
const finalMaxWidth = maxWidth || (responsiveEnabled &&
|
|
167
|
+
const finalMaxWidth = maxWidth || (responsiveEnabled && isTabletDevice ? 600 : undefined);
|
|
170
168
|
const horizontalPadding = responsiveEnabled ? getResponsiveHorizontalPadding(tokens.spacing.md, insets) : tokens.spacing.md;
|
|
171
169
|
|
|
172
170
|
const styles = useMemo(() => StyleSheet.create({
|
package/src/responsive/config.ts
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* These values determine when responsive behaviors change
|
|
11
11
|
*/
|
|
12
12
|
export const DEVICE_BREAKPOINTS = {
|
|
13
|
-
SMALL_PHONE: 375, // iPhone 13 mini
|
|
14
|
-
MEDIUM_PHONE: 414, // iPhone 13/14/15
|
|
15
|
-
LARGE_PHONE:
|
|
13
|
+
SMALL_PHONE: 375, // iPhone SE, iPhone 13 mini
|
|
14
|
+
MEDIUM_PHONE: 414, // iPhone 13/14/15 (390-393px actual)
|
|
15
|
+
LARGE_PHONE: 500, // iPhone 14/15 Pro Max (430px) - buffer for future devices
|
|
16
16
|
SMALL_TABLET: 768, // iPad mini
|
|
17
17
|
TABLET: 1024, // iPad Air and larger tablets
|
|
18
18
|
} as const;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Responsive grid sizing and column calculations
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { getScreenDimensions } from '../device/detection';
|
|
7
|
-
import {
|
|
6
|
+
import { getScreenDimensions, isTablet } from '../device/detection';
|
|
7
|
+
import { GRID_CONFIG } from './config';
|
|
8
8
|
import { validateNumber } from './validation';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -23,8 +23,8 @@ export const getResponsiveGridColumns = (
|
|
|
23
23
|
const validatedMobile = validateNumber(mobileColumns, 'mobileColumns', 1, 20);
|
|
24
24
|
const validatedTablet = validateNumber(tabletColumns, 'tabletColumns', 1, 20);
|
|
25
25
|
|
|
26
|
-
const
|
|
27
|
-
return
|
|
26
|
+
const isTabletDevice = isTablet();
|
|
27
|
+
return isTabletDevice ? validatedTablet : validatedMobile;
|
|
28
28
|
} catch {
|
|
29
29
|
return 2;
|
|
30
30
|
}
|
|
@@ -3,10 +3,16 @@
|
|
|
3
3
|
* Layout utilities for positioning and spacing.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { getScreenDimensions } from '../device/detection';
|
|
7
|
-
import {
|
|
6
|
+
import { getScreenDimensions, isTablet } from '../device/detection';
|
|
7
|
+
import { LAYOUT_CONSTANTS } from './config';
|
|
8
8
|
import { validateNumber, validateSafeAreaInsets } from './validation';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Check if device is tablet-sized (for responsive layouts)
|
|
12
|
+
* Uses expo-device based detection for accuracy
|
|
13
|
+
*/
|
|
14
|
+
const checkIsTabletSize = (): boolean => isTablet();
|
|
15
|
+
|
|
10
16
|
/**
|
|
11
17
|
* Responsive horizontal padding
|
|
12
18
|
*/
|
|
@@ -18,10 +24,10 @@ export const getResponsiveHorizontalPadding = (
|
|
|
18
24
|
const validatedBasePadding = validateNumber(basePadding, 'basePadding', 0, 100);
|
|
19
25
|
validateSafeAreaInsets(insets);
|
|
20
26
|
|
|
21
|
-
const { width } = getScreenDimensions();
|
|
22
27
|
const { left = 0, right = 0 } = insets;
|
|
28
|
+
const isTabletDevice = checkIsTabletSize();
|
|
23
29
|
|
|
24
|
-
if (
|
|
30
|
+
if (isTabletDevice) {
|
|
25
31
|
const tabletPadding = validatedBasePadding * 1.5;
|
|
26
32
|
return Math.max(
|
|
27
33
|
tabletPadding,
|
|
@@ -66,10 +72,10 @@ export const getResponsiveFABPosition = (
|
|
|
66
72
|
): { bottom: number; right: number } => {
|
|
67
73
|
try {
|
|
68
74
|
validateSafeAreaInsets(insets);
|
|
69
|
-
const { width } = getScreenDimensions();
|
|
70
75
|
const { bottom = 0, right = 0 } = insets;
|
|
76
|
+
const isTabletDevice = checkIsTabletSize();
|
|
71
77
|
|
|
72
|
-
if (
|
|
78
|
+
if (isTabletDevice) {
|
|
73
79
|
return {
|
|
74
80
|
bottom: Math.max(
|
|
75
81
|
LAYOUT_CONSTANTS.FAB_BOTTOM_TABLET,
|
|
@@ -133,10 +139,10 @@ export const getResponsiveTabBarHeight = (
|
|
|
133
139
|
): number => {
|
|
134
140
|
try {
|
|
135
141
|
validateSafeAreaInsets(insets);
|
|
136
|
-
const { width } = getScreenDimensions();
|
|
137
142
|
const { bottom = 0 } = insets;
|
|
143
|
+
const isTabletDevice = checkIsTabletSize();
|
|
138
144
|
|
|
139
|
-
const baseHeight =
|
|
145
|
+
const baseHeight = isTabletDevice
|
|
140
146
|
? TAB_BAR_CONSTANTS.BASE_HEIGHT_TABLET
|
|
141
147
|
: TAB_BAR_CONSTANTS.BASE_HEIGHT_PHONE;
|
|
142
148
|
|
|
@@ -156,9 +162,8 @@ export const getResponsiveTabBarConfig = (
|
|
|
156
162
|
): ResponsiveTabBarConfig => {
|
|
157
163
|
try {
|
|
158
164
|
validateSafeAreaInsets(insets);
|
|
159
|
-
const { width } = getScreenDimensions();
|
|
160
165
|
const { bottom = 0 } = insets;
|
|
161
|
-
const isTabletSize =
|
|
166
|
+
const isTabletSize = checkIsTabletSize();
|
|
162
167
|
|
|
163
168
|
const baseHeight = isTabletSize
|
|
164
169
|
? TAB_BAR_CONSTANTS.BASE_HEIGHT_TABLET
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Modal, bottom sheet, and dialog layout utilities.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { getScreenDimensions } from '../device/detection';
|
|
6
|
+
import { getScreenDimensions, isTablet } from '../device/detection';
|
|
7
7
|
import {
|
|
8
|
-
DEVICE_BREAKPOINTS,
|
|
9
8
|
LAYOUT_CONSTANTS,
|
|
10
9
|
HEIGHT_THRESHOLDS,
|
|
11
10
|
SIZE_CONSTRAINTS,
|
|
@@ -74,7 +73,7 @@ export const getResponsiveMinModalHeight = (): number => {
|
|
|
74
73
|
export const getResponsiveModalWidth = (): number => {
|
|
75
74
|
try {
|
|
76
75
|
const { width } = getScreenDimensions();
|
|
77
|
-
const isTabletDevice =
|
|
76
|
+
const isTabletDevice = isTablet();
|
|
78
77
|
|
|
79
78
|
const widthPercent = isTabletDevice
|
|
80
79
|
? MODAL_CONFIG.WIDTH_PERCENT_TABLET
|
|
@@ -92,8 +91,8 @@ export const getResponsiveModalWidth = (): number => {
|
|
|
92
91
|
|
|
93
92
|
export const getResponsiveModalHeight = (): number => {
|
|
94
93
|
try {
|
|
95
|
-
const {
|
|
96
|
-
const isTabletDevice =
|
|
94
|
+
const { height } = getScreenDimensions();
|
|
95
|
+
const isTabletDevice = isTablet();
|
|
97
96
|
|
|
98
97
|
if (isTabletDevice) {
|
|
99
98
|
return height * MODAL_CONFIG.HEIGHT_PERCENT_TABLET;
|
|
@@ -111,8 +110,7 @@ export const getResponsiveModalHeight = (): number => {
|
|
|
111
110
|
|
|
112
111
|
export const getResponsiveModalBorderRadius = (): number => {
|
|
113
112
|
try {
|
|
114
|
-
const
|
|
115
|
-
const isTabletDevice = width >= DEVICE_BREAKPOINTS.TABLET;
|
|
113
|
+
const isTabletDevice = isTablet();
|
|
116
114
|
|
|
117
115
|
return isTabletDevice
|
|
118
116
|
? MODAL_CONFIG.BORDER_RADIUS_TABLET
|
|
@@ -124,8 +122,7 @@ export const getResponsiveModalBorderRadius = (): number => {
|
|
|
124
122
|
|
|
125
123
|
export const getResponsiveModalMaxWidth = (): number => {
|
|
126
124
|
try {
|
|
127
|
-
const
|
|
128
|
-
const isTabletDevice = width >= DEVICE_BREAKPOINTS.TABLET;
|
|
125
|
+
const isTabletDevice = isTablet();
|
|
129
126
|
|
|
130
127
|
return isTabletDevice
|
|
131
128
|
? MODAL_CONFIG.MAX_WIDTH_TABLET
|
|
@@ -140,8 +137,7 @@ export const getResponsiveBackdropOpacity = (): number => {
|
|
|
140
137
|
};
|
|
141
138
|
|
|
142
139
|
export const getResponsiveModalLayout = (): ResponsiveModalLayout => {
|
|
143
|
-
const
|
|
144
|
-
const isTabletDevice = width >= DEVICE_BREAKPOINTS.TABLET;
|
|
140
|
+
const isTabletDevice = isTablet();
|
|
145
141
|
|
|
146
142
|
return {
|
|
147
143
|
width: getResponsiveModalWidth(),
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* Responsive sizing utilities for UI components.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { getScreenDimensions } from '../device/detection';
|
|
6
|
+
import { getScreenDimensions, isSmallPhone, isTablet } from '../device/detection';
|
|
7
7
|
import {
|
|
8
|
-
DEVICE_BREAKPOINTS,
|
|
9
8
|
RESPONSIVE_PERCENTAGES,
|
|
10
9
|
SIZE_CONSTRAINTS,
|
|
11
10
|
HEIGHT_THRESHOLDS,
|
|
@@ -27,11 +26,13 @@ export const getResponsiveLogoSize = (baseSize: number = 140): number => {
|
|
|
27
26
|
try {
|
|
28
27
|
const validatedBaseSize = validateNumber(baseSize, 'baseSize', 50, 500);
|
|
29
28
|
const { width } = getScreenDimensions();
|
|
29
|
+
const isSmallPhoneDevice = isSmallPhone();
|
|
30
|
+
const isTabletDevice = isTablet();
|
|
30
31
|
|
|
31
|
-
if (
|
|
32
|
+
if (isSmallPhoneDevice) {
|
|
32
33
|
const calculatedSize = safePercentage(width, RESPONSIVE_PERCENTAGES.LOGO_SMALL_PHONE_MAX);
|
|
33
34
|
return clamp(calculatedSize, SIZE_CONSTRAINTS.LOGO_MIN_SMALL, SIZE_CONSTRAINTS.LOGO_MAX_SMALL);
|
|
34
|
-
} else if (
|
|
35
|
+
} else if (isTabletDevice) {
|
|
35
36
|
const calculatedSize = safePercentage(width, RESPONSIVE_PERCENTAGES.LOGO_TABLET_MAX);
|
|
36
37
|
return clamp(calculatedSize, SIZE_CONSTRAINTS.LOGO_MIN_TABLET, SIZE_CONSTRAINTS.LOGO_MAX_TABLET);
|
|
37
38
|
}
|
|
@@ -73,11 +74,13 @@ export const getResponsiveIconContainerSize = (baseSize: number = 140): number =
|
|
|
73
74
|
try {
|
|
74
75
|
const validatedBaseSize = validateNumber(baseSize, 'baseSize', 50, 300);
|
|
75
76
|
const { width } = getScreenDimensions();
|
|
77
|
+
const isSmallPhoneDevice = isSmallPhone();
|
|
78
|
+
const isTabletDevice = isTablet();
|
|
76
79
|
|
|
77
|
-
if (
|
|
80
|
+
if (isSmallPhoneDevice) {
|
|
78
81
|
const calculatedSize = safePercentage(width, RESPONSIVE_PERCENTAGES.ICON_CONTAINER_SMALL_PHONE);
|
|
79
82
|
return Math.min(calculatedSize, SIZE_CONSTRAINTS.ICON_MAX_SMALL);
|
|
80
|
-
} else if (
|
|
83
|
+
} else if (isTabletDevice) {
|
|
81
84
|
const calculatedSize = safePercentage(width, RESPONSIVE_PERCENTAGES.ICON_CONTAINER_TABLET);
|
|
82
85
|
return Math.min(calculatedSize, SIZE_CONSTRAINTS.ICON_MAX_TABLET);
|
|
83
86
|
}
|
|
@@ -96,10 +99,12 @@ export const getResponsiveMaxWidth = (baseWidth: number = 400): number => {
|
|
|
96
99
|
try {
|
|
97
100
|
const validatedBaseWidth = validateNumber(baseWidth, 'baseWidth', 100, 1000);
|
|
98
101
|
const { width } = getScreenDimensions();
|
|
102
|
+
const isSmallPhoneDevice = isSmallPhone();
|
|
103
|
+
const isTabletDevice = isTablet();
|
|
99
104
|
|
|
100
|
-
if (
|
|
105
|
+
if (isSmallPhoneDevice) {
|
|
101
106
|
return safePercentage(width, RESPONSIVE_PERCENTAGES.CONTENT_SMALL_PHONE);
|
|
102
|
-
} else if (
|
|
107
|
+
} else if (isTabletDevice) {
|
|
103
108
|
const calculatedWidth = safePercentage(width, RESPONSIVE_PERCENTAGES.CONTENT_TABLET);
|
|
104
109
|
return Math.min(calculatedWidth, SIZE_CONSTRAINTS.CONTENT_MAX_TABLET);
|
|
105
110
|
}
|
|
@@ -118,12 +123,13 @@ export const getResponsiveMaxWidth = (baseWidth: number = 400): number => {
|
|
|
118
123
|
export const getResponsiveFontSize = (baseFontSize: number): number => {
|
|
119
124
|
try {
|
|
120
125
|
const validatedBaseSize = validateFontSize(baseFontSize);
|
|
121
|
-
const
|
|
126
|
+
const isSmallPhoneDevice = isSmallPhone();
|
|
127
|
+
const isTabletDevice = isTablet();
|
|
122
128
|
|
|
123
|
-
if (
|
|
129
|
+
if (isSmallPhoneDevice) {
|
|
124
130
|
const scaledSize = validatedBaseSize * RESPONSIVE_PERCENTAGES.FONT_SMALL_PHONE;
|
|
125
131
|
return Math.max(scaledSize, SIZE_CONSTRAINTS.FONT_MIN_SIZE);
|
|
126
|
-
} else if (
|
|
132
|
+
} else if (isTabletDevice) {
|
|
127
133
|
return validatedBaseSize * RESPONSIVE_PERCENTAGES.FONT_TABLET;
|
|
128
134
|
}
|
|
129
135
|
|