Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

layout.ts

34 lines933 Bytes

1function clamp(value: number, min: number, max: number): number {
2 return Math.min(Math.max(value, min), max);
3}
4​
5export type LayoutVariant = "compact" | "split";
6​
7export interface Layout {
8 readonly variant: LayoutVariant;
9 readonly usesSplitView: boolean;
10 readonly listPaneWidth: number | null;
11 readonly shellPadding: number;
13​
14export function deriveLayout(input: { readonly width: number; readonly height: number }): Layout {
15 const { width, height } = input;
16 const shortestEdge = Math.min(width, height);
17 const wideEnoughForSplit = width >= 900 || (width >= 700 && shortestEdge >= 700);
18​
19 if (!wideEnoughForSplit) {
20 return {
21 variant: "compact",
22 usesSplitView: false,
23 listPaneWidth: null,
24 shellPadding: 0,
25 };
26 }
27​
28 return {
29 variant: "split",
30 usesSplitView: true,
31 listPaneWidth: clamp(Math.round(width * 0.34), 320, 420),
32 shellPadding: width >= 1180 ? 20 : 14,
33 };