Skip to content

Commit

Permalink
Move TreeView icons into the theme (#3337)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Potoms <[email protected]>
  • Loading branch information
Janpot authored Apr 4, 2024
1 parent e74d4f6 commit c86cb70
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 28 deletions.
18 changes: 18 additions & 0 deletions packages/toolpad-studio/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { createTheme, ThemeOptions, Theme, alpha } from '@mui/material/styles';
import type {} from '@mui/x-data-grid/themeAugmentation';
import type {} from '@mui/x-data-grid-pro/themeAugmentation';
import type {} from '@mui/x-tree-view/themeAugmentation';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';

declare module '@mui/material/styles/createPalette' {
interface ColorRange {
Expand Down Expand Up @@ -923,6 +925,22 @@ export function getThemedComponents(theme: Theme): { components: Theme['componen
size: 'small',
},
},
MuiSimpleTreeView: {
defaultProps: {
slots: {
collapseIcon: ExpandMoreIcon,
expandIcon: ChevronRightIcon,
},
slotProps: {
collapseIcon: {
style: { fontSize: '0.9rem', opacity: 0.5 },
},
expandIcon: {
style: { fontSize: '0.9rem', opacity: 0.5 },
},
},
},
},
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import clsx from 'clsx';
import { NodeId } from '@toolpad/studio-runtime';
import { Box, Typography, styled, IconButton } from '@mui/material';
import { SimpleTreeView, TreeItem, TreeItemProps, treeItemClasses } from '@mui/x-tree-view';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import useBoolean from '@toolpad/utils/hooks/useBoolean';
import * as appDom from '@toolpad/studio-runtime/appDom';
import MoreVertIcon from '@mui/icons-material/MoreVert';
Expand All @@ -17,9 +15,6 @@ import EditableTreeItem, { EditableTreeItemProps } from '../../../components/Edi
import ExplorerHeader from '../ExplorerHeader';
import NodeMenu from '../NodeMenu';

const CollapseIcon = styled(ExpandMoreIcon)({ fontSize: '0.9rem', opacity: 0.5 });
const ExpandIcon = styled(ChevronRightIcon)({ fontSize: '0.9rem', opacity: 0.5 });

const classes = {
treeItemMenuButton: 'Toolpad__HierarchyListItem',
treeItemMenuOpen: 'Toolpad__HierarchyListItemMenuOpen',
Expand Down Expand Up @@ -296,8 +291,6 @@ export default function HierarchyExplorer() {
<ExplorerHeader headerText="Page hierarchy" />
<SimpleTreeView
aria-label="Page hierarchy explorer"
// TODO: This belongs as a default property in the theme
slots={{ collapseIcon: CollapseIcon, expandIcon: ExpandIcon }}
expandedItems={Array.from(expandedDomNodeIdSet)}
selectedItems={selectedDomNodeId}
onSelectedItemsChange={handleNodeSelect}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import {
import { SimpleTreeView, treeItemClasses } from '@mui/x-tree-view';
import AddIcon from '@mui/icons-material/Add';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import useBoolean from '@toolpad/utils/hooks/useBoolean';
import * as appDom from '@toolpad/studio-runtime/appDom';
import dataSources from '../../../../toolpadDataSources/client';
Expand All @@ -27,9 +25,6 @@ import EditableTreeItem, { EditableTreeItemProps } from '../../../../components/
import NodeMenu from '../../NodeMenu';
import ExplorerHeader from '../../ExplorerHeader';

const CollapseIcon = styled(ExpandMoreIcon)({ fontSize: '0.9rem', opacity: 0.5 });
const ExpandIcon = styled(ChevronRightIcon)({ fontSize: '0.9rem', opacity: 0.5 });

const classes = {
treeItemMenuButton: 'Toolpad__QueryListItem',
treeItemMenuOpen: 'Toolpad__QueryListItemMenuOpen',
Expand Down Expand Up @@ -360,8 +355,6 @@ function Explorer({ nodes, setAnchorEl, nodeName, headerText }: ExplorerProps) {
? currentView.view.nodeId
: ''
}
// TODO: This belongs as a default property in the theme
slots={{ collapseIcon: CollapseIcon, expandIcon: ExpandIcon }}
sx={{
flexGrow: 1,
maxWidth: 400,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as React from 'react';
import { styled, Box, IconButton, Stack, Tooltip } from '@mui/material';
import { SimpleTreeView, treeItemClasses } from '@mui/x-tree-view';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import { NodeId } from '@toolpad/studio-runtime';
import clsx from 'clsx';
Expand All @@ -19,9 +17,6 @@ import EditableTreeItem, { EditableTreeItemProps } from '../../../components/Edi
import { scrollIntoViewIfNeeded } from '../../../utils/dom';
import ExplorerHeader from '../ExplorerHeader';

const CollapseIcon = styled(ExpandMoreIcon)({ fontSize: '0.9rem', opacity: 0.5 });
const ExpandIcon = styled(ChevronRightIcon)({ fontSize: '0.9rem', opacity: 0.5 });

const PagesExplorerRoot = styled(Stack)({
height: '100%',
width: '100%',
Expand Down Expand Up @@ -358,8 +353,6 @@ export default function PagesExplorer({ className }: PagesExplorerProps) {
expandedItems={expanded}
onExpandedItemsChange={handleToggle}
multiSelect
// TODO: This belongs as a default property in the theme
slots={{ collapseIcon: CollapseIcon, expandIcon: ExpandIcon }}
sx={{
overflow: 'auto',
scrollbarGutter: 'stable',
Expand Down
7 changes: 0 additions & 7 deletions packages/toolpad-studio/src/toolpad/FunctionsEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
} from '@mui/material';
import { errorFrom } from '@toolpad/utils/errors';
import { treeItemClasses, TreeItem, SimpleTreeView } from '@mui/x-tree-view';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
import AddIcon from '@mui/icons-material/Add';
import CloseIcon from '@mui/icons-material/Close';
import JavascriptIcon from '@mui/icons-material/Javascript';
Expand All @@ -44,9 +42,6 @@ import ExplorerHeader from '../AppEditor/ExplorerHeader';
import EditableTreeItem, { EditableTreeItemProps } from '../../components/EditableTreeItem';
import { scrollIntoViewIfNeeded } from '../../utils/dom';

const CollapseIcon = styled(ExpandMoreIcon)({ fontSize: '0.9rem', opacity: 0.5 });
const ExpandIcon = styled(ChevronRightIcon)({ fontSize: '0.9rem', opacity: 0.5 });

const fileTreeItemClasses = generateUtilityClasses('FileTreeItem', ['actionButton', 'handlerItem']);

const FileTreeItemRoot = styled(EditableTreeItem)(({ theme }) => ({
Expand Down Expand Up @@ -339,8 +334,6 @@ export default function FunctionsEditor() {
ref={handlerTreeRef}
selectedItems={selectedNodeId}
onSelectedItemsChange={handleSelectFunction}
// TODO: This belongs as a default property in the theme
slots={{ collapseIcon: CollapseIcon, expandIcon: ExpandIcon }}
expandedItems={expanded}
onExpandedItemsChange={(_event, itemIds) => setExpanded(itemIds)}
sx={{
Expand Down

0 comments on commit c86cb70

Please sign in to comment.