mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: resize sidebar feature.
This commit is contained in:
42
client/src/components/Dashboard/DashboardSplitePane.js
Normal file
42
client/src/components/Dashboard/DashboardSplitePane.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import React, { useState, useRef } from 'react';
|
||||
import SplitPane from 'react-split-pane';
|
||||
import { debounce } from 'lodash';
|
||||
|
||||
import withDashboard from 'containers/Dashboard/withDashboard';
|
||||
import { compose } from 'utils';
|
||||
|
||||
function DashboardSplitPane({
|
||||
sidebarExpended,
|
||||
children
|
||||
}) {
|
||||
const [defaultSize, setDefaultSize] = useState(
|
||||
parseInt(localStorage.getItem('dashboard-size'), 10) || 220,
|
||||
);
|
||||
const debounceSaveSize = useRef(
|
||||
debounce((size) => {
|
||||
localStorage.setItem('dashboard-size', size);
|
||||
}, 500),
|
||||
);
|
||||
const handleChange = (size) => {
|
||||
debounceSaveSize.current(size);
|
||||
setDefaultSize(size);
|
||||
}
|
||||
return (
|
||||
<SplitPane
|
||||
allowResize={sidebarExpended}
|
||||
split="vertical"
|
||||
minSize={180}
|
||||
maxSize={300}
|
||||
defaultSize={sidebarExpended ? defaultSize : 50}
|
||||
size={sidebarExpended ? defaultSize : 50}
|
||||
onChange={handleChange}
|
||||
className="primary"
|
||||
>
|
||||
{children}
|
||||
</SplitPane>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDashboard(({ sidebarExpended }) => ({ sidebarExpended }))
|
||||
)(DashboardSplitPane);
|
||||
Reference in New Issue
Block a user