Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move TreeView icons into the theme #3337

Merged
merged 5 commits into from
Apr 4, 2024
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
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
Loading