Skip to content
This repository was archived by the owner on Jan 2, 2021. It is now read-only.

Commit 804cad5

Browse files
committed
2 parents c1b4a53 + e165f1b commit 804cad5

File tree

5 files changed

+69
-13
lines changed

5 files changed

+69
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function App() {
8787
- `toggleButtonProps: PropsObject`
8888
- Use this to add props to the toggle button. For example, you can add `className`, `style` (merge and override default style), `onClick` (extend default handler), etc.
8989
- `position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"`
90-
- Defaults to `bottom-right`
90+
- Defaults to `bottom-left`
9191
- The position of the React Query logo to open and close the devtools panel
9292

9393
## Embedded Mode

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export function ReactQueryDevtools(props: {
2424
React.ButtonHTMLAttributes<HTMLButtonElement>,
2525
HTMLButtonElement
2626
>
27+
/**
28+
* The position of the React Query logo to open and close the devtools panel.
29+
* Defaults to 'bottom-left'.
30+
*/
31+
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
2732
}): React.ReactElement
2833

2934
export function ReactQueryDevtoolsPanel(props: {

src/Logo.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ export function ReactQueryDevtools({
118118
zIndex: '99999',
119119
width: '100%',
120120
height: '500px',
121-
maxHeight: '50%',
121+
maxHeight: '90%',
122122
boxShadow: '0 0 20px rgba(0,0,0,.3)',
123123
borderTop: `1px solid ${theme.gray}`,
124124
...panelStyle,
125125
}}
126+
setIsOpen={setIsOpen}
126127
/>
127128
<Button
128129
{...otherCloseButtonProps}
@@ -159,6 +160,7 @@ export function ReactQueryDevtools({
159160
) : (
160161
<button
161162
{...otherToggleButtonProps}
163+
aria-label="Open React Query Devtools"
162164
onClick={() => {
163165
setIsOpen(true)
164166
onToggleClick && onToggleClick()
@@ -197,11 +199,7 @@ export function ReactQueryDevtools({
197199
...toggleButtonStyle,
198200
}}
199201
>
200-
<Logo
201-
width="1.5em"
202-
height="1.5em"
203-
aria-label="Open React Query Devtools"
204-
/>
202+
<Logo aria-hidden />
205203
</button>
206204
)}
207205
</div>
@@ -224,6 +222,8 @@ const sortFns = {
224222

225223
export const ReactQueryDevtoolsPanel = React.forwardRef(
226224
function ReactQueryDevtoolsPanel(props, ref) {
225+
const { setIsOpen, ...panelProps } = props
226+
227227
const queryCache = useQueryCache ? useQueryCache() : cache
228228

229229
const [sort, setSort] = useLocalStorage(
@@ -238,6 +238,8 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
238238
false
239239
)
240240

241+
const [isDragging, setIsDragging] = React.useState(false)
242+
241243
const sortFn = React.useMemo(() => sortFns[sort], [sort])
242244

243245
React[isServer ? 'useEffect' : 'useLayoutEffect'](() => {
@@ -246,6 +248,36 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
246248
}
247249
}, [setSort, sortFn])
248250

251+
React[isServer ? 'useEffect' : 'useLayoutEffect'](() => {
252+
if (isDragging) {
253+
const run = e => {
254+
const containerHeight = window.innerHeight - e.pageY
255+
256+
if (containerHeight < 70) {
257+
setIsOpen(false)
258+
} else {
259+
ref.current.style.height = `${containerHeight}px`
260+
}
261+
}
262+
document.addEventListener('mousemove', run)
263+
document.addEventListener('mouseup', handleDragEnd)
264+
265+
return () => {
266+
document.removeEventListener('mousemove', run)
267+
document.removeEventListener('mouseup', handleDragEnd)
268+
}
269+
}
270+
}, [isDragging])
271+
272+
const handleDragStart = e => {
273+
if (e.button !== 0) return // Only allow left click for drag
274+
setIsDragging(true)
275+
}
276+
277+
const handleDragEnd = e => {
278+
setIsDragging(false)
279+
}
280+
249281
const [unsortedQueries, setUnsortedQueries] = React.useState(
250282
Object.values(queryCache.queries)
251283
)
@@ -302,17 +334,30 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
302334

303335
return (
304336
<ThemeProvider theme={theme}>
305-
<Panel ref={ref} className="ReactQueryDevtoolsPanel" {...props}>
337+
<Panel ref={ref} className="ReactQueryDevtoolsPanel" {...panelProps}>
306338
<div
307339
style={{
308340
flex: '1 1 500px',
309341
minHeight: '40%',
342+
maxHeight: '100%',
310343
overflow: 'auto',
311344
borderRight: `1px solid ${theme.grayAlt}`,
312345
display: 'flex',
313346
flexDirection: 'column',
314347
}}
315348
>
349+
<div
350+
style={{
351+
left: 0,
352+
width: '100%',
353+
height: '4px',
354+
marginBottom: '-4px',
355+
cursor: 'row-resize',
356+
zIndex: 100000,
357+
}}
358+
onMouseDown={handleDragStart}
359+
onMouseUp={handleDragEnd}
360+
></div>
316361
<div
317362
style={{
318363
padding: '.5rem',
@@ -419,7 +464,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
419464
</div>
420465
<div
421466
style={{
422-
overflow: 'auto',
467+
overflow: 'auto scroll',
423468
}}
424469
>
425470
{queries.map((query, i) => (

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5286,9 +5286,9 @@ lodash.sortby@^4.7.0:
52865286
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
52875287

52885288
lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15:
5289-
version "4.17.15"
5290-
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
5291-
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
5289+
version "4.17.19"
5290+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
5291+
integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==
52925292

52935293
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
52945294
version "1.4.0"

0 commit comments

Comments
 (0)