Created MenuLayout test

This commit is contained in:
Alejandro Celaya
2021-02-28 09:28:46 +01:00
parent d7edd69e60
commit 25e53bf627
6 changed files with 94 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
import { useState, useRef } from 'react';
import { useSwipeable as useReactSwipeable } from 'react-swipeable';
const DEFAULT_DELAY = 2000;
@@ -30,3 +31,23 @@ export const useToggle = (initialValue = false): ToggleResult => {
return [ flag, () => setFlag(!flag), () => setFlag(true), () => setFlag(false) ];
};
export const useSwipeable = (showSidebar: () => void, hideSidebar: () => void) => {
const swipeMenuIfNoModalExists = (callback: () => void) => (e: any) => {
const swippedOnVisitsTable = (e.event.composedPath() as HTMLElement[]).some(
({ classList }) => classList?.contains('visits-table'),
);
if (swippedOnVisitsTable || document.querySelector('.modal')) {
return;
}
callback();
};
return useReactSwipeable({
delta: 40,
onSwipedLeft: swipeMenuIfNoModalExists(hideSidebar),
onSwipedRight: swipeMenuIfNoModalExists(showSidebar),
});
};