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

[TreeView] Prepare support for PigmentCSS #13412

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This should work as long as it has zero-styled.

import { getRichTreeViewProUtilityClass } from './richTreeViewProClasses';
import {
RichTreeViewProProps,
Expand All @@ -19,6 +19,8 @@ import {
import { DEFAULT_TREE_VIEW_PRO_PLUGINS } 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 } 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 } from './SimpleTreeView.plugins';
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;
}
Loading