fix: update form
This commit is contained in:
1
src/shared/lib/clickOutside/index.ts
Normal file
1
src/shared/lib/clickOutside/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { useClickOutside } from './useClickOutside';
|
||||
28
src/shared/lib/clickOutside/useClickOutside.tsx
Normal file
28
src/shared/lib/clickOutside/useClickOutside.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { RefObject, useEffect } from 'react';
|
||||
|
||||
export function useClickOutside(
|
||||
ref: RefObject<HTMLDivElement | null>,
|
||||
fn: (event: Event) => void,
|
||||
) {
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: Event) => {
|
||||
const el = ref?.current;
|
||||
if (event instanceof MouseEvent && window !== undefined) {
|
||||
const x = event?.offsetX || 0;
|
||||
const width = window?.innerWidth - 18;
|
||||
if (x >= width) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!el || el.contains((event?.target as Node) || null)) {
|
||||
return;
|
||||
}
|
||||
fn(event);
|
||||
};
|
||||
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside);
|
||||
};
|
||||
}, [ref, fn]);
|
||||
}
|
||||
15
src/shared/lib/detectIOS/detectIOS.ts
Normal file
15
src/shared/lib/detectIOS/detectIOS.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
function detectIOS() {
|
||||
const iosQuirkPresent = () => {
|
||||
const audio = new Audio();
|
||||
audio.volume = 0.5;
|
||||
return audio.volume === 1; // volume cannot be changed from "1" on iOS 12 and below
|
||||
};
|
||||
|
||||
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
|
||||
const isAppleDevice = navigator.userAgent.includes('Macintosh');
|
||||
const isTouchScreen = navigator.maxTouchPoints >= 1; // true for iOS 13 (and hopefully beyond)
|
||||
|
||||
return isIOS || (isAppleDevice && (isTouchScreen || iosQuirkPresent()));
|
||||
}
|
||||
|
||||
export { detectIOS };
|
||||
1
src/shared/lib/detectIOS/index.ts
Normal file
1
src/shared/lib/detectIOS/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { detectIOS } from './detectIOS';
|
||||
2
src/shared/lib/index.ts
Normal file
2
src/shared/lib/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { useClickOutside } from './clickOutside';
|
||||
export { detectIOS } from './detectIOS';
|
||||
Reference in New Issue
Block a user