Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as React from 'react';
import { alpha } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid2';
import Grid from '@mui/material/Grid';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import StatCard, { StatCardProps } from '../components/StatCard';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,88 +1,22 @@
'use client';
import * as React from 'react';
import { usePathname, useRouter } from 'next/navigation';
import { CrudProvider, List, Create, Edit, Show } from '@toolpad/core/Crud';
import { Crud } from '@toolpad/core/Crud';
import { employeesDataSource, Employee, employeesCache } from '../../../mocks/employees';
import CustomDataGrid from '../../../components/CustomDataGrid';

function matchPath(pattern: string, pathname: string): string | null {
const regex = new RegExp(`^${pattern.replace(/:[^/]+/g, '([^/]+)')}$`);
const match = pathname.match(regex);
return match ? match[1] : null;
}

export default function EmployeesCrudPage() {
const pathname = usePathname();
const router = useRouter();

const rootPath = '/employees';
const listPath = rootPath;
const showPath = `${rootPath}/:employeeId`;
const createPath = `${rootPath}/new`;
const editPath = `${rootPath}/:employeeId/edit`;

const showEmployeeId = matchPath(showPath, pathname);
const editEmployeeId = matchPath(editPath, pathname);

const handleRowClick = React.useCallback(
(employeeId: string | number) => {
console.log('Clicked on row with ID', employeeId);
router.push(`${rootPath}/${String(employeeId)}`);
},
[router],
);

const handleCreateClick = React.useCallback(() => {
router.push(createPath);
}, [createPath, router]);

const handleEditClick = React.useCallback(
(employeeId: string | number) => {
router.push(`${rootPath}/${String(employeeId)}/edit`);
},
[router],
);

const handleCreate = React.useCallback(() => {
router.push(listPath);
}, [listPath, router]);

const handleEdit = React.useCallback(() => {
router.push(listPath);
}, [listPath, router]);

const handleDelete = React.useCallback(() => {
router.push(listPath);
}, [listPath, router]);

return (
<CrudProvider<Employee> dataSource={employeesDataSource} dataSourceCache={employeesCache}>
{pathname === listPath ? (
<List<Employee>
initialPageSize={20}
onRowClick={handleRowClick}
onCreateClick={handleCreateClick}
onEditClick={handleEditClick}
slots={{
dataGrid: CustomDataGrid,
}}
/>
) : null}
{pathname === createPath ? (
<Create<Employee>
initialValues={{ title: 'New Employee' }}
onSubmitSuccess={handleCreate}
resetOnSubmit={false}
/>
) : null}
{pathname !== createPath && showEmployeeId ? (
<Show<Employee> id={showEmployeeId} onEditClick={handleEditClick} onDelete={handleDelete} />
) : null}
{editEmployeeId ? (
<div className="employee-edit-container">
<Edit<Employee> id={editEmployeeId} onSubmitSuccess={handleEdit} />
</div>
) : null}
</CrudProvider>
<Crud<Employee>
dataSource={employeesDataSource}
dataSourceCache={employeesCache}
rootPath="/employees"
initialPageSize={20}
defaultValues={{ title: 'New Employee' }}
slots={{
list: {
dataGrid: CustomDataGrid,
},
}}
/>
);
}
45 changes: 21 additions & 24 deletions examples/core/auth-nextjs-themed/app/components/CustomTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ import CardContent from '@mui/material/CardContent';
import Collapse from '@mui/material/Collapse';
import Typography from '@mui/material/Typography';
import { RichTreeView } from '@mui/x-tree-view/RichTreeView';
import { useTreeItem, UseTreeItemParameters } from '@mui/x-tree-view/useTreeItem';
import {
unstable_useTreeItem2 as useTreeItem2,
UseTreeItem2Parameters,
} from '@mui/x-tree-view/useTreeItem2';
import {
TreeItem2Content,
TreeItem2IconContainer,
TreeItem2Label,
TreeItem2Root,
} from '@mui/x-tree-view/TreeItem2';
import { TreeItem2Icon } from '@mui/x-tree-view/TreeItem2Icon';
import { TreeItem2Provider } from '@mui/x-tree-view/TreeItem2Provider';
TreeItemContent,
TreeItemIconContainer,
TreeItemLabel,
TreeItemRoot,
} from '@mui/x-tree-view/TreeItem';
import { TreeItemIcon } from '@mui/x-tree-view/TreeItemIcon';
import { TreeItemProvider } from '@mui/x-tree-view/TreeItemProvider';
import { TreeViewBaseItem } from '@mui/x-tree-view/models';
import { useTheme } from '@mui/material/styles';

Expand Down Expand Up @@ -112,17 +109,17 @@ function CustomLabel({ color, expandable, children, ...other }: CustomLabelProps

const iconColor = color ? colors[color] : null;
return (
<TreeItem2Label {...other} sx={{ display: 'flex', alignItems: 'center' }}>
<TreeItemLabel {...other} sx={{ display: 'flex', alignItems: 'center' }}>
{iconColor && <DotIcon color={iconColor} />}
<Typography className="labelText" variant="body2" sx={{ color: 'text.primary' }}>
{children}
</Typography>
</TreeItem2Label>
</TreeItemLabel>
);
}

interface CustomTreeItemProps
extends Omit<UseTreeItem2Parameters, 'rootRef'>,
extends Omit<UseTreeItemParameters, 'rootRef'>,
Omit<React.HTMLAttributes<HTMLLIElement>, 'onFocus'> {}

const CustomTreeItem = React.forwardRef(function CustomTreeItem(
Expand All @@ -139,14 +136,14 @@ const CustomTreeItem = React.forwardRef(function CustomTreeItem(
getGroupTransitionProps,
status,
publicAPI,
} = useTreeItem2({ id, itemId, children, label, disabled, rootRef: ref });
} = useTreeItem({ id, itemId, children, label, disabled, rootRef: ref });

const item = publicAPI.getItem(itemId);
const color = item?.color;
return (
<TreeItem2Provider itemId={itemId}>
<TreeItem2Root {...getRootProps(other)}>
<TreeItem2Content
<TreeItemProvider id={id} itemId={itemId}>
<TreeItemRoot {...getRootProps(other)}>
<TreeItemContent
{...getContentProps({
className: clsx('content', {
expanded: status.expanded,
Expand All @@ -157,18 +154,18 @@ const CustomTreeItem = React.forwardRef(function CustomTreeItem(
})}
>
{status.expandable && (
<TreeItem2IconContainer {...getIconContainerProps()}>
<TreeItem2Icon status={status} />
</TreeItem2IconContainer>
<TreeItemIconContainer {...getIconContainerProps()}>
<TreeItemIcon status={status} />
</TreeItemIconContainer>
)}

<CustomLabel {...getLabelProps({ color })} />
</TreeItem2Content>
</TreeItemContent>
{children && (
<TransitionComponent {...getGroupTransitionProps({ className: 'groupTransition' })} />
)}
</TreeItem2Root>
</TreeItem2Provider>
</TreeItemRoot>
</TreeItemProvider>
);
});

Expand Down
2 changes: 1 addition & 1 deletion examples/core/auth-nextjs-themed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dayjs": "^1",
"clsx": "^2",
"@react-spring/web": "^9",
"@toolpad/core": "^0.13.0",
"@toolpad/core": "^0.14.0",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like I had forgotten this one.

"next": "^15",
"next-auth": "^5.0.0-beta.25",
"react": "^19.0.0",
Expand Down
37 changes: 18 additions & 19 deletions examples/core/auth-nextjs-themed/theme/customizations/inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,27 +442,8 @@ export const inputsCustomizations: Components<Theme> = {
styleOverrides: {
root: ({ theme }) => ({
color: theme.palette.grey[500],
'.employee-edit-container & .MuiIconButton-root': {
border: 'none',
'&:hover': {
backgroundColor: 'rgba(0, 0, 0, 0.04)',
border: 'none',
},
'&:active': {
border: 'none',
},
},
...theme.applyStyles('dark', {
color: theme.palette.grey[400],
'.employee-edit-container & .MuiIconButton-root': {
backgroundColor: 'transparent',
border: 'none',
height: 24,
'&:hover': {
backgroundColor: theme.palette.grey[900],
border: 'none',
},
},
}),
}),
},
Expand All @@ -474,4 +455,22 @@ export const inputsCustomizations: Components<Theme> = {
}),
},
},
MuiPickersInputBase: {
styleOverrides: {
// @ts-expect-error
root: ({ theme }) => ({
marginTop: '6px',
border: `1px solid ${theme.palette.divider}`,
' .MuiPickersInputBase-sectionsContainer': {
padding: '10px 0',
},
' .MuiPickersOutlinedInput-notchedOutline': {
border: 0,
},
' .MuiIconButton-root': {
border: 0,
},
}),
},
},
};
3 changes: 3 additions & 0 deletions examples/core/auth-nextjs-themed/theme/themeTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ declare module '@mui/material/styles' {
defaultProps?: Partial<GridComponentsPropsOverrides>;
styleOverrides?: Record<string, any>;
};
MuiPickersInputBase?: {
styleOverrides?: Record<string, any>;
};
}
}
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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