Skip to content

Commit

Permalink
[TreeView] Prepare support for PigmentCSS (#13412)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviendelangle authored Jun 10, 2024
1 parent 2305117 commit 40e631d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { styled, useThemeProps } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import { useLicenseVerifier, Watermark } from '@mui/x-license';
import { useSlotProps } from '@mui/base/utils';
Expand All @@ -10,6 +9,7 @@ import {
buildWarning,
extractPluginParamsFromProps,
} from '@mui/x-tree-view/internals';
import { styled, createUseThemeProps } from '../internals/zero-styled';
import { getRichTreeViewProUtilityClass } from './richTreeViewProClasses';
import {
RichTreeViewProProps,
Expand All @@ -22,6 +22,8 @@ import {
} from '../internals/plugins';
import { getReleaseInfo } from '../internals/utils/releaseInfo';

const useThemeProps = createUseThemeProps('MuiRichTreeViewPro');

const useUtilityClasses = <R extends {}, Multiple extends boolean | undefined>(
ownerState: RichTreeViewProProps<R, Multiple>,
) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/x-tree-view-pro/src/internals/zero-styled/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useThemeProps } from '@mui/material/styles';

export { styled } from '@mui/material/styles';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function createUseThemeProps(name: string) {
return useThemeProps;
}
4 changes: 3 additions & 1 deletion packages/x-tree-view/src/RichTreeView/RichTreeView.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled, useThemeProps } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import { useSlotProps } from '@mui/base/utils';
import { getRichTreeViewUtilityClass } from './richTreeViewClasses';
import { RichTreeViewProps, RichTreeViewSlotProps, RichTreeViewSlots } from './RichTreeView.types';
import { styled, createUseThemeProps } from '../internals/zero-styled';
import { useTreeView } from '../internals/useTreeView';
import { TreeViewProvider } from '../internals/TreeViewProvider';
import { DEFAULT_TREE_VIEW_PLUGINS, DefaultTreeViewPluginSignatures } from '../internals/plugins';
import { TreeItem, TreeItemProps } from '../TreeItem';
import { buildWarning } from '../internals/utils/warning';
import { extractPluginParamsFromProps } from '../internals/utils/extractPluginParamsFromProps';

const useThemeProps = createUseThemeProps('MuiRichTreeView');

const useUtilityClasses = <R extends {}, Multiple extends boolean | undefined>(
ownerState: RichTreeViewProps<R, Multiple>,
) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/x-tree-view/src/SimpleTreeView/SimpleTreeView.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled, useThemeProps } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import { useSlotProps } from '@mui/base/utils';
import { styled, createUseThemeProps } from '../internals/zero-styled';
import { getSimpleTreeViewUtilityClass } from './simpleTreeViewClasses';
import {
SimpleTreeViewProps,
Expand All @@ -15,6 +15,8 @@ import { SIMPLE_TREE_VIEW_PLUGINS, SimpleTreeViewPluginSignatures } from './Simp
import { buildWarning } from '../internals/utils/warning';
import { extractPluginParamsFromProps } from '../internals/utils/extractPluginParamsFromProps';

const useThemeProps = createUseThemeProps('MuiSimpleTreeView');

const useUtilityClasses = <Multiple extends boolean | undefined>(
ownerState: SimpleTreeViewProps<Multiple>,
) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/x-tree-view/src/TreeItem/TreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import Collapse from '@mui/material/Collapse';
import { resolveComponentProps, useSlotProps } from '@mui/base/utils';
import useForkRef from '@mui/utils/useForkRef';
import { shouldForwardProp } from '@mui/system/createStyled';
import { alpha, styled, useThemeProps } from '@mui/material/styles';
import { alpha } from '@mui/material/styles';
import { TransitionProps } from '@mui/material/transitions';
import unsupportedProp from '@mui/utils/unsupportedProp';
import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef';
import { unstable_composeClasses as composeClasses } from '@mui/base';
import { styled, createUseThemeProps } from '../internals/zero-styled';
import { TreeItemContent } from './TreeItemContent';
import { treeItemClasses, getTreeItemUtilityClass } from './treeItemClasses';
import { TreeItemOwnerState, TreeItemProps } from './TreeItem.types';
Expand All @@ -19,6 +20,8 @@ import { TreeViewCollapseIcon, TreeViewExpandIcon } from '../icons';
import { TreeItem2Provider } from '../TreeItem2Provider';
import { TreeViewItemDepthContext } from '../internals/TreeViewItemDepthContext';

const useThemeProps = createUseThemeProps('MuiTreeItem');

const useUtilityClasses = (ownerState: TreeItemOwnerState) => {
const { classes } = ownerState;

Expand Down
5 changes: 4 additions & 1 deletion packages/x-tree-view/src/TreeItem2/TreeItem2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import unsupportedProp from '@mui/utils/unsupportedProp';
import { alpha, styled, useThemeProps } from '@mui/material/styles';
import { alpha } from '@mui/material/styles';
import Collapse from '@mui/material/Collapse';
import MuiCheckbox, { CheckboxProps } from '@mui/material/Checkbox';
import { useSlotProps } from '@mui/base/utils';
import { shouldForwardProp } from '@mui/system/createStyled';
import composeClasses from '@mui/utils/composeClasses';
import { styled, createUseThemeProps } from '../internals/zero-styled';
import { TreeItem2Props, TreeItem2OwnerState } from './TreeItem2.types';
import {
unstable_useTreeItem2 as useTreeItem2,
Expand All @@ -18,6 +19,8 @@ import { getTreeItemUtilityClass } from '../TreeItem';
import { TreeItem2Icon } from '../TreeItem2Icon';
import { TreeItem2Provider } from '../TreeItem2Provider';

const useThemeProps = createUseThemeProps('MuiTreeItem2');

export const TreeItem2Root = styled('li', {
name: 'MuiTreeItem2',
slot: 'Root',
Expand Down
4 changes: 3 additions & 1 deletion packages/x-tree-view/src/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled, useThemeProps } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import { styled, createUseThemeProps } from '../internals/zero-styled';
import { getTreeViewUtilityClass } from './treeViewClasses';
import { TreeViewProps } from './TreeView.types';
import { SimpleTreeView, SimpleTreeViewRoot } from '../SimpleTreeView';

const useThemeProps = createUseThemeProps('MuiTreeView');

const useUtilityClasses = <Multiple extends boolean | undefined>(
ownerState: TreeViewProps<Multiple>,
) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useTheme } from '@mui/material/styles';
import { useRtl } from '@mui/system/RtlProvider';
import useEventCallback from '@mui/utils/useEventCallback';
import { TreeViewItemMeta, TreeViewPlugin } from '../../models';
import {
Expand All @@ -21,8 +21,7 @@ function isPrintableCharacter(string: string) {
export const useTreeViewKeyboardNavigation: TreeViewPlugin<
UseTreeViewKeyboardNavigationSignature
> = ({ instance, params, state }) => {
const theme = useTheme();
const isRTL = theme.direction === 'rtl';
const isRtl = useRtl();
const firstCharMap = React.useRef<TreeViewFirstCharMap>({});

const updateFirstCharMap = useEventCallback(
Expand Down Expand Up @@ -171,7 +170,7 @@ export const useTreeViewKeyboardNavigation: TreeViewPlugin<

// If the focused item is expanded, we move the focus to its first child
// If the focused item is collapsed and has children, we expand it
case (key === 'ArrowRight' && !isRTL) || (key === 'ArrowLeft' && isRTL): {
case (key === 'ArrowRight' && !isRtl) || (key === 'ArrowLeft' && isRtl): {
if (instance.isItemExpanded(itemId)) {
const nextItemId = getNextNavigableItem(instance, itemId);
if (nextItemId) {
Expand All @@ -188,7 +187,7 @@ export const useTreeViewKeyboardNavigation: TreeViewPlugin<

// If the focused item is expanded, we collapse it
// If the focused item is collapsed and has a parent, we move the focus to this parent
case (key === 'ArrowLeft' && !isRTL) || (key === 'ArrowRight' && isRTL): {
case (key === 'ArrowLeft' && !isRtl) || (key === 'ArrowRight' && isRtl): {
if (canToggleItemExpansion(itemId) && instance.isItemExpanded(itemId)) {
instance.toggleItemExpansion(event, itemId);
event.preventDefault();
Expand Down
8 changes: 8 additions & 0 deletions packages/x-tree-view/src/internals/zero-styled/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useThemeProps } from '@mui/material/styles';

export { styled } from '@mui/material/styles';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function createUseThemeProps(name: string) {
return useThemeProps;
}

0 comments on commit 40e631d

Please sign in to comment.