Skip to content
Myr

diff-pane.tsx

This file

Path

apps/web/src/features/code/diff-pane.tsx

82 lines · 2.0 KiB · TypeScript

Last changed by

Merge redesign into mainoscabrielbefore adoptioncaedd21

History of this file

Take it

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

line 1why, one step back
1/**

Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72

lines 2–4why, one step back
2 * Until the box has stuck under the toolbar it does not scroll, so a wheel over
3 * the diff moves the page and the head scrolls away first; once stuck it4 * scrolls (Pierre's `CodeView` needs a scroller of its own).

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 5–9why, one step back
5 */
6import { useEffect, useRef, useState } from "react";7import type { ReactNode } from "react";89const PANE =

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 10why, one step back
10 "group/pane sticky top-(--stick-toolbar) h-[calc(100dvh-var(--stick-toolbar))] scroll-mt-(--stick-toolbar) -mt-6 -mb-16 flex min-h-0 flex-col";

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 11–60why, one step back
11
12export const PANE_SCROLLER =13 "min-h-0 flex-1 overflow-auto overscroll-y-auto group-data-[stuck=false]/pane:overflow-y-hidden";1415const pixels = (length: string) => Number(/^-?[\d.]+/u.exec(length)?.[0] ?? 0);1617const followStuck = (box: HTMLElement, stuck: (now: boolean) => void) => {18 let frame = 0;1920 const read = () => {21 frame = 0;22 stuck(23 box.getBoundingClientRect().top <=24 pixels(globalThis.getComputedStyle(box).top) + 125 );26 };2728 const onScroll = () => {29 if (frame === 0) {30 frame = globalThis.requestAnimationFrame(read);31 }32 };3334 read();35 document.addEventListener("scroll", onScroll, {36 capture: true,37 passive: true,38 });39 globalThis.addEventListener("resize", onScroll, { passive: true });4041 return () => {42 globalThis.cancelAnimationFrame(frame);43 document.removeEventListener("scroll", onScroll, { capture: true });44 globalThis.removeEventListener("resize", onScroll);45 };46};4748const useStuck = () => {49 const pane = useRef<HTMLDivElement>(null);50 const [stuck, setStuck] = useState<boolean>();5152 useEffect(() => {53 const box = pane.current;5455 return box === null ? undefined : followStuck(box, setStuck);56 }, []);5758 return { pane, stuck };59};60

Merge build/1500-design-draws into mainoscabrielbefore adoption9bc46b7

lines 61–67why, one step back
61export const DiffPane = ({
62 children,63 id,64}: {65 readonly children: ReactNode;66 readonly id?: string;67}) => {

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 68–72why, one step back
68 const { pane, stuck } = useStuck();
6970 return (71 <div72 className={PANE}

Merge build/1500-design-draws into mainoscabrielbefore adoption9bc46b7

line 73why, one step back
73 id={id}

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 74–82why, one step back
74 data-diff-pane=""
75 data-files=""76 data-stuck={stuck}77 ref={pane}78 >79 {children}80 </div>81 );82};