(props)
| 408 | } |
| 409 | |
| 410 | const DraggablePanel: Component<DevtoolsPanelProps> = (props) => { |
| 411 | const theme = useTheme() |
| 412 | const css = useQueryDevtoolsContext().shadowDOMTarget |
| 413 | ? goober.css.bind({ target: useQueryDevtoolsContext().shadowDOMTarget }) |
| 414 | : goober.css |
| 415 | const styles = createMemo(() => { |
| 416 | return theme() === 'dark' ? darkStyles(css) : lightStyles(css) |
| 417 | }) |
| 418 | |
| 419 | let closeBtnRef!: HTMLButtonElement |
| 420 | |
| 421 | // Focus the close button when the panel opens for screen reader accessibility |
| 422 | onMount(() => { |
| 423 | closeBtnRef.focus() |
| 424 | }) |
| 425 | |
| 426 | const [isResizing, setIsResizing] = createSignal(false) |
| 427 | |
| 428 | const position = createMemo( |
| 429 | () => |
| 430 | (props.localStore.position || |
| 431 | useQueryDevtoolsContext().position || |
| 432 | POSITION) as DevtoolsPosition, |
| 433 | ) |
| 434 | |
| 435 | const handleDragStart: JSX.EventHandler<HTMLDivElement, MouseEvent> = ( |
| 436 | event, |
| 437 | ) => { |
| 438 | const panelElement = event.currentTarget.parentElement |
| 439 | if (!panelElement) return |
| 440 | setIsResizing(true) |
| 441 | const { height, width } = panelElement.getBoundingClientRect() |
| 442 | const startX = event.clientX |
| 443 | const startY = event.clientY |
| 444 | let newSize = 0 |
| 445 | const minHeight = convertRemToPixels(3.5) |
| 446 | const minWidth = convertRemToPixels(12) |
| 447 | const runDrag = (moveEvent: MouseEvent) => { |
| 448 | moveEvent.preventDefault() |
| 449 | |
| 450 | if (position() === 'left' || position() === 'right') { |
| 451 | const valToAdd = |
| 452 | position() === 'right' |
| 453 | ? startX - moveEvent.clientX |
| 454 | : moveEvent.clientX - startX |
| 455 | newSize = Math.round(width + valToAdd) |
| 456 | if (newSize < minWidth) { |
| 457 | newSize = minWidth |
| 458 | } |
| 459 | props.setLocalStore('width', String(Math.round(newSize))) |
| 460 | |
| 461 | const newWidth = panelElement.getBoundingClientRect().width |
| 462 | // If the panel size didn't decrease, this means we have reached the minimum width |
| 463 | // of the panel so we restore the original width in local storage |
| 464 | // Restoring the width helps in smooth open/close transitions |
| 465 | if (Number(props.localStore.width) < newWidth) { |
| 466 | props.setLocalStore('width', String(newWidth)) |
| 467 | } |
nothing calls this directly
no test coverage detected