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

mobileLayout.ts

37 lines968 Bytes

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