Skip to content

Commit 41c4f3b

Browse files
committed
fixup! ✨(frontend) add resizable left panel on desktop with persistence
1 parent a628380 commit 41c4f3b

File tree

2 files changed

+100
-82
lines changed

2 files changed

+100
-82
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { PropsWithChildren } from 'react';
2+
import { useTranslation } from 'react-i18next';
3+
import { css } from 'styled-components';
4+
5+
import { Box } from '@/components';
6+
import { useCunninghamTheme } from '@/cunningham';
7+
import { LeftPanel } from '@/features/left-panel';
8+
import { MAIN_LAYOUT_ID } from '@/layouts/conf';
9+
import { useResponsiveStore } from '@/stores';
10+
11+
import { HEADER_HEIGHT } from '../../features/header/conf';
12+
import { ResizableLeftPanel } from '../../features/left-panel/components/ResizableLeftPanel';
13+
14+
export interface MainLayoutContentProps {
15+
backgroundColor: 'white' | 'grey';
16+
enableResizablePanel?: boolean;
17+
onResizingChange?: (isResizing: boolean) => void;
18+
}
19+
20+
export function MainLayoutContent({
21+
children,
22+
backgroundColor,
23+
enableResizablePanel = false,
24+
onResizingChange,
25+
}: PropsWithChildren<MainLayoutContentProps>) {
26+
const { isDesktop } = useResponsiveStore();
27+
const { colorsTokens } = useCunninghamTheme();
28+
const { t } = useTranslation();
29+
const currentBackgroundColor = !isDesktop ? 'white' : backgroundColor;
30+
31+
const mainContent = (
32+
<Box
33+
as="main"
34+
role="main"
35+
aria-label={t('Main content')}
36+
id={MAIN_LAYOUT_ID}
37+
$align="center"
38+
$flex={1}
39+
$width="100%"
40+
$height={`calc(100dvh - ${HEADER_HEIGHT}px)`}
41+
$padding={{
42+
all: isDesktop ? 'base' : '0',
43+
}}
44+
$background={
45+
currentBackgroundColor === 'white'
46+
? colorsTokens['greyscale-000']
47+
: colorsTokens['greyscale-050']
48+
}
49+
$css={css`
50+
overflow-y: auto;
51+
overflow-x: clip;
52+
`}
53+
>
54+
{children}
55+
</Box>
56+
);
57+
58+
if (!isDesktop) {
59+
return (
60+
<>
61+
<LeftPanel />
62+
{mainContent}
63+
</>
64+
);
65+
}
66+
67+
if (enableResizablePanel) {
68+
return (
69+
<ResizableLeftPanel
70+
leftPanel={<LeftPanel />}
71+
onResizingChange={onResizingChange}
72+
>
73+
{mainContent}
74+
</ResizableLeftPanel>
75+
);
76+
}
77+
78+
return (
79+
<>
80+
<Box
81+
$css={css`
82+
width: 300px;
83+
min-width: 300px;
84+
border-right: 1px solid ${colorsTokens['greyscale-200']};
85+
`}
86+
>
87+
<LeftPanel />
88+
</Box>
89+
{mainContent}
90+
</>
91+
);
92+
}

src/frontend/apps/impress/src/layouts/MainLayout.tsx

Lines changed: 8 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import { PropsWithChildren, useState } from 'react';
2-
import { useTranslation } from 'react-i18next';
32
import { css } from 'styled-components';
43

54
import { Box } from '@/components';
6-
import { useCunninghamTheme } from '@/cunningham';
5+
import { MainLayoutContent } from '@/components/main-layout/MainLayoutContent';
76
import { Header } from '@/features/header';
87
import { HEADER_HEIGHT } from '@/features/header/conf';
9-
import { LeftPanel } from '@/features/left-panel';
10-
import { MAIN_LAYOUT_ID } from '@/layouts/conf';
11-
import { useResponsiveStore } from '@/stores';
12-
13-
import { ResizableLeftPanel } from '../features/left-panel/components/ResizableLeftPanel';
148

159
type MainLayoutProps = {
1610
backgroundColor?: 'white' | 'grey';
@@ -22,82 +16,8 @@ export function MainLayout({
2216
backgroundColor = 'white',
2317
enableResizablePanel = false,
2418
}: PropsWithChildren<MainLayoutProps>) {
25-
const { isDesktop } = useResponsiveStore();
26-
const { colorsTokens } = useCunninghamTheme();
27-
const currentBackgroundColor = !isDesktop ? 'white' : backgroundColor;
28-
const { t } = useTranslation();
29-
3019
const [isResizing, setIsResizing] = useState(false);
3120

32-
// Main content area (same for all layouts)
33-
const mainContent = (
34-
<Box
35-
as="main"
36-
role="main"
37-
aria-label={t('Main content')}
38-
id={MAIN_LAYOUT_ID}
39-
$align="center"
40-
$flex={1}
41-
$width="100%"
42-
$height={`calc(100dvh - ${HEADER_HEIGHT}px)`}
43-
$padding={{
44-
all: isDesktop ? 'base' : '0',
45-
}}
46-
$background={
47-
currentBackgroundColor === 'white'
48-
? colorsTokens['greyscale-000']
49-
: colorsTokens['greyscale-050']
50-
}
51-
$css={css`
52-
overflow-y: auto;
53-
overflow-x: clip;
54-
`}
55-
>
56-
{children}
57-
</Box>
58-
);
59-
60-
// Render layout based on device and resizable panel setting
61-
const renderContent = () => {
62-
// Mobile: simple layout
63-
if (!isDesktop) {
64-
return (
65-
<>
66-
<LeftPanel />
67-
{mainContent}
68-
</>
69-
);
70-
}
71-
72-
// Desktop with resizable panel
73-
if (enableResizablePanel) {
74-
return (
75-
<ResizableLeftPanel
76-
leftPanel={<LeftPanel />}
77-
onResizingChange={setIsResizing}
78-
>
79-
{mainContent}
80-
</ResizableLeftPanel>
81-
);
82-
}
83-
84-
// Desktop with fixed panel
85-
return (
86-
<>
87-
<Box
88-
$css={css`
89-
width: 300px;
90-
min-width: 300px;
91-
border-right: 1px solid ${colorsTokens['greyscale-200']};
92-
`}
93-
>
94-
<LeftPanel />
95-
</Box>
96-
{mainContent}
97-
</>
98-
);
99-
};
100-
10121
return (
10222
<Box
10323
className={`--docs--main-layout ${isResizing ? 'resizing' : ''}`}
@@ -114,7 +34,13 @@ export function MainLayout({
11434
$width="100%"
11535
$height={`calc(100dvh - ${HEADER_HEIGHT}px)`}
11636
>
117-
{renderContent()}
37+
<MainLayoutContent
38+
backgroundColor={backgroundColor}
39+
enableResizablePanel={enableResizablePanel}
40+
onResizingChange={setIsResizing}
41+
>
42+
{children}
43+
</MainLayoutContent>
11844
</Box>
11945
</Box>
12046
);

0 commit comments

Comments
 (0)