import * as React from 'react'; import clsx from 'clsx'; import { animated, useSpring } from '@react-spring/web'; import { TransitionProps } from '@mui/material/transitions'; import Box from '@mui/material/Box'; import Card from '@mui/material/Card'; 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 { 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'; type Color = 'blue' | 'green'; type ExtendedTreeItemProps = { color?: Color; id: string; label: string; }; const ITEMS: TreeViewBaseItem[] = [ { id: '1', label: 'Website', children: [ { id: '1.1', label: 'Home', color: 'green' }, { id: '1.2', label: 'Pricing', color: 'green' }, { id: '1.3', label: 'About us', color: 'green' }, { id: '1.4', label: 'Blog', children: [ { id: '1.1.1', label: 'Announcements', color: 'blue' }, { id: '1.1.2', label: 'April lookahead', color: 'blue' }, { id: '1.1.3', label: "What's new", color: 'blue' }, { id: '1.1.4', label: 'Meet the team', color: 'blue' }, ], }, ], }, { id: '2', label: 'Store', children: [ { id: '2.1', label: 'All products', color: 'green' }, { id: '2.2', label: 'Categories', children: [ { id: '2.2.1', label: 'Gadgets', color: 'blue' }, { id: '2.2.2', label: 'Phones', color: 'blue' }, { id: '2.2.3', label: 'Wearables', color: 'blue' }, ], }, { id: '2.3', label: 'Bestsellers', color: 'green' }, { id: '2.4', label: 'Sales', color: 'green' }, ], }, { id: '4', label: 'Contact', color: 'blue' }, { id: '5', label: 'Help', color: 'blue' }, ]; function DotIcon({ color }: { color: string }) { return ( ); } const AnimatedCollapse = animated(Collapse); function TransitionComponent(props: TransitionProps) { const style = useSpring({ to: { opacity: props.in ? 1 : 0, transform: `translate3d(0,${props.in ? 0 : 20}px,0)`, }, }); return ; } interface CustomLabelProps { children: React.ReactNode; color?: Color; expandable?: boolean; } function CustomLabel({ color, expandable, children, ...other }: CustomLabelProps) { const theme = useTheme(); const colors = { blue: (theme.vars || theme).palette.primary.main, green: (theme.vars || theme).palette.success.main, }; const iconColor = color ? colors[color] : null; return ( {iconColor && } {children} ); } interface CustomTreeItemProps extends Omit, Omit, 'onFocus'> {} const CustomTreeItem = React.forwardRef(function CustomTreeItem( props: CustomTreeItemProps, ref: React.Ref, ) { const { id, itemId, label, disabled, children, ...other } = props; const { getRootProps, getContentProps, getIconContainerProps, getLabelProps, getGroupTransitionProps, status, publicAPI, } = useTreeItem({ id, itemId, children, label, disabled, rootRef: ref }); const item = publicAPI.getItem(itemId); const color = item?.color; return ( {status.expandable && ( )} {children && ( )} ); }); export default function CustomizedTreeView() { return ( Product tree ); }