Skip to content

Commit

Permalink
Resizable split panes
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliohome committed Oct 6, 2023
1 parent 4c87a96 commit b17d978
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.3.0",
"split-pane-react": "^0.1.3",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down Expand Up @@ -75,4 +76,4 @@
}
}
}
}
}
46 changes: 35 additions & 11 deletions src/web/src/layout/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { FC, ReactElement, useContext, useEffect, useMemo } from 'react';
import React, { FC, ReactElement, useContext, useEffect, useMemo, useState } from 'react';
import SplitPane, { Pane, SashContent } from 'split-pane-react';
import 'split-pane-react/esm/themes/default.css';
import Header from './header';
import Sidebar from './sidebar';
import { Routes, Route, useNavigate } from 'react-router-dom';
Expand All @@ -15,7 +17,14 @@ import { headerStackStyles, mainStackStyles, rootStackStyles, sidebarStackStyles
import TodoItemDetailPane from '../components/todoItemDetailPane';
import { bindActionCreators } from '../actions/actionCreators';

const Layout: FC = (): ReactElement => {
const Layout: FC = (): ReactElement => {
const [sizes, setSizes] = useState([ 300, 'auto', '30%']);
const layoutCSS = {
height: '100%',
display: 'flex',
alignItems: 'strech',
justifyContent: 'top'
};
const navigate = useNavigate();
const appContext = useContext<AppContext>(TodoContext)
const actions = useMemo(() => ({
Expand Down Expand Up @@ -49,33 +58,48 @@ const Layout: FC = (): ReactElement => {
}

return (
<Stack styles={rootStackStyles}>
<div style={{ height: 800 }}>
<Stack styles={rootStackStyles}>
<Stack.Item styles={headerStackStyles}>
<Header></Header>
</Stack.Item>
<Stack horizontal grow={1}>
<Stack.Item styles={sidebarStackStyles}>
<SplitPane
split='vertical'
sizes={sizes}
onChange={setSizes}
sashRender={(_, active) => (
<SashContent active={active} type="vscode" />
)}
>
<Pane >
<Stack styles={sidebarStackStyles} style={{ ...layoutCSS}}>
<Sidebar
selectedList={appContext.state.selectedList}
lists={appContext.state.lists}
onListCreate={onListCreated} />
</Stack.Item>
<Stack.Item grow={1} styles={mainStackStyles}>
</Stack>
</Pane>
<Pane>
<Stack styles={mainStackStyles} style={{ ...layoutCSS}}>
<Routes>
<Route path="/lists/:listId/items/:itemId" element={<HomePage />} />
<Route path="/lists/:listId" element={<HomePage />} />
<Route path="/lists" element={<HomePage />} />
<Route path="/" element={<HomePage />} />
</Routes>
</Stack.Item>
<Stack.Item styles={sidebarStackStyles}>
</Stack>
</Pane>
<Pane>
<Stack styles={sidebarStackStyles} style={{ ...layoutCSS}}>
<TodoItemDetailPane
item={appContext.state.selectedItem}
onEdit={onItemEdited}
onCancel={onItemEditCancel} />
</Stack.Item>
</Stack>
</Pane>
</SplitPane>
</Stack>
</Stack>
</div>
);
}

Expand Down

0 comments on commit b17d978

Please sign in to comment.