Total Complexity | 4 |
Complexity/F | 0 |
Lines of Code | 69 |
Function Count | 0 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
1 | 1 | import React from "react"; |
|
2 | 1 | import { useDispatch, useSelector } from "react-redux"; |
|
3 | |||
4 | import { AppConfig, ThemeField } from "../../types"; |
||
5 | |||
6 | 1 | import { |
|
7 | closeDrawer, |
||
8 | driveWithDarkMode, |
||
9 | isDrawerOpen, |
||
10 | } from "@cianciarusocataldo/modular-engine"; |
||
11 | |||
12 | 1 | import { Drawer } from "@cianciarusocataldo/modular-ui"; |
|
13 | |||
14 | 1 | const AppDrawer = ({ |
|
15 | 7 | logo, |
|
16 | 7 | children, |
|
17 | 7 | theme, |
|
18 | 7 | position, |
|
19 | }: { |
||
20 | logo?: () => JSX.Element; |
||
21 | theme: ThemeField; |
||
22 | children?: JSX.Element; |
||
23 | position?: AppConfig["drawer"]["position"]; |
||
24 | }) => { |
||
25 | 7 | const dispatch = useDispatch(); |
|
26 | 7 | const isDrawerShowing = useSelector(isDrawerOpen); |
|
27 | |||
28 | /* istanbul ignore next */ |
||
29 | React.useEffect(() => { |
||
30 | if (isDrawerShowing) { |
||
31 | let element = document.getElementById("modular-drawer"); |
||
32 | let app = document.getElementById("app-container"); |
||
33 | if (app) { |
||
34 | app.onclick = function (e: Event) { |
||
35 | if (element && !element.contains(e.target as Node)) { |
||
36 | dispatch(closeDrawer()); |
||
37 | } |
||
38 | }; |
||
39 | } |
||
40 | } |
||
41 | return () => { |
||
42 | let app = document.getElementById("app-container"); |
||
43 | |||
44 | if (app) { |
||
45 | app.onclick = null; |
||
46 | } |
||
47 | }; |
||
48 | }, [dispatch, isDrawerShowing]); |
||
49 | |||
50 | 7 | const DrawerComponent = driveWithDarkMode(Drawer); |
|
51 | |||
52 | 7 | return ( |
|
53 | <DrawerComponent |
||
54 | className={theme.className} |
||
55 | logo={logo} |
||
56 | hide={!isDrawerShowing} |
||
57 | onClose={() => { |
||
58 | 1 | dispatch(closeDrawer()); |
|
59 | }} |
||
60 | style={theme.style} |
||
61 | position={position} |
||
62 | > |
||
63 | {children} |
||
64 | </DrawerComponent> |
||
65 | ); |
||
66 | }; |
||
67 | |||
68 | export default AppDrawer; |
||
69 |