-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathSettingsTab.tsx
227 lines (222 loc) · 8.19 KB
/
SettingsTab.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import { useState } from "react"
import { Checkbox } from "../components/Checkbox.js"
import { Input } from "../components/Input.js"
import { SelectWithOptions } from "../components/Select.js"
import { Stack } from "../components/Stack.js"
import { RouteBoundaryOptions } from "../context/rdtReducer.js"
import { useSettingsContext } from "../context/useRDTContext.js"
import { uppercaseFirstLetter } from "../utils/string.js"
export const SettingsTab = () => {
const { settings, setSettings } = useSettingsContext()
const [minHeight, setMinHeight] = useState(settings.minHeight.toString())
const [maxHeight, setMaxHeight] = useState(settings.maxHeight.toString())
const [expansionLevel, setExpansionLevel] = useState(settings.expansionLevel.toString())
const [openHotkey, setOpenHotkey] = useState(settings.openHotkey.toString())
const [eventsToKeep, setEventsToKeep] = useState(settings.eventsToKeep.toString())
return (
<Stack className="mb-4">
<h1>
<span className="text-lg font-semibold">Settings</span>
<hr className="mt-2 border-gray-400" />
</h1>
<Checkbox
id="defaultOpen"
hint="The dev tools will be open by default when you run the application and when you refresh the browser."
onChange={() => setSettings({ defaultOpen: !settings.defaultOpen })}
value={settings.defaultOpen}
>
Open dev tools by default
</Checkbox>
<Checkbox
id="requireUrlFlag"
hint={`Allows you to only show rdt when there is a flag in the URL search params set. (${settings.urlFlag}=true)`}
onChange={() => setSettings({ requireUrlFlag: !settings.requireUrlFlag })}
value={settings.requireUrlFlag}
>
Show dev tools only when URL flag is set ?{settings.urlFlag}=true
</Checkbox>
<Checkbox
id="hideUntilHover"
hint="The dev tools trigger will be hidden on the page until you hover over it."
onChange={() => setSettings({ hideUntilHover: !settings.hideUntilHover })}
value={settings.hideUntilHover}
>
Hide the trigger until hovered
</Checkbox>
<Checkbox
id="showBreakpointIndicator"
hint="Whether to show the breakpoint indicator or not"
onChange={() => setSettings({ showBreakpointIndicator: !settings.showBreakpointIndicator })}
value={settings.showBreakpointIndicator}
>
Show breakpoint indicator
</Checkbox>
<hr className="mt-2 border-gray-700" />
<Stack gap="lg">
{settings.requireUrlFlag && (
<Input
name="urlFlag"
id="urlFlag"
label="URL flag to use"
hint={`This allows you to change the URL search param flag that will be used to show the dev tools when "Show dev tools only when URL flag is set" is set to true`}
value={settings.urlFlag}
onChange={(e) => setSettings({ urlFlag: e.target.value ?? "" })}
onBlur={(e) => {
setSettings({ urlFlag: e.target.value.trim() })
}}
/>
)}
<Input
name="expansionLevel"
id="expansionLevel"
label="Depth of expansion for JSON objects"
hint="This allows you to change the depth of expanded properties of json objects."
value={expansionLevel}
onChange={(e) => setExpansionLevel(e.target.value ?? "")}
onBlur={(e) => {
const value = Number.parseInt(e.target.value)
if (value && !Number.isNaN(value) && value >= 0) {
setSettings({ expansionLevel: value })
}
}}
/>
<Input
name="openHotkey"
id="openHotkey"
label="Hotkey to open/close development tools"
hint="This allows you to change the default hotkey used to open development tools."
value={openHotkey}
onChange={(e) => setOpenHotkey(e.target.value ?? "")}
onBlur={(e) => {
const value = e.target.value
if (value) {
setSettings({ openHotkey: value })
}
}}
/>
<div className="flex flex-col gap-2 lg:flex-row">
<Input
name="minHeight"
label="Min height of the dev tools (px)"
hint="The dev tools will not shrink below this height when being dragged."
id="minHeight"
value={minHeight}
onChange={(e) => setMinHeight(e.target.value ?? "")}
onBlur={(e) => {
const value = Number.parseInt(e.target.value)
if (value && !Number.isNaN(value) && value < settings.maxHeight && value > 100) {
setSettings({ minHeight: value })
}
}}
/>
<Input
name="maxHeight"
id="maxHeight"
label="Max height of the dev tools (px)"
hint="The dev tools will not expand beyond this height when being dragged."
value={maxHeight}
onChange={(e) => setMaxHeight(e.target.value ?? "")}
onBlur={(e) => {
const value = Number.parseInt(e.target.value)
if (value && !Number.isNaN(value) && value > settings.minHeight) {
setSettings({ maxHeight: value })
}
}}
/>
</div>
<div className="flex flex-col gap-2 lg:flex-row">
<SelectWithOptions
label="Trigger position"
onSelect={(value) => setSettings({ position: value })}
value={settings.position}
className="w-full"
options={[
{ label: "Bottom Right", value: "bottom-right" },
{ label: "Bottom Left", value: "bottom-left" },
{ label: "Top Right", value: "top-right" },
{ label: "Top Left", value: "top-left" },
{ label: "Middle Right", value: "middle-right" },
{ label: "Middle Left", value: "middle-left" },
]}
hint="This will determine where your trigger position on the screen is when the tools are collapsed."
/>
<SelectWithOptions
label="Environments position"
onSelect={(value) => setSettings({ liveUrlsPosition: value as any })}
value={settings.liveUrlsPosition}
className="w-full"
options={[
{ label: "Bottom Right", value: "bottom-right" },
{ label: "Bottom Left", value: "bottom-left" },
{ label: "Top Right", value: "top-right" },
{ label: "Top Left", value: "top-left" },
]}
hint="This will determine where your environments position on the screen is."
/>
<SelectWithOptions
label="Panel position"
onSelect={(value) => setSettings({ panelLocation: value })}
value={settings.panelLocation}
className="w-full"
options={[
{ label: "Top", value: "top" },
{ label: "Bottom", value: "bottom" },
]}
hint="This will determine where your panel shows up once opened"
/>
</div>
<div className="flex flex-col gap-2 lg:flex-row">
<SelectWithOptions
label="Route boundary gradient"
onSelect={(value) => setSettings({ routeBoundaryGradient: value })}
value={settings.routeBoundaryGradient}
options={RouteBoundaryOptions.map((option) => ({
label: uppercaseFirstLetter(option),
value: option,
}))}
className="w-full"
hint="This will determine the look of the gradient shown for route boundaries."
/>
<SelectWithOptions
label="Show route boundaries on"
onSelect={(value) => setSettings({ showRouteBoundariesOn: value })}
value={settings.showRouteBoundariesOn}
options={[
{ value: "hover", label: "Hover" },
{ value: "click", label: "Click" },
]}
className="w-full"
hint="This will determine if the route boundaries show on hover of a route segment or clicking a button."
/>
</div>
<Input
name="port"
id="port"
label="Remix Forge port (default: 3003)"
hint="The port on which Remix Forge is running. If you change this field make sure you change the port in the Remix Forge config as well."
value={settings.port}
onChange={(e) => {
const value = e.target.value
if (value && !Number.isNaN(Number.parseInt(value))) {
setSettings({ port: Number.parseInt(value) })
}
}}
/>
<Input
name="eventsToKeep"
id="eventsToKeep"
label="Number of events to keep in history"
hint="The number of loader/action events to keep in history per route. Minimum: 1, Maximum: 100"
value={eventsToKeep}
onChange={(e) => setEventsToKeep(e.target.value ?? "")}
onBlur={(e) => {
const value = Number.parseInt(e.target.value)
if (value && !Number.isNaN(value) && value >= 1 && value <= 100) {
setSettings({ eventsToKeep: value })
}
}}
/>
</Stack>
</Stack>
)
}