MCPcopy Create free account
hub / github.com/TanStack/query / DraggablePanel

Function DraggablePanel

packages/query-devtools/src/Devtools.tsx:498–762  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

496}
497
498const DraggablePanel: Component<DevtoolsPanelProps> = (props) => {
499 const { setSelectedQueryHash, panelWidth, setPanelWidth } = useDevtoolsState()
500
501 const theme = useTheme()
502 const css = useQueryDevtoolsContext().shadowDOMTarget
503 ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget })
504 : goober.css
505 const styles = createMemo(() => {
506 return theme() === 'dark' ? darkStyles(css) : lightStyles(css)
507 })
508
509 let closeBtnRef!: HTMLButtonElement
510
511 // Focus the close button when the panel opens for screen reader accessibility
512 onMount(() => {
513 closeBtnRef.focus()
514 })
515
516 const [isResizing, setIsResizing] = createSignal(false)
517
518 const position = createMemo(
519 () =>
520 (props.localStore.position ||
521 useQueryDevtoolsContext().position ||
522 POSITION) as DevtoolsPosition,
523 )
524
525 const handleDragStart: JSX.EventHandler<HTMLDivElement, MouseEvent> = (
526 event,
527 ) => {
528 const panelElement = event.currentTarget.parentElement
529 if (!panelElement) return
530 setIsResizing(true)
531 const { height, width } = panelElement.getBoundingClientRect()
532 const startX = event.clientX
533 const startY = event.clientY
534 let newSize = 0
535 const minHeight = convertRemToPixels(3.5)
536 const minWidth = convertRemToPixels(12)
537 const runDrag = (moveEvent: MouseEvent) => {
538 moveEvent.preventDefault()
539
540 if (position() === 'left' || position() === 'right') {
541 const valToAdd =
542 position() === 'right'
543 ? startX - moveEvent.clientX
544 : moveEvent.clientX - startX
545 newSize = Math.round(width + valToAdd)
546 if (newSize < minWidth) {
547 newSize = minWidth
548 }
549 props.setLocalStore('width', String(Math.round(newSize)))
550
551 const newWidth = panelElement.getBoundingClientRect().width
552 // If the panel size didn't decrease, this means we have reached the minimum width
553 // of the panel so we restore the original width in local storage
554 // Restoring the width helps in smooth open/close transitions
555 if (Number(props.localStore.width) < newWidth) {

Callers

nothing calls this directly

Calls 8

useDevtoolsStateFunction · 0.90
useThemeFunction · 0.90
useQueryDevtoolsContextFunction · 0.90
getSidedPropFunction · 0.90
convertRemToPixelsFunction · 0.90
getPanelDynamicStylesFunction · 0.85
darkStylesFunction · 0.70
lightStylesFunction · 0.70

Tested by

no test coverage detected