Skip to content

Commit

Permalink
[TreeView] Remove deprecated TreeView component (#15093)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle authored Nov 7, 2024
1 parent 7061865 commit fc5bd87
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 631 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,53 @@ After running the codemods, make sure to test your application and that you don'
Feel free to [open an issue](https://github.com/mui/mui-x/issues/new/choose) for support if you need help to proceed with your migration.
:::

### ✅ Use Simple Tree View instead of Tree View

The `<TreeView />` component has been renamed `<SimpleTreeView />` which has exactly the same API:

```diff
-import { TreeView } from '@mui/x-tree-view';
+import { SimpleTreeView } from '@mui/x-tree-view';

-import { TreeView } from '@mui/x-tree-view/TreeView';
+import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';

return (
- <TreeView>
+ <SimpleTreeView>
<TreeItem itemId="1" label="First item" />
- </TreeView>
+ </SimpleTreeView>
);
```

If you were using theme augmentation, you will also need to migrate it:

```diff
const theme = createTheme({
components: {
- MuiTreeView: {
+ MuiSimpleTreeView: {
styleOverrides: {
root: {
opacity: 0.5,
},
},
},
},
});
```

If you were using the `treeViewClasses` object, you can replace it with the new `simpleTreeViewClasses` object:

```diff
import { treeViewClasses } from '@mui/x-tree-view/TreeView';
import { simpleTreeViewClasses } from '@mui/x-tree-view/SimpleTreeView';

-const rootClass = treeViewClasses.root;
+const rootClass = simpleTreeViewClasses.root;
```

## New API to customize the Tree Item

The `ContentComponent` or `ContentProps` props of the `TreeItem` component have been removed in favor of the new `slots`, `slotProps` props and of the `useTreeItem` hook.
Expand All @@ -85,7 +132,7 @@ This inconsistency has been solved, all the event manager now target the root of
</SimpleTreeView>
```

## Rename the `TreeItem2` (and related utils)
## Rename the `TreeItem2` (and related utils)

All the new Tree Item-related components and utils (introduced in the previous major to improve the DX of the Tree Item component) are becoming the default way of using the Tree Item and are therefore losing their `2` suffix:

Expand Down
4 changes: 0 additions & 4 deletions docs/data/treeViewApiPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,5 @@ const treeViewApiPages: MuiPage[] = [
pathname: '/x/api/tree-view/tree-item-icon',
title: 'TreeItemIcon',
},
{
pathname: '/x/api/tree-view/tree-view',
title: 'TreeView',
},
];
export default treeViewApiPages;
23 changes: 0 additions & 23 deletions docs/pages/x/api/tree-view/tree-view.js

This file was deleted.

129 changes: 0 additions & 129 deletions docs/pages/x/api/tree-view/tree-view.json

This file was deleted.

103 changes: 0 additions & 103 deletions docs/translations/api-docs/tree-view/tree-view/tree-view.json

This file was deleted.

23 changes: 22 additions & 1 deletion packages/x-codemod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,29 @@ npx @mui/x-codemod@latest v8.0.0/tree-view/preset-safe <path|folder>

The list includes these transformers

- [`rename-tree-view-simple-tree-view`](#rename-tree-view-simple-tree-view)
- [`rename-tree-item-2`](#rename-tree-item-2)

#### `rename-tree-view-simple-tree-view`

Renames the Tree View component to Simple Tree View

```diff
-import { TreeView } from '@mui/x-tree-view';
+import { SimpleTreeView } from '@mui/x-tree-view';

-import { TreeView } from '@mui/x-tree-view/TreeView';
+import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';

return (
- <TreeView>
+ <SimpleTreeView>
<TreeItem itemId="1" label="First item" />
- </TreeView>
+ </SimpleTreeView>
);
```

#### `rename-tree-item-2`

Renames the `TreeItem2` component to `TreeItem` (same for any subcomponents or utils like `useTreeItem2` or `TreeItem2Icon`).
Expand Down Expand Up @@ -280,7 +301,7 @@ npx @mui/x-codemod@latest v7.0.0/tree-view/preset-safe <path|folder>

The list includes these transformers

- [`rename-tree-view-simple-tree-view`](#rename-tree-view-simple-tree-view)
- [`rename-tree-view-simple-tree-view`](#rename-tree-view-simple-tree-view-1)
- [`rename-use-tree-item`](#rename-use-tree-item)
- [`rename-expansion-props`](#rename-expansion-props)
- [`rename-selection-props`](#rename-selection-props)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @ts-nocheck
import * as React from 'react';
import { TreeItem2 } from '@mui/x-tree-view/TreeItem2';
import { SimpleTreeView } from '@mui/x-tree-view/SimpleTreeView';
import { TreeView } from '@mui/x-tree-view/TreeView';

const className = treeViewClasses.root;

// prettier-ignore
<SimpleTreeView>
<TreeItem2 nodeId="1" label="Item 1" />
</SimpleTreeView>;
<TreeView>
<TreeItem2 itemId="1" label="Item 1" />
</TreeView>;
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ const className = treeViewClasses.root;

// prettier-ignore
<SimpleTreeView>
<TreeItem nodeId="1" label="Item 1" />
<TreeItem itemId="1" label="Item 1" />
</SimpleTreeView>;
Loading

0 comments on commit fc5bd87

Please sign in to comment.