* feat(PBI-49): add debugProps helper + Vitest test
Adds lib/debug.ts with debugProps(id, component, file) that returns
data-debug-id and data-debug-label attrs in dev mode, empty object in
production. Adds __tests__/lib/debug.test.ts covering both modes.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* docs(PBI-49): add debug-id pattern doc + CLAUDE.md reference
Adds docs/patterns/debug-id.md documenting the named-component boundary
rule (6 punten), helper-voorbeeld, skip-criteria en motivatie voor
handmatige pad-argumenten. Voegt verwijzing toe aan CLAUDE.md
patterns-tabel.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(PBI-49): migrate 17 shared/ components to debugProps helper
Replace hardcoded data-debug-id + data-debug-label attribute pairs with
{...debugProps(id, component, file)} spread in all 17 components/shared/
files. Existing debug-ids preserved unchanged.
* feat(PBI-49): add debugProps to backlog/, sprint/, solo/ components
* feat(PBI-49): add debugProps to jobs/ + ideas/ components
* feat(PBI-49): add debugProps to products/ + settings/ + notifications/ components
* feat(PBI-49): add debugProps to admin/ + dashboard/ + dialogs/ + mobile/ + split-pane/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(PBI-49): use attr(data-debug-id) for debug tooltip in globals.css
* refactor(PBI-49): remove data-debug-label from debugProps helper + test
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(PBI-49): strip unused component/file args from debugProps in shared/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(PBI-49): add BEM sub-element data-debug-id to StatusBar, NavBar, PanelNavBar
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(PBI-49): add BEM sub-element data-debug-id to components/sprint/*
- new-sprint-dialog: __submit on submit button
- sprint-backlog: __list on SprintBacklogLeft + SprintBacklogRight scroll areas
- sprint-board-client: root wrapper div (display:contents) + __drag-overlay
- sprint-header: __title on goal button, __dates on dates button, __actions on action cluster
- sprint-run-controls: root on controls div, __start/__cancel on action buttons; __blockers-dialog on dialog content
- start-sprint-button: root on trigger button, __dialog on dialog content, __submit on submit button
- sync-active-sprint-cookie: no debug-id (returns null, side-effect only), comment added
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(PBI-49): add BEM sub-element data-debug-id to components/backlog/*
* feat(PBI-49): add BEM sub-element data-debug-id to components/ideas/*
* feat(PBI-49): add BEM sub-element data-debug-id to components/dashboard/* + components/markdown.tsx
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(PBI-49): add BEM sub-element data-debug-id to new-product-button
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(PBI-49): add BEM sub-element data-debug-id to components/solo/*
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(PBI-49): add BEM sub-elements to nav-status-indicators
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(PBI-49): add BEM sub-element data-debug-id to components/jobs/*
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(PBI-49): add BEM sub-element data-debug-id to components/products/*
* feat(PBI-49): add BEM sub-element data-debug-id to components/notifications/*
- answer-modal: __content (scroll area), __submit (footer)
- notifications-bridge: skip comment (bridge, non-rendering wrapper)
- notifications-realtime-mount: skip comment (returns null)
- notifications-sheet: __header, __items (questions list)
- push-toggle: __switch (button), __label (button text) on subscribed/unsubscribed states
* feat(PBI-49): add BEM sub-element data-debug-id to components/settings/*
- leave-product-button: root only (single-button component)
- min-quota-editor: __input (number input), __save (save button)
- profile-editor: __username (bio/short-description input), __save (submit)
- role-manager: __roles (checkbox list), __add (save button)
- token-manager: __tokens (active tokens list), __generate (create button)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(PBI-49): add BEM sub-element data-debug-id to admin, auth, dialogs, entity-dialog, mobile, split-pane
* docs(PBI-49): add debug-labels BEM pattern doc + CLAUDE.md entry
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
185 lines
6.1 KiB
TypeScript
185 lines
6.1 KiB
TypeScript
'use client'
|
|
|
|
import { Fragment, useRef, useState, useEffect, useCallback } from 'react'
|
|
import { cn } from '@/lib/utils'
|
|
import { debugProps } from '@/lib/debug'
|
|
|
|
const COOKIE_PREFIX = 'sp:'
|
|
const COOKIE_MAX_AGE = 60 * 60 * 24 * 365
|
|
|
|
function readSplits(cookieKey: string, n: number): number[] | null {
|
|
if (typeof document === 'undefined') return null
|
|
const match = document.cookie.match(
|
|
new RegExp(`(?:^|; )${COOKIE_PREFIX}${cookieKey}=([^;]+)`)
|
|
)
|
|
if (!match) return null
|
|
try {
|
|
const parsed: unknown = JSON.parse(decodeURIComponent(match[1]))
|
|
if (
|
|
!Array.isArray(parsed) ||
|
|
parsed.length !== n ||
|
|
parsed.some((v) => typeof v !== 'number') ||
|
|
Math.abs((parsed as number[]).reduce((a, b) => a + b, 0) - 100) > 1
|
|
) return null
|
|
return parsed as number[]
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
function writeSplits(cookieKey: string, splits: number[]) {
|
|
document.cookie = `${COOKIE_PREFIX}${cookieKey}=${encodeURIComponent(
|
|
JSON.stringify(splits)
|
|
)}; max-age=${COOKIE_MAX_AGE}; path=/; samesite=lax`
|
|
}
|
|
|
|
export interface SplitPaneProps {
|
|
panes: React.ReactNode[]
|
|
defaultSplit: number[] // length n, values sum to 100
|
|
cookieKey: string
|
|
tabLabels?: string[] // mobile tab labels, defaults to "Pane N"
|
|
minSize?: number // minimum px per pane, default 200
|
|
mobileBreakpoint?: number // default 1024
|
|
activeTab?: number // controlled: parent manages which tab is active
|
|
onActiveTabChange?: (index: number) => void
|
|
}
|
|
|
|
export function SplitPane({
|
|
panes,
|
|
defaultSplit,
|
|
cookieKey,
|
|
tabLabels,
|
|
minSize = 200,
|
|
mobileBreakpoint = 1024,
|
|
activeTab: activeTabProp,
|
|
onActiveTabChange,
|
|
}: SplitPaneProps) {
|
|
const isControlled = activeTabProp !== undefined
|
|
const n = panes.length
|
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
const splitsRef = useRef<number[]>(defaultSplit)
|
|
|
|
const [splits, setSplits] = useState<number[]>(() => {
|
|
return readSplits(cookieKey, n) ?? defaultSplit
|
|
})
|
|
const [dragging, setDragging] = useState<number | null>(null) // divider index (0..n-2)
|
|
const [isMobile, setIsMobile] = useState(false)
|
|
const [internalTab, setInternalTab] = useState(0)
|
|
const activeTab = isControlled ? activeTabProp : internalTab
|
|
|
|
const handleTabChange = (i: number) => {
|
|
if (!isControlled) setInternalTab(i)
|
|
onActiveTabChange?.(i)
|
|
}
|
|
|
|
useEffect(() => { splitsRef.current = splits }, [splits])
|
|
|
|
useEffect(() => {
|
|
const check = () => setIsMobile(window.innerWidth < mobileBreakpoint)
|
|
check()
|
|
window.addEventListener('resize', check)
|
|
return () => window.removeEventListener('resize', check)
|
|
}, [mobileBreakpoint])
|
|
|
|
const onMouseMove = useCallback((e: MouseEvent) => {
|
|
if (dragging === null || !containerRef.current) return
|
|
const rect = containerRef.current.getBoundingClientRect()
|
|
const containerWidth = rect.width
|
|
const minPct = (minSize / containerWidth) * 100
|
|
|
|
const cursorPct = ((e.clientX - rect.left) / containerWidth) * 100
|
|
const current = splitsRef.current
|
|
// Left edge of pane[dragging] in percentage
|
|
const leftEdge = current.slice(0, dragging).reduce((a, b) => a + b, 0)
|
|
const combinedWidth = current[dragging] + current[dragging + 1]
|
|
|
|
const newLeft = Math.min(Math.max(cursorPct - leftEdge, minPct), combinedWidth - minPct)
|
|
const newRight = combinedWidth - newLeft
|
|
|
|
setSplits((prev) => {
|
|
const next = [...prev]
|
|
next[dragging] = newLeft
|
|
next[dragging + 1] = newRight
|
|
return next
|
|
})
|
|
}, [dragging, minSize])
|
|
|
|
const onMouseUp = useCallback(() => {
|
|
if (dragging !== null) {
|
|
writeSplits(cookieKey, splitsRef.current)
|
|
setDragging(null)
|
|
}
|
|
}, [dragging, cookieKey])
|
|
|
|
useEffect(() => {
|
|
if (dragging !== null) {
|
|
window.addEventListener('mousemove', onMouseMove)
|
|
window.addEventListener('mouseup', onMouseUp)
|
|
}
|
|
return () => {
|
|
window.removeEventListener('mousemove', onMouseMove)
|
|
window.removeEventListener('mouseup', onMouseUp)
|
|
}
|
|
}, [dragging, onMouseMove, onMouseUp])
|
|
|
|
if (isMobile) {
|
|
return (
|
|
<div className="flex flex-col h-full" {...debugProps('split-pane', 'SplitPane', 'components/split-pane/split-pane.tsx')}>
|
|
<div className="flex items-center border-b border-border shrink-0">
|
|
{activeTab > 0 && (
|
|
<button
|
|
onClick={() => handleTabChange(activeTab - 1)}
|
|
className="px-3 py-2 text-sm text-muted-foreground hover:text-foreground transition-colors shrink-0"
|
|
aria-label="Terug"
|
|
>
|
|
←
|
|
</button>
|
|
)}
|
|
{panes.map((_, i) => (
|
|
<button
|
|
key={i}
|
|
onClick={() => handleTabChange(i)}
|
|
className={cn(
|
|
'flex-1 py-2 text-sm font-medium transition-colors',
|
|
activeTab === i
|
|
? 'border-b-2 border-primary text-primary'
|
|
: 'text-muted-foreground hover:text-foreground'
|
|
)}
|
|
>
|
|
{tabLabels?.[i] ?? `Pane ${i + 1}`}
|
|
</button>
|
|
))}
|
|
</div>
|
|
<div className="flex-1 overflow-auto">
|
|
{panes[activeTab]}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div ref={containerRef} className="flex h-full overflow-hidden select-none" {...debugProps('split-pane', 'SplitPane', 'components/split-pane/split-pane.tsx')}>
|
|
{panes.map((pane, i) => (
|
|
<Fragment key={i}>
|
|
{i > 0 && (
|
|
<div
|
|
data-debug-id="split-pane__divider"
|
|
onMouseDown={() => setDragging(i - 1)}
|
|
className={cn(
|
|
'w-1 shrink-0 bg-border hover:bg-primary transition-colors cursor-col-resize',
|
|
dragging === i - 1 && 'bg-primary'
|
|
)}
|
|
/>
|
|
)}
|
|
<div
|
|
className="flex flex-col overflow-hidden"
|
|
style={i === n - 1 ? { flex: 1 } : { width: `${splits[i]}%` }}
|
|
data-debug-id={i === 0 ? 'split-pane__left' : i === n - 1 ? 'split-pane__right' : undefined}
|
|
>
|
|
{pane}
|
|
</div>
|
|
</Fragment>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|