Skip to content

Commit

Permalink
[core] Allow changing the width of the drawer in dashboard layout com… (
Browse files Browse the repository at this point in the history
#4296)

Co-authored-by: Pedro Ferreira <[email protected]>
  • Loading branch information
garryxiao and apedroferreira authored Oct 25, 2024
1 parent b126c45 commit 1ef74f0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/pages/toolpad/core/api/dashboard-layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"defaultSidebarCollapsed": { "type": { "name": "bool" }, "default": "false" },
"disableCollapsibleSidebar": { "type": { "name": "bool" }, "default": "false" },
"hideNavigation": { "type": { "name": "bool" }, "default": "false" },
"sidebarExpandedWidth": {
"type": { "name": "union", "description": "number<br>&#124;&nbsp;string" },
"default": "320"
},
"slotProps": {
"type": {
"name": "shape",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"hideNavigation": {
"description": "Whether the navigation bar and menu icon should be hidden"
},
"sidebarExpandedWidth": { "description": "Width of the sidebar when expanded." },
"slotProps": { "description": "The props used for each slot inside." },
"slots": { "description": "The components used for each slot inside." },
"sx": {
Expand Down
15 changes: 13 additions & 2 deletions packages/toolpad-core/src/DashboardLayout/DashboardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export interface DashboardLayoutProps {
* @default false
*/
hideNavigation?: boolean;
/**
* Width of the sidebar when expanded.
* @default 320
*/
sidebarExpandedWidth?: number | string;
/**
* The components used for each slot inside.
* @default {}
Expand Down Expand Up @@ -121,6 +126,7 @@ function DashboardLayout(props: DashboardLayoutProps) {
disableCollapsibleSidebar = false,
defaultSidebarCollapsed = false,
hideNavigation = false,
sidebarExpandedWidth = 320,
slots,
slotProps,
sx,
Expand Down Expand Up @@ -286,7 +292,7 @@ function DashboardLayout(props: DashboardLayoutProps) {

const getDrawerSharedSx = React.useCallback(
(isMini: boolean, isTemporary: boolean) => {
const drawerWidth = isMini ? 64 : 320;
const drawerWidth = isMini ? 64 : sidebarExpandedWidth;

return {
width: drawerWidth,
Expand All @@ -302,7 +308,7 @@ function DashboardLayout(props: DashboardLayoutProps) {
},
};
},
[isNavigationExpanded],
[isNavigationExpanded, sidebarExpandedWidth],
);

const layoutRef = React.useRef<Element | null>(null);
Expand Down Expand Up @@ -469,6 +475,11 @@ DashboardLayout.propTypes /* remove-proptypes */ = {
* @default false
*/
hideNavigation: PropTypes.bool,
/**
* Width of the sidebar when expanded.
* @default 320
*/
sidebarExpandedWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* The props used for each slot inside.
* @default {}
Expand Down

0 comments on commit 1ef74f0

Please sign in to comment.