@@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
4
4
5
5
export type SizeType = 'sm' | 'md' | 'lg' | 'xl' | '2xl' ;
6
6
7
- const getBreakpointFromSize = ( breakpoint : SizeType | number ) => {
7
+ export const getBreakpointFromSize = ( breakpoint : SizeType | number ) => {
8
8
switch ( breakpoint ) {
9
9
case 'sm' :
10
10
return 640 ;
@@ -21,7 +21,7 @@ const getBreakpointFromSize = (breakpoint: SizeType | number) => {
21
21
}
22
22
} ;
23
23
24
- const checkIsMobileUserAgent = ( ) : boolean | undefined => {
24
+ export const checkIsMobileUserAgent = ( ) : boolean | undefined => {
25
25
if ( typeof window === 'undefined' ) return ;
26
26
27
27
const userAgent = window . navigator ?. userAgent ;
@@ -33,7 +33,25 @@ const checkIsMobileUserAgent = (): boolean | undefined => {
33
33
) ;
34
34
} ;
35
35
36
- const checkIsMobileScreen = ( breakpoint : number ) : boolean | undefined => {
36
+ export const checkIsIphoneOrSafariDevice = ( ) : boolean | undefined => {
37
+ if ( typeof window === 'undefined' ) return ;
38
+
39
+ const userAgent = window . navigator ?. userAgent ;
40
+
41
+ /* 1 . is it Safari? (Chrome & co. also contain “Safari/…”, so exclude them) */
42
+ const isSafari =
43
+ / S a f a r i \/ \d / i. test ( userAgent ) && // has “Safari/xxx”
44
+ ! / C h r o m e | C r i O S | F x i O S | E d g | O P R / i. test ( userAgent ) ; // …but not the other browsers
45
+
46
+ /* 2. is it an Apple device? (macOS or iOS/iPadOS) */
47
+ const isAppleDevice = / M a c i n t o s h | i P (?: h o n e | a d | o d ) / . test ( userAgent ) ;
48
+
49
+ return isSafari && isAppleDevice ; // true for mac-Safari & iOS-Safari
50
+ } ;
51
+
52
+ export const checkIsMobileScreen = (
53
+ breakpoint : number
54
+ ) : boolean | undefined => {
37
55
if ( typeof window === 'undefined' ) return ;
38
56
39
57
return ( window ?. innerWidth ?? 0 ) <= breakpoint ;
@@ -45,7 +63,7 @@ type UseDeviceState = {
45
63
isMobile : boolean | undefined ;
46
64
} ;
47
65
48
- const calculateIsMobile = ( breakpoint : SizeType | number ) => {
66
+ export const calculateIsMobile = ( breakpoint : SizeType | number = 'md' ) => {
49
67
const breakpointValue = getBreakpointFromSize ( breakpoint ) ;
50
68
51
69
const isMobileUserAgent = checkIsMobileUserAgent ( ) ;
0 commit comments