forge
Explore
Log in

Don't you dare go Hollow

↔️ let every side panel be resized and expanded

Browse files at this commit

fe60954caf78d307feb2fb820b468331f3a8a89cBurak BoduroğluParent: 7eac1f2
  • feat
    • ↔️ let every side panel be resized and expanded
Show full message
feat: ↔️ let every side panel be resized and expanded

- drag the panel's left edge to set its width (keyboard: arrows, Home
  resets; double-click resets); the width is kept in localStorage and
  shared by all panels, clamped to leave the page visible behind it
- an expand / restore button in the header toggles a ~1120px panel
- phones keep the full-screen panel; the handle sits last in the DOM so
  opening a panel does not focus it
src/components/ui/side-panel.tsxmodified+114 -2
@@ -1,12 +1,38 @@
1 import { Dialog as DialogPrimitive } from "@kobalte/core/dialog";1 import { Dialog as DialogPrimitive } from "@kobalte/core/dialog";
2 import { createEffect, createSignal, onCleanup, type ParentProps } from "solid-js";2 import { createEffect, createSignal, onCleanup, type ParentProps } from "solid-js";
3 import { ConfirmDialog } from "@/components/ui/confirm-dialog";3 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
4-import { IconAlert, IconX } from "@/components/ui/icons";4+import { IconAlert, IconMaximize, IconMinimize, IconX } from "@/components/ui/icons";
5 import { cn } from "@/lib/cn";5 import { cn } from "@/lib/cn";
6 import { useT } from "@/stores/preferences-context";6 import { useT } from "@/stores/preferences-context";
7 7
8 let openPanelCount = 0;8 let openPanelCount = 0;
9 9
10+/** Width the user dragged or expanded a panel to; one value for every panel. */
11+const WIDTH_KEY = "hezarfen.sidePanel.width";
12+const MIN_WIDTH = 360;
13+/** Room kept free on the left so the page behind still reads as "behind". */
14+const PAGE_GUTTER = 64;
15+const EXPANDED_WIDTH = 1120;
16+
17+const maxPanelWidth = () => (typeof window === "undefined" ? EXPANDED_WIDTH : Math.max(MIN_WIDTH, window.innerWidth - PAGE_GUTTER));
18+const clampWidth = (value: number) => Math.round(Math.min(Math.max(value, MIN_WIDTH), maxPanelWidth()));
19+const readStoredWidth = (): number | null => {
20+ try {
21+ const value = Number(localStorage.getItem(WIDTH_KEY));
22+ return Number.isFinite(value) && value > 0 ? value : null;
23+ } catch {
24+ return null;
25+ }
26+};
27+const storeWidth = (value: number | null) => {
28+ try {
29+ if (value == null) localStorage.removeItem(WIDTH_KEY);
30+ else localStorage.setItem(WIDTH_KEY, String(value));
31+ } catch {
32+ // Private mode: the width lasts for this page only.
33+ }
34+};
35+
10 export function SidePanel(36 export function SidePanel(
11 props: ParentProps<{37 props: ParentProps<{
12 open: boolean;38 open: boolean;
@@ -71,6 +97,65 @@ export function SidePanel(
71 return "max-w-[min(34rem,100vw)]";97 return "max-w-[min(34rem,100vw)]";
72 };98 };
73 99
100+ // A user-chosen width, dragged from the left edge or set by the expand
101+ // button, overrides the size preset on screens wide enough to have a page
102+ // beside the panel. Phones keep the full-screen panel.
103+ const [customWidth, setCustomWidth] = createSignal<number | null>(readStoredWidth());
104+ const roomyQuery = () =>
105+ typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia("(min-width: 640px)") : null;
106+ const [roomy, setRoomy] = createSignal(roomyQuery()?.matches ?? false);
107+ createEffect(() => {
108+ if (!props.open) return;
109+ const query = roomyQuery();
110+ if (!query) return;
111+ const sync = () => setRoomy(query.matches);
112+ sync();
113+ query.addEventListener("change", sync);
114+ onCleanup(() => query.removeEventListener("change", sync));
115+ });
116+ const appliedWidth = () => {
117+ const value = customWidth();
118+ return roomy() && value != null ? clampWidth(value) : null;
119+ };
120+ const expanded = () => (appliedWidth() ?? 0) >= clampWidth(EXPANDED_WIDTH) - 8;
121+ const setWidth = (value: number | null) => {
122+ setCustomWidth(value == null ? null : clampWidth(value));
123+ storeWidth(value == null ? null : clampWidth(value));
124+ };
125+ const toggleExpanded = () => setWidth(expanded() ? null : EXPANDED_WIDTH);
126+ const startResize = (event: PointerEvent) => {
127+ if (event.button !== 0) return;
128+ event.preventDefault();
129+ const handle = event.currentTarget as HTMLElement;
130+ try {
131+ handle.setPointerCapture(event.pointerId);
132+ } catch {
133+ // No active pointer to capture (synthetic events); moves still arrive.
134+ }
135+ const previousCursor = document.body.style.cursor;
136+ document.body.style.cursor = "col-resize";
137+ const move = (moveEvent: PointerEvent) => setCustomWidth(clampWidth(window.innerWidth - moveEvent.clientX));
138+ const stop = () => {
139+ handle.removeEventListener("pointermove", move);
140+ handle.removeEventListener("pointerup", stop);
141+ handle.removeEventListener("pointercancel", stop);
142+ document.body.style.cursor = previousCursor;
143+ storeWidth(customWidth());
144+ };
145+ handle.addEventListener("pointermove", move);
146+ handle.addEventListener("pointerup", stop);
147+ handle.addEventListener("pointercancel", stop);
148+ };
149+ const resizeByKey = (event: KeyboardEvent) => {
150+ const step = event.shiftKey ? 80 : 24;
151+ const current = appliedWidth() ?? (event.currentTarget as HTMLElement).parentElement?.getBoundingClientRect().width ?? MIN_WIDTH;
152+ if (event.key === "ArrowLeft") setWidth(current + step);
153+ else if (event.key === "ArrowRight") setWidth(current - step);
154+ else if (event.key === "Home") setWidth(null);
155+ else return;
156+ event.preventDefault();
157+ };
158+
74 return (159 return (
75 <>160 <>
76 <DialogPrimitive open={props.open} onOpenChange={requestOpenChange} modal={false} preventScroll>161 <DialogPrimitive open={props.open} onOpenChange={requestOpenChange} modal={false} preventScroll>
@@ -102,8 +187,9 @@ export function SidePanel(
102 width(),187 width(),
103 props.class,188 props.class,
104 )}189 )}
190+ style={appliedWidth() != null ? { width: `${appliedWidth()}px`, "max-width": "100vw" } : undefined}
105 >191 >
106- <div class="flex shrink-0 items-start justify-between gap-4 border-b border-border-hairline px-5 py-4">192+ <div class="flex shrink-0 items-start justify-between gap-2 border-b border-border-hairline px-5 py-4">
107 <div class="min-w-0 flex-1 space-y-1">193 <div class="min-w-0 flex-1 space-y-1">
108 <DialogPrimitive.Title class="truncate text-base font-semibold leading-6 tracking-tight">194 <DialogPrimitive.Title class="truncate text-base font-semibold leading-6 tracking-tight">
109 {props.title}195 {props.title}
@@ -114,6 +200,15 @@ export function SidePanel(
114 </DialogPrimitive.Description>200 </DialogPrimitive.Description>
115 )}201 )}
116 </div>202 </div>
203+ <button
204+ type="button"
205+ aria-label={expanded() ? t("sidePanel.collapse") : t("sidePanel.expand")}
206+ title={expanded() ? t("sidePanel.collapse") : t("sidePanel.expand")}
207+ class="hidden h-9 w-9 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring sm:inline-flex"
208+ onClick={toggleExpanded}
209+ >
210+ {expanded() ? <IconMinimize class="h-4 w-4" /> : <IconMaximize class="h-4 w-4" />}
211+ </button>
117 <DialogPrimitive.CloseButton212 <DialogPrimitive.CloseButton
118 type="button"213 type="button"
119 aria-label={t("common.close")}214 aria-label={t("common.close")}
@@ -135,6 +230,23 @@ export function SidePanel(
135 >230 >
136 {props.children}231 {props.children}
137 </div>232 </div>
233+ {/* Drag the left edge to resize; double-click or Home resets. Last in
234+ the DOM so opening the panel does not focus it first. */}
235+ <div
236+ role="separator"
237+ aria-orientation="vertical"
238+ aria-label={t("sidePanel.resize")}
239+ aria-valuemin={MIN_WIDTH}
240+ aria-valuemax={maxPanelWidth()}
241+ aria-valuenow={appliedWidth() ?? undefined}
242+ tabIndex={0}
243+ class="group/resize absolute inset-y-0 -left-1.5 z-10 hidden w-3 cursor-col-resize touch-none outline-hidden sm:block"
244+ onPointerDown={startResize}
245+ onDblClick={() => setWidth(null)}
246+ onKeyDown={resizeByKey}
247+ >
248+ <span class="absolute inset-y-0 left-1/2 w-0.5 -translate-x-1/2 bg-transparent transition-colors group-hover/resize:bg-primary/60 group-focus-visible/resize:bg-primary" />
249+ </div>
138 </DialogPrimitive.Content>250 </DialogPrimitive.Content>
139 </DialogPrimitive.Portal>251 </DialogPrimitive.Portal>
140 </DialogPrimitive>252 </DialogPrimitive>
src/i18n/locales/en.tsmodified+3 -0
@@ -789,6 +789,9 @@ export const en: Dict = {
789 "sidePanel.discardSummary": "What you entered in this form has not been saved and will be lost.",789 "sidePanel.discardSummary": "What you entered in this form has not been saved and will be lost.",
790 "sidePanel.discard": "Discard changes",790 "sidePanel.discard": "Discard changes",
791 "sidePanel.keepEditing": "Keep editing",791 "sidePanel.keepEditing": "Keep editing",
792+ "sidePanel.expand": "Expand panel",
793+ "sidePanel.collapse": "Restore panel width",
794+ "sidePanel.resize": "Resize panel",
792 "dashboard.partialError": "Some panels could not load and show no data.",795 "dashboard.partialError": "Some panels could not load and show no data.",
793 "common.breadcrumb": "Breadcrumb",796 "common.breadcrumb": "Breadcrumb",
794 "common.truncatedNotice": "Showing the first {shown} of {total} records.",797 "common.truncatedNotice": "Showing the first {shown} of {total} records.",
src/i18n/locales/tr.tsmodified+3 -0
@@ -785,6 +785,9 @@ export const tr: Dict = {
785 "sidePanel.discardSummary": "Bu forma girdikleriniz kaydedilmedi ve kaybolacak.",785 "sidePanel.discardSummary": "Bu forma girdikleriniz kaydedilmedi ve kaybolacak.",
786 "sidePanel.discard": "Değişiklikleri at",786 "sidePanel.discard": "Değişiklikleri at",
787 "sidePanel.keepEditing": "Düzenlemeye devam et",787 "sidePanel.keepEditing": "Düzenlemeye devam et",
788+ "sidePanel.expand": "Paneli genişlet",
789+ "sidePanel.collapse": "Paneli daralt",
790+ "sidePanel.resize": "Panel genişliğini ayarla",
788 "dashboard.partialError": "Bazı bölümler yüklenemedi ve veri göstermiyor.",791 "dashboard.partialError": "Bazı bölümler yüklenemedi ve veri göstermiyor.",
789 "common.breadcrumb": "Sayfa konumu",792 "common.breadcrumb": "Sayfa konumu",
790 "common.truncatedNotice": "{total} kayıttan ilk {shown} tanesi gösteriliyor.",793 "common.truncatedNotice": "{total} kayıttan ilk {shown} tanesi gösteriliyor.",
src/i18n/messages.tsmodified+3 -0
@@ -776,6 +776,9 @@ export type MessageKey =
776 | "sidePanel.discardSummary"776 | "sidePanel.discardSummary"
777 | "sidePanel.discard"777 | "sidePanel.discard"
778 | "sidePanel.keepEditing"778 | "sidePanel.keepEditing"
779+ | "sidePanel.expand"
780+ | "sidePanel.collapse"
781+ | "sidePanel.resize"
779 | "dashboard.partialError"782 | "dashboard.partialError"
780 | "common.breadcrumb"783 | "common.breadcrumb"
781 | "common.truncatedNotice"784 | "common.truncatedNotice"