Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/routes/Outlet.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@

/* If empty state or page is shown (not hidden), router outlet (first column) should have max width */
> div:not(:global(.ion-hide)) ~ ion-router-outlet {
max-width: 520px;
flex: 0 0 var(--first-column-width);
max-width: calc(100% - 300px);
}

/* Column divider */
> .columnDivider {
order: 0;
flex: 0 0 auto;
}

/* First column (main content) */
Expand All @@ -42,3 +49,32 @@
}
}
}

/* Resizable divider styles */
.columnDivider {
width: 4px;
background: var(
--ion-toolbar-background,
var(--ion-color-step-50, var(--ion-background-color-step-50, #f7f7f7))
);
cursor: col-resize;
position: relative;
transition: background-color 0.2s ease;
}

.columnDivider:hover,
.columnDivider:active {
background: var(--ion-color-light);
}

.columnDivider::before {
content: "";
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 2px;
height: 20px;
background: var(--ion-color-light);
border-radius: 1px;
}
2 changes: 2 additions & 0 deletions src/routes/Outlet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import buildPostsRoutes from "./tabs/posts";
import profile from "./tabs/profile";
import search from "./tabs/search";
import settings from "./tabs/settings";
import ColumnDivider from "./twoColumn/ColumnDivider";
import SecondColumnContent from "./twoColumn/SecondColumnContent";

import styles from "./Outlet.module.css";
Expand Down Expand Up @@ -51,6 +52,7 @@ function AppRoutes() {

return (
<div className={styles.routerOutletContents}>
{twoColumnLayoutEnabled && <ColumnDivider />}
{twoColumnLayoutEnabled && <SecondColumnContent />}

{/* This is first (order = -1) in css. Why? See Outlet.module.css */}
Expand Down
85 changes: 85 additions & 0 deletions src/routes/twoColumn/ColumnDivider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { useEffect, useRef, useState } from "react";

import { useColumnWidth } from "./useColumnWidth";

import styles from "../Outlet.module.css";

interface ColumnDividerProps {
onResize?: (width: number) => void;
}

export default function ColumnDivider({ onResize }: ColumnDividerProps) {
const dividerRef = useRef<HTMLDivElement>(null);
const [isResizing, setIsResizing] = useState(false);
const [startX, setStartX] = useState(0);
const [startWidth, setStartWidth] = useState(0);
const { updateColumnWidth } = useColumnWidth();

useEffect(() => {
const handleMouseDown = (e: MouseEvent) => {
if (e.target === dividerRef.current) {
console.log("Mouse down on divider");

Check warning on line 21 in src/routes/twoColumn/ColumnDivider.tsx

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement. Only these console methods are allowed: warn, error, info
setIsResizing(true);
setStartX(e.clientX);

// Get current width with fallback to default
const currentWidthStr = getComputedStyle(
document.documentElement,
).getPropertyValue("--first-column-width");
const currentWidth = parseInt(currentWidthStr) || 520; // fallback to 520px
console.log(

Check warning on line 30 in src/routes/twoColumn/ColumnDivider.tsx

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement. Only these console methods are allowed: warn, error, info
"Current width:",
currentWidth,
"raw value:",
currentWidthStr,
);
setStartWidth(currentWidth);

document.body.style.cursor = "col-resize";
document.body.style.userSelect = "none";
}
};

const handleMouseMove = (e: MouseEvent) => {
if (!isResizing) return;

const deltaX = e.clientX - startX;
const newWidth = Math.max(300, Math.min(800, startWidth + deltaX));

console.log("Resizing to:", newWidth, "delta:", deltaX);

Check warning on line 49 in src/routes/twoColumn/ColumnDivider.tsx

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement. Only these console methods are allowed: warn, error, info
updateColumnWidth(newWidth);
onResize?.(newWidth);
};

const handleMouseUp = () => {
console.log("Mouse up, stopping resize");

Check warning on line 55 in src/routes/twoColumn/ColumnDivider.tsx

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement. Only these console methods are allowed: warn, error, info
setIsResizing(false);
document.body.style.cursor = "";
document.body.style.userSelect = "";
};

const divider = dividerRef.current;
if (divider) {
divider.addEventListener("mousedown", handleMouseDown);
}

document.addEventListener("mousemove", handleMouseMove);
document.addEventListener("mouseup", handleMouseUp);

return () => {
if (divider) {
divider.removeEventListener("mousedown", handleMouseDown);
}
document.removeEventListener("mousemove", handleMouseMove);
document.removeEventListener("mouseup", handleMouseUp);
};
}, [isResizing, startX, startWidth, onResize, updateColumnWidth]);

return (
<div
ref={dividerRef}
className={styles.columnDivider}
title="Drag to resize columns"
/>
);
}
36 changes: 36 additions & 0 deletions src/routes/twoColumn/useColumnWidth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useEffect, useState } from "react";

const DEFAULT_WIDTH = 520;
const MIN_WIDTH = 300;
const MAX_WIDTH = 800;

export function useColumnWidth() {
const [columnWidth, setColumnWidth] = useState(DEFAULT_WIDTH);

// Initialize the CSS custom property when the component mounts
useEffect(() => {
document.documentElement.style.setProperty(
"--first-column-width",
`${DEFAULT_WIDTH}px`,
);
console.log("Initialized CSS property to:", DEFAULT_WIDTH);

Check warning on line 16 in src/routes/twoColumn/useColumnWidth.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement. Only these console methods are allowed: warn, error, info
}, []);

const updateColumnWidth = (width: number) => {
const clampedWidth = Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, width));
console.log("Setting column width to:", clampedWidth);

Check warning on line 21 in src/routes/twoColumn/useColumnWidth.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement. Only these console methods are allowed: warn, error, info
setColumnWidth(clampedWidth);
document.documentElement.style.setProperty(
"--first-column-width",
`${clampedWidth}px`,
);
console.log(

Check warning on line 27 in src/routes/twoColumn/useColumnWidth.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement. Only these console methods are allowed: warn, error, info
"CSS property set, checking:",
getComputedStyle(document.documentElement).getPropertyValue(
"--first-column-width",
),
);
};

return { columnWidth, updateColumnWidth };
}
Loading