-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
700 lines (656 loc) · 32 KB
/
index.html
File metadata and controls
700 lines (656 loc) · 32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Better Resizable Panels — shadcn component</title>
<meta name="description" content="Pixel-accurate resizable panels for React with drag handles, min/max constraints, flex panel behavior, and localStorage persistence." />
<!-- Open Graph -->
<meta property="og:type" content="website" />
<meta property="og:url" content="https://rbby.dev/better-resizable-panels/" />
<meta property="og:title" content="Better Resizable Panels" />
<meta property="og:description" content="Pixel-accurate resizable panels for React. Drag handles with min/max constraints, flex panel behavior, and localStorage persistence." />
<meta property="og:image" content="https://rbby.dev/better-resizable-panels/og-image.png" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Better Resizable Panels" />
<meta name="twitter:description" content="Pixel-accurate resizable panels for React. Drag handles with min/max constraints, flex panel behavior, and localStorage persistence." />
<meta name="twitter:image" content="https://rbby.dev/better-resizable-panels/og-image.png" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=JetBrains+Mono:wght@300;400;500;600&display=swap" rel="stylesheet" />
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
display: ['"Instrument Serif"', 'Georgia', 'serif'],
mono: ['"JetBrains Mono"', 'monospace'],
},
colors: {
border: 'rgb(var(--border) / <alpha-value>)',
primary: { DEFAULT: 'rgb(var(--primary) / <alpha-value>)' },
'muted-foreground': 'rgb(var(--muted-foreground) / <alpha-value>)',
},
borderColor: {
DEFAULT: 'rgb(var(--border) / <alpha-value>)',
},
},
},
};
</script>
<style>
:root {
--border: 39 39 42;
--primary: 6 182 212;
--muted-foreground: 161 161 170;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: "JetBrains Mono", monospace;
background: #09090b;
color: #fafafa;
-webkit-font-smoothing: antialiased;
}
.grid-bg {
background-image:
linear-gradient(rgba(6,182,212,0.04) 1px, transparent 1px),
linear-gradient(90deg, rgba(6,182,212,0.04) 1px, transparent 1px);
background-size: 48px 48px;
}
.glow { box-shadow: 0 0 60px -12px rgba(6,182,212,0.15); }
@keyframes fade-up {
from { opacity: 0; transform: translateY(28px); }
to { opacity: 1; transform: translateY(0); }
}
.fade-up {
animation: fade-up 0.7s ease both;
}
.fade-up-d1 { animation-delay: 0.1s; }
.fade-up-d2 { animation-delay: 0.2s; }
.fade-up-d3 { animation-delay: 0.3s; }
.fade-up-d4 { animation-delay: 0.4s; }
.fade-up-d5 { animation-delay: 0.5s; }
/* Code syntax colors */
.syn-kw { color: #c084fc; }
.syn-fn { color: #60a5fa; }
.syn-str { color: #34d399; }
.syn-cm { color: #525252; }
.syn-num { color: #fb923c; }
.syn-type { color: #22d3ee; }
.syn-op { color: #a1a1aa; }
</style>
</head>
<body class="grid-bg min-h-screen">
<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@18.3.1/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js"></script>
<script crossorigin src="https://unpkg.com/@babel/standalone@7/babel.min.js"></script>
<script type="text/babel">
const { useState, useEffect, useCallback, useRef, useMemo } = React;
/* ── Utilities ── */
function cn(...args) {
return args.filter(Boolean).join(" ");
}
function useLocalStorage(key, initialValue) {
const [stored, setStored] = useState(() => {
try {
const raw = localStorage.getItem(key);
return raw != null ? JSON.parse(raw) : initialValue;
} catch { return initialValue; }
});
const setValue = useCallback((value) => {
setStored((prev) => {
const next = value instanceof Function ? value(prev) : value;
try { localStorage.setItem(key, JSON.stringify(next)); } catch {}
return next;
});
}, [key]);
return [stored, setValue];
}
/* ── useResizable Hook ── */
function useResizable({ storageKey, orientation, panels }) {
const containerRef = useRef(null);
const [savedSizes, setSavedSizes] = useLocalStorage("resizable-" + storageKey, null);
const [sizes, setSizesState] = useState([]);
const [dragging, setDragging] = useState(false);
const flexIndex = panels.findIndex((p) => p.flex);
const effectiveFlexIndex = flexIndex >= 0 ? flexIndex : panels.length - 1;
const initSizes = useCallback((containerSize) => {
if (savedSizes && savedSizes.length === panels.length) {
const total = savedSizes.reduce((a, b) => a + b, 0);
if (Math.abs(total - containerSize) < containerSize * 0.3) {
const adjusted = [...savedSizes];
adjusted[effectiveFlexIndex] = Math.max(
panels[effectiveFlexIndex]?.minSize ?? 50,
adjusted[effectiveFlexIndex] + (containerSize - total)
);
return adjusted;
}
}
return panels.map((p) => (p.defaultSize / 100) * containerSize);
}, [panels, savedSizes, effectiveFlexIndex]);
useEffect(() => {
const el = containerRef.current;
if (!el) return;
const measure = () => {
const cs = orientation === "horizontal" ? el.offsetWidth : el.offsetHeight;
if (cs <= 0) return;
setSizesState((prev) => {
if (prev.length === 0) return initSizes(cs);
const nonFlex = prev.reduce((s, v, i) => i === effectiveFlexIndex ? s : s + v, 0);
const nf = Math.max(panels[effectiveFlexIndex]?.minSize ?? 50, cs - nonFlex);
return prev.map((s, i) => i === effectiveFlexIndex ? nf : s);
});
};
measure();
const obs = new ResizeObserver(measure);
obs.observe(el);
return () => obs.disconnect();
}, [orientation, panels.length, effectiveFlexIndex, initSizes]);
const dragState = useRef(null);
const startDrag = useCallback((handleIndex, startPos) => {
dragState.current = { handleIndex, startPos, startSizes: [...sizes] };
setDragging(true);
}, [sizes]);
useEffect(() => {
if (!dragging) return;
const onMove = (e) => {
const ds = dragState.current;
if (!ds) return;
const pos = orientation === "horizontal" ? e.clientX : e.clientY;
const delta = pos - ds.startPos;
const i = ds.handleIndex, j = i + 1;
let a = ds.startSizes[i] + delta, b = ds.startSizes[j] - delta;
const mA = panels[i]?.minSize ?? 30, mB = panels[j]?.minSize ?? 30;
const xA = panels[i]?.maxSize ?? Infinity, xB = panels[j]?.maxSize ?? Infinity;
if (a < mA) { b += a - mA; a = mA; }
if (b < mB) { a += b - mB; b = mB; }
if (a > xA) { b += a - xA; a = xA; }
if (b > xB) { a += b - xB; b = xB; }
a = Math.max(mA, Math.min(xA, a));
b = Math.max(mB, Math.min(xB, b));
setSizesState((prev) => { const n = [...prev]; n[i] = a; n[j] = b; return n; });
};
const onUp = () => {
dragState.current = null;
setDragging(false);
setSizesState((c) => { setSavedSizes(c); return c; });
};
document.addEventListener("pointermove", onMove);
document.addEventListener("pointerup", onUp);
return () => { document.removeEventListener("pointermove", onMove); document.removeEventListener("pointerup", onUp); };
}, [dragging, orientation, panels, setSavedSizes]);
return { sizes, startDrag, containerRef, dragging };
}
/* ── Components ── */
function ResizableGroup({ storageKey, orientation, panels, children, className }) {
const { sizes, startDrag, containerRef, dragging } = useResizable({ storageKey, orientation, panels });
const isH = orientation === "horizontal";
const childArray = React.Children.toArray(children);
const elements = [];
let panelIdx = 0;
for (let i = 0; i < childArray.length; i++) {
const child = childArray[i];
if (React.isValidElement(child) && child.type === ResizableHandle) {
const hi = panelIdx - 1;
elements.push(React.cloneElement(child, {
key: "handle-" + hi,
_orientation: orientation,
_onDragStart: (sp) => startDrag(hi, sp),
}));
} else {
const size = sizes[panelIdx];
const style = size != null
? { [isH ? "width" : "height"]: size, flexShrink: 0, flexGrow: 0, overflow: "hidden" }
: { flex: 1 };
elements.push(<div key={"panel-" + panelIdx} style={style} className="min-w-0 min-h-0">{child}</div>);
panelIdx++;
}
}
return (
<div ref={containerRef}
className={cn("flex h-full w-full", isH ? "flex-row" : "flex-col", dragging && "select-none", className)}
style={dragging ? { cursor: isH ? "col-resize" : "row-resize" } : undefined}>
{elements}
</div>
);
}
function ResizableHandle({ className, children, _orientation, _onDragStart, ...rest }) {
const orientation = _orientation || "horizontal";
const isH = orientation === "horizontal";
const onDown = useCallback((e) => {
e.preventDefault();
_onDragStart?.(isH ? e.clientX : e.clientY);
}, [_onDragStart, isH]);
return (
<div role="separator" aria-orientation={isH ? "vertical" : "horizontal"} onPointerDown={onDown}
className={cn(
"relative flex items-center justify-center shrink-0 bg-border transition-colors hover:bg-primary/10 active:bg-primary/20",
isH ? "w-1.5 cursor-col-resize" : "h-1.5 cursor-row-resize",
className
)}>
{children ?? <DefaultGrip orientation={orientation} />}
</div>
);
}
function DefaultGrip({ orientation }) {
const isH = orientation === "horizontal";
return (
<div className={cn("flex items-center justify-center rounded-sm bg-border border border-border", isH ? "h-6 w-3" : "w-6 h-3")}>
<div className={cn("flex gap-px", isH ? "flex-col" : "flex-row")}>
<div className="rounded-full bg-muted-foreground/40 h-0.5 w-0.5" />
<div className="rounded-full bg-muted-foreground/40 h-0.5 w-0.5" />
<div className="rounded-full bg-muted-foreground/40 h-0.5 w-0.5" />
</div>
</div>
);
}
function ResizablePanel({ children, className }) {
return <div className={cn("h-full w-full", className)}>{children}</div>;
}
/* ── FadeIn ── */
function FadeIn({ children, delay = 0, className = "" }) {
const ref = useRef(null);
const [vis, setVis] = useState(false);
useEffect(() => {
const obs = new IntersectionObserver(([e]) => { if (e.isIntersecting) setVis(true); }, { threshold: 0.08 });
if (ref.current) obs.observe(ref.current);
return () => obs.disconnect();
}, []);
return (
<div ref={ref} className={className} style={{
opacity: vis ? 1 : 0,
transform: vis ? "translateY(0)" : "translateY(24px)",
transition: `opacity 0.7s ease ${delay}s, transform 0.7s ease ${delay}s`,
}}>
{children}
</div>
);
}
/* ── Copy button ── */
function CopyBtn({ text }) {
const [copied, setCopied] = useState(false);
const copy = () => {
navigator.clipboard.writeText(text).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 2000);
});
};
return (
<button onClick={copy}
className="shrink-0 px-3 py-1 text-xs rounded border border-zinc-700 hover:border-cyan-700 hover:text-cyan-400 transition-colors">
{copied ? "Copied" : "Copy"}
</button>
);
}
/* ── Demo: App Layout (2-panel) ── */
function AppLayoutDemo() {
const navItems = [
{ icon: "◆", label: "Dashboard", active: true },
{ icon: "◇", label: "Projects" },
{ icon: "△", label: "Analytics" },
{ icon: "○", label: "Settings" },
];
const stats = [
{ label: "Revenue", value: "$12,480", change: "+14%" },
{ label: "Users", value: "3,842", change: "+7%" },
{ label: "Uptime", value: "99.98%", change: "+0.02%" },
];
return (
<ResizableGroup storageKey="demo-app" orientation="horizontal"
panels={[
{ id: "nav", defaultSize: 22, minSize: 140, maxSize: 280 },
{ id: "main", defaultSize: 78, minSize: 300, flex: true },
]}>
<ResizablePanel>
<div className="h-full bg-zinc-950/80 p-3 flex flex-col gap-1">
<div className="text-[11px] font-semibold text-cyan-400 tracking-widest uppercase mb-3 px-2">Acme Corp</div>
{navItems.map((n) => (
<div key={n.label} className={cn(
"flex items-center gap-2.5 px-2 py-1.5 rounded text-[11px] cursor-default transition-colors",
n.active ? "bg-cyan-500/10 text-cyan-300" : "text-zinc-500 hover:text-zinc-300"
)}>
<span className="text-[9px]">{n.icon}</span>
{n.label}
</div>
))}
<div className="mt-auto px-2 py-1.5 text-[10px] text-zinc-600">v2.4.1</div>
</div>
</ResizablePanel>
<ResizableHandle />
<ResizablePanel>
<div className="h-full bg-zinc-900/60 p-4 overflow-auto">
<div className="text-[11px] text-zinc-500 mb-1">Overview</div>
<div className="text-sm font-medium mb-4">Dashboard</div>
<div className="grid grid-cols-3 gap-3">
{stats.map((s) => (
<div key={s.label} className="border border-zinc-800 rounded-lg p-3">
<div className="text-[10px] text-zinc-500 mb-1">{s.label}</div>
<div className="text-sm font-medium">{s.value}</div>
<div className="text-[10px] text-emerald-500 mt-1">{s.change}</div>
</div>
))}
</div>
<div className="mt-4 border border-zinc-800 rounded-lg p-3">
<div className="text-[10px] text-zinc-500 mb-2">Activity</div>
{[...Array(4)].map((_, i) => (
<div key={i} className="flex items-center gap-2 py-1.5 border-t border-zinc-800/50 first:border-0">
<div className="h-1.5 w-1.5 rounded-full bg-cyan-500/40" />
<div className="text-[10px] text-zinc-400 flex-1">
{["Deploy to production", "Database backup complete", "New user signup", "API latency spike resolved"][i]}
</div>
<div className="text-[9px] text-zinc-600">{["2m", "18m", "1h", "3h"][i]}</div>
</div>
))}
</div>
</div>
</ResizablePanel>
</ResizableGroup>
);
}
/* ── Demo: Email Client (3-panel) ── */
function EmailDemo() {
const folders = [
{ name: "Inbox", count: 12 }, { name: "Starred", count: 3 },
{ name: "Sent" }, { name: "Drafts", count: 2 }, { name: "Archive" },
];
const emails = [
{ from: "Sarah Chen", subject: "Q2 roadmap review", time: "10:42", unread: true },
{ from: "DevOps Bot", subject: "Deploy #1847 succeeded", time: "09:15", unread: true },
{ from: "Jake Mueller", subject: "Re: API rate limiting", time: "Fri" },
{ from: "Nora Patel", subject: "Design review tomorrow", time: "Fri" },
{ from: "GitHub", subject: "[better-resizable-panels] New star", time: "Thu" },
{ from: "Alex Rivera", subject: "Coffee next week?", time: "Wed" },
];
const [sel, setSel] = useState(0);
return (
<ResizableGroup storageKey="demo-email" orientation="horizontal"
panels={[
{ id: "folders", defaultSize: 18, minSize: 120, maxSize: 200 },
{ id: "list", defaultSize: 32, minSize: 200 },
{ id: "detail", defaultSize: 50, minSize: 280, flex: true },
]}>
<ResizablePanel>
<div className="h-full bg-zinc-950/80 p-2.5 flex flex-col gap-0.5">
<div className="text-[11px] font-semibold text-zinc-300 tracking-wide px-2 mb-2">Mail</div>
{folders.map((f, i) => (
<div key={f.name} className={cn(
"flex items-center justify-between px-2 py-1.5 rounded text-[11px] cursor-default transition-colors",
i === 0 ? "bg-cyan-500/10 text-cyan-300" : "text-zinc-500 hover:text-zinc-300"
)}>
<span>{f.name}</span>
{f.count && <span className="text-[9px] bg-zinc-800 px-1.5 py-0.5 rounded-full">{f.count}</span>}
</div>
))}
</div>
</ResizablePanel>
<ResizableHandle />
<ResizablePanel>
<div className="h-full bg-zinc-900/40 overflow-auto">
{emails.map((e, i) => (
<div key={i} onClick={() => setSel(i)}
className={cn(
"px-3 py-2.5 border-b border-zinc-800/50 cursor-default transition-colors",
sel === i ? "bg-cyan-500/5" : "hover:bg-zinc-800/30",
)}>
<div className="flex items-center justify-between mb-0.5">
<span className={cn("text-[11px]", e.unread ? "font-semibold text-zinc-200" : "text-zinc-400")}>{e.from}</span>
<span className="text-[9px] text-zinc-600">{e.time}</span>
</div>
<div className={cn("text-[10px] truncate", e.unread ? "text-zinc-300" : "text-zinc-500")}>{e.subject}</div>
</div>
))}
</div>
</ResizablePanel>
<ResizableHandle />
<ResizablePanel>
<div className="h-full bg-zinc-900/60 p-4 overflow-auto">
<div className="text-sm font-medium mb-1">{emails[sel].subject}</div>
<div className="flex items-center gap-2 mb-4">
<span className="text-[11px] text-cyan-400">{emails[sel].from}</span>
<span className="text-[9px] text-zinc-600">{emails[sel].time}</span>
</div>
<div className="text-[11px] text-zinc-400 leading-relaxed space-y-2">
<p>Hey team,</p>
<p>Just wanted to follow up on this. I've reviewed the latest changes and everything looks good to ship. The performance numbers are solid — p99 latency dropped from 240ms to 85ms after the caching layer went in.</p>
<p>Let me know if you need anything else before we merge.</p>
<p className="text-zinc-500">— {emails[sel].from}</p>
</div>
</div>
</ResizablePanel>
</ResizableGroup>
);
}
/* ── Demo: IDE Layout (nested) ── */
function IDEDemo() {
const files = [
{ depth: 0, name: "src", open: true },
{ depth: 1, name: "components", open: true },
{ depth: 2, name: "Button.tsx", ext: "tsx" },
{ depth: 2, name: "Dialog.tsx", ext: "tsx" },
{ depth: 1, name: "hooks", open: true },
{ depth: 2, name: "useResizable.ts", ext: "ts" },
{ depth: 1, name: "App.tsx", ext: "tsx" },
{ depth: 1, name: "main.ts", ext: "ts" },
];
const codeLines = [
{ num: 1, content: <><span className="syn-kw">import</span> {"React "}<span className="syn-kw">from</span> <span className="syn-str">"react"</span>;</> },
{ num: 2, content: <><span className="syn-kw">import</span> {" { "}<span className="syn-fn">useResizable</span>{" } "}<span className="syn-kw">from</span> <span className="syn-str">"./hooks/useResizable"</span>;</> },
{ num: 3, content: "" },
{ num: 4, content: <><span className="syn-kw">interface</span> <span className="syn-type">PanelProps</span> {"{"}</> },
{ num: 5, content: <>{" "}<span className="syn-fn">minSize</span><span className="syn-op">?:</span> <span className="syn-type">number</span>;</> },
{ num: 6, content: <>{" "}<span className="syn-fn">flex</span><span className="syn-op">?:</span> <span className="syn-type">boolean</span>;</> },
{ num: 7, content: <>{"}"}</> },
{ num: 8, content: "" },
{ num: 9, content: <><span className="syn-kw">export function</span> <span className="syn-fn">Panel</span>{"({ "}<span className="syn-fn">minSize</span> = <span className="syn-num">200</span>{" }: "}<span className="syn-type">PanelProps</span>{") {"}</> },
{ num: 10, content: <>{" "}<span className="syn-kw">const</span> {"{ sizes } = "}<span className="syn-fn">useResizable</span>({"{"}</> },
{ num: 11, content: <>{" storageKey: "}<span className="syn-str">"panel"</span>,</> },
{ num: 12, content: <>{" orientation: "}<span className="syn-str">"horizontal"</span>,</> },
{ num: 13, content: <>{" }"});</> },
{ num: 14, content: "" },
{ num: 15, content: <>{" "}<span className="syn-kw">return</span> {"<"}<span className="syn-type">div</span> <span className="syn-fn">style</span>={"{"}{"{ width: sizes[0] }"}{"}"}{">"}{"..."}<span className="syn-op">{"</"}</span><span className="syn-type">div</span><span className="syn-op">{">"}</span>;</> },
{ num: 16, content: <>{"}"}</> },
];
const termLines = [
{ prompt: true, text: "bun run dev" },
{ text: "$ bun ./src/main.ts", dim: true },
{ text: "" },
{ text: " ➜ Local: http://localhost:3000/", color: "text-cyan-400" },
{ text: " ➜ Network: http://192.168.1.42:3000/", dim: true },
{ text: "" },
{ text: "[0.8ms] HMR connected", dim: true },
];
return (
<ResizableGroup storageKey="demo-ide" orientation="horizontal"
panels={[
{ id: "tree", defaultSize: 20, minSize: 130, maxSize: 260 },
{ id: "editor-area", defaultSize: 80, minSize: 400, flex: true },
]}>
<ResizablePanel>
<div className="h-full bg-zinc-950/80 p-2 overflow-auto">
<div className="text-[10px] text-zinc-600 uppercase tracking-widest px-1.5 mb-2">Explorer</div>
{files.map((f, i) => (
<div key={i} className="flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] cursor-default hover:bg-zinc-800/40 transition-colors"
style={{ paddingLeft: 6 + f.depth * 12 }}>
{f.ext ? (
<span className={cn("text-[8px]", f.ext === "tsx" ? "text-cyan-500" : "text-yellow-500")}>●</span>
) : (
<span className="text-[9px] text-zinc-600">{f.open ? "▾" : "▸"}</span>
)}
<span className={f.ext ? "text-zinc-300" : "text-zinc-400 font-medium"}>{f.name}</span>
</div>
))}
</div>
</ResizablePanel>
<ResizableHandle />
<ResizablePanel>
<ResizableGroup storageKey="demo-ide-v" orientation="vertical"
panels={[
{ id: "editor", defaultSize: 65, minSize: 100, flex: true },
{ id: "terminal", defaultSize: 35, minSize: 80 },
]}>
<ResizablePanel>
<div className="h-full bg-zinc-900/60 overflow-auto">
<div className="flex items-center border-b border-zinc-800/50">
<div className="px-3 py-1.5 text-[10px] text-cyan-400 border-b border-cyan-500 bg-zinc-900/60">App.tsx</div>
<div className="px-3 py-1.5 text-[10px] text-zinc-600">main.ts</div>
</div>
<div className="p-3 font-mono">
{codeLines.map((l) => (
<div key={l.num} className="flex text-[10.5px] leading-[18px]">
<span className="w-7 shrink-0 text-right pr-3 text-zinc-700 select-none">{l.num}</span>
<span className="text-zinc-300 whitespace-pre">{l.content}</span>
</div>
))}
</div>
</div>
</ResizablePanel>
<ResizableHandle />
<ResizablePanel>
<div className="h-full bg-zinc-950/90 overflow-auto">
<div className="flex items-center border-b border-zinc-800/50 px-3 py-1 text-[10px] text-zinc-500">
Terminal
</div>
<div className="p-3 font-mono">
{termLines.map((l, i) => (
<div key={i} className={cn("text-[10.5px] leading-[18px]", l.color, l.dim && "text-zinc-600", !l.color && !l.dim && "text-zinc-300")}>
{l.prompt && <span className="text-emerald-500">❯ </span>}
{l.text}
</div>
))}
</div>
</div>
</ResizablePanel>
</ResizableGroup>
</ResizablePanel>
</ResizableGroup>
);
}
/* ── App ── */
const INSTALL_CMD = "npx shadcn@latest add https://rbby.dev/better-resizable-panels/r/resizable-panels.json";
function App() {
const features = [
{ title: "Pixel min/max", desc: "Constraints in real pixels, not percentages that shift with viewport." },
{ title: "Flex panel", desc: "One panel absorbs container resizes. Others stay fixed." },
{ title: "Persistent", desc: "Sizes saved to localStorage. Survives reloads and reasonable window changes." },
{ title: "Zero deps", desc: "Two small files. React + Tailwind. No runtime libraries." },
];
const demos = [
{ title: "App Layout", desc: "Two-panel sidebar with min/max constraints", component: <AppLayoutDemo /> },
{ title: "Email Client", desc: "Three-panel with independent resizing", component: <EmailDemo /> },
{ title: "IDE Layout", desc: "Nested horizontal + vertical splits", component: <IDEDemo /> },
];
return (
<div className="max-w-5xl mx-auto px-6 py-16">
{/* Hero */}
<header className="mb-20">
<div className="fade-up">
<h1 className="font-display italic text-5xl md:text-7xl tracking-tight mb-4">
Better Resizable<br />
<span className="text-cyan-400">Panels</span>
</h1>
</div>
<p className="fade-up fade-up-d1 text-sm text-zinc-400 max-w-lg leading-relaxed mb-8">
Pixel-accurate resizable panels for React. Drag handles with min/max constraints,
a flex panel that absorbs container resizes, and automatic localStorage persistence.
Two files, zero runtime dependencies.
</p>
<div className="fade-up fade-up-d2 flex items-center gap-2 bg-zinc-900/80 border border-zinc-800 rounded-lg px-4 py-3 max-w-2xl">
<span className="text-cyan-600 text-xs shrink-0">$</span>
<code className="text-[11px] text-zinc-300 flex-1 overflow-x-auto whitespace-nowrap scrollbar-none">{INSTALL_CMD}</code>
<CopyBtn text={INSTALL_CMD} />
</div>
<div className="fade-up fade-up-d3 flex items-center gap-4 mt-6">
<a href="https://github.com/rbbydotdev/better-resizable-panels" target="_blank" rel="noopener"
className="text-[11px] text-zinc-500 hover:text-cyan-400 transition-colors underline underline-offset-2 decoration-zinc-700 hover:decoration-cyan-700">
GitHub
</a>
<a href="https://github.com/rbbydotdev/better-resizable-panels#readme" target="_blank" rel="noopener"
className="text-[11px] text-zinc-500 hover:text-cyan-400 transition-colors underline underline-offset-2 decoration-zinc-700 hover:decoration-cyan-700">
Documentation
</a>
<span className="text-[10px] text-zinc-700">MIT License</span>
</div>
</header>
{/* Features */}
<FadeIn className="mb-20">
<div className="text-[10px] text-cyan-600 uppercase tracking-[0.2em] mb-4">Why better?</div>
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
{features.map((f, i) => (
<FadeIn key={f.title} delay={i * 0.08}>
<div className="border border-zinc-800/60 rounded-lg p-4 hover:border-zinc-700 transition-colors h-full">
<div className="text-xs font-medium text-zinc-200 mb-1.5">{f.title}</div>
<div className="text-[10.5px] text-zinc-500 leading-relaxed">{f.desc}</div>
</div>
</FadeIn>
))}
</div>
</FadeIn>
{/* Demos */}
<div className="space-y-12">
<FadeIn>
<div className="text-[10px] text-cyan-600 uppercase tracking-[0.2em] mb-1">Interactive demos</div>
<div className="text-[11px] text-zinc-600">Drag the handles to resize. Sizes persist in localStorage.</div>
</FadeIn>
{demos.map((d, i) => (
<FadeIn key={d.title} delay={0.05}>
<div className="space-y-3">
<div>
<div className="text-sm font-medium text-zinc-200">{d.title}</div>
<div className="text-[10.5px] text-zinc-500">{d.desc}</div>
</div>
<div className="border border-zinc-800 rounded-xl overflow-hidden glow" style={{ height: i === 2 ? 420 : 360 }}>
{d.component}
</div>
</div>
</FadeIn>
))}
</div>
{/* Quick start */}
<FadeIn className="mt-20">
<div className="border border-zinc-800 rounded-xl p-6 bg-zinc-900/30">
<div className="text-[10px] text-cyan-600 uppercase tracking-[0.2em] mb-4">Quick start</div>
<pre className="text-[11px] text-zinc-300 leading-relaxed overflow-x-auto"><code>{
`import {
ResizableGroup,
ResizableHandle,
ResizablePanel,
} from "@/components/ui/resizable-panels";
<ResizableGroup
storageKey="my-layout"
orientation="horizontal"
panels={[
{ id: "sidebar", defaultSize: 25, minSize: 200 },
{ id: "main", defaultSize: 75, minSize: 400, flex: true },
]}
>
<ResizablePanel>Sidebar</ResizablePanel>
<ResizableHandle />
<ResizablePanel>Content</ResizablePanel>
</ResizableGroup>`
}</code></pre>
</div>
</FadeIn>
{/* Footer */}
<footer className="mt-16 pt-8 border-t border-zinc-800/50 flex items-center justify-between">
<div className="text-[10px] text-zinc-600">
Built by{" "}
<a href="https://github.com/rbbydotdev" target="_blank" rel="noopener" className="text-zinc-500 hover:text-cyan-400 transition-colors">
@rbbydotdev
</a>
</div>
<div className="text-[10px] text-zinc-700">
shadcn registry component
</div>
</footer>
</div>
);
}
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
</script>
</body>
</html>