-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormikDebug.tsx
57 lines (52 loc) · 1.4 KB
/
FormikDebug.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Box, IconButton, Portal, Slide, useOutsideClick } from '@chakra-ui/react';
import { Field } from 'formik';
import { useRef } from 'react';
import { RiCloseCircleLine } from 'react-icons/ri';
export const isDevelopmentMode = () =>
!process.env.NODE_ENV || process.env.NODE_ENV === 'development';
type FormikDebugProps = {
isOpen: boolean;
onToggle: () => void;
};
export const FormikDebug = ({ isOpen, onToggle }: FormikDebugProps) => {
const debuggerRef = useRef(null);
useOutsideClick({
ref: debuggerRef,
handler: () => {
if (isOpen) onToggle();
},
});
return isDevelopmentMode() ? (
<Portal>
<Slide
ref={debuggerRef}
direction="bottom"
in={isOpen}
style={{ maxWidth: 'fit-content', zIndex: 100000 }}
>
<Box
p="40px"
color="white"
mt="4"
bg="brand.500"
rounded="md"
shadow="md"
h="100vh"
minW="40vw"
overflowY="scroll"
>
<IconButton
aria-label="Close debugger"
icon={<RiCloseCircleLine color="#000" style={{ width: '100%' }} />}
onClick={onToggle}
float="right"
/>
<pre>
<Field>{({ form }: any) => JSON.stringify(form, null, 2)}</Field>
</pre>
</Box>
</Slide>
</Portal>
) : null;
};
export default FormikDebug;