-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathdevToolUI.tsx
More file actions
102 lines (96 loc) · 2.79 KB
/
devToolUI.tsx
File metadata and controls
102 lines (96 loc) · 2.79 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import * as React from 'react';
import { Control } from 'react-hook-form';
import { Animate } from 'react-simple-animate';
import Header from './header';
import Panel from './panel';
import colors from './colors';
import Logo from './logo';
import { Button } from './styled';
import { useStateMachine } from 'little-state-machine';
import { setVisible } from './settingAction';
import { PLACEMENT, getPositionByPlacement } from './position';
export interface DevtoolUIProps {
control: Control<any>;
placement?: PLACEMENT;
/** Custom styles for the "show/hide panel" button and for the panel div */
styles?: {
/** Custom styles for the "show/hide panel" button */
button?: React.HTMLAttributes<HTMLButtonElement>['style'];
/** Custom styles for the panel div */
panel?: React.HTMLAttributes<HTMLDivElement>['style'];
};
}
export const DevToolUI: React.FC<DevtoolUIProps> = ({
control,
placement = 'top-right',
styles,
}) => {
const { state, actions } = useStateMachine({
setVisible,
});
const position = getPositionByPlacement(placement, 0, 0);
const visibility = state.visible ? 'visible' : 'hidden';
return (
<>
<Animate
play={state.visible}
duration={0.2}
start={{
...position,
position: 'fixed',
transform: placement.includes('right')
? 'translateX(280px)'
: 'translateX(-280px)',
zIndex: 99999,
}}
end={{
...position,
position: 'fixed',
transform: 'translateX(0)',
zIndex: 99999,
}}
>
<div
style={{
...position,
position: 'fixed',
height: '100vh',
width: 250,
zIndex: 99999,
visibility,
background: colors.buttonBlue,
display: 'grid',
textAlign: 'left',
color: 'white',
fontSize: 14,
gridTemplateRows: '40px auto',
fontFamily:
"-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif",
...styles?.panel,
}}
>
<Header setVisible={actions.setVisible} control={control} />
<Panel control={control} />
</div>
</Animate>
{!state.visible && (
<Button
title="Show dev panel"
hideBackground
style={{
position: 'fixed',
zIndex: 99999,
...getPositionByPlacement(placement, 3, 3),
padding: 3,
margin: 0,
background: 'none',
...styles?.button,
}}
type="button"
>
<Logo actions={actions} />
</Button>
)}
</>
);
};