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

[DataGrid] refactor: theme to CSS variables #15704

Merged
merged 47 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
af5bdf9
refactor: theme => css variables
romgrk Dec 2, 2024
339768b
lint
romgrk Dec 2, 2024
90c1fc2
lint
romgrk Dec 2, 2024
1fc98c6
feat: breakpoints
romgrk Dec 3, 2024
15484db
feat: breakpoints
romgrk Dec 3, 2024
9a5014e
refactor: theme.spacing => vars.spacing
romgrk Dec 3, 2024
bf20ed3
refactor: zIndex
romgrk Dec 3, 2024
71c993f
refactor: finish t.spacing()
romgrk Dec 3, 2024
b1054ec
refactor: finish all but GRS
romgrk Dec 4, 2024
41b1451
lint
romgrk Dec 4, 2024
9d718e2
Merge branch 'master' into feat-agnostic-css-variables
romgrk Dec 4, 2024
4e83cb6
fix: missing variables
romgrk Dec 4, 2024
f0645af
refactor: GridRootStyles
romgrk Dec 4, 2024
07e64a0
refactor: GRS: more colors
romgrk Dec 4, 2024
4670236
refactor: more ergonomic API
romgrk Dec 4, 2024
4bccecc
lint
romgrk Dec 6, 2024
1de35d9
lint
romgrk Dec 6, 2024
4822768
draft: test reverting text color
romgrk Dec 6, 2024
f643319
lint
romgrk Dec 9, 2024
734d8e7
draft: try remove style
romgrk Dec 9, 2024
3dc38ef
Revert "draft: try remove style"
romgrk Dec 9, 2024
cd34948
Revert "refactor: GRS: more colors"
romgrk Dec 9, 2024
cc48bd1
refactor: GRS: main colors
romgrk Dec 9, 2024
8311425
refactor: GRS(2): colors
romgrk Dec 9, 2024
2476462
refactor: GRS(3): colors
romgrk Dec 9, 2024
736948b
refactor: GRS(4): colors
romgrk Dec 9, 2024
2973e5c
refactor: GRS(5): focus color
romgrk Dec 9, 2024
802c642
refactor: GRS: complete
romgrk Dec 9, 2024
e7e253a
Merge branch 'master' into feat-agnostic-css-variables
romgrk Dec 12, 2024
23d3ad4
draft: split CSS variables
romgrk Dec 12, 2024
414f359
Merge branch 'master' into feat-agnostic-css-variables
romgrk Jan 7, 2025
00c953d
Revert "draft: split CSS variables"
romgrk Jan 8, 2025
cf98e2c
Merge branch 'master' into feat-agnostic-css-variables
romgrk Jan 8, 2025
ae48775
fix: conflict marker
romgrk Jan 8, 2025
c3d77de
fix: css variables accessible from root
romgrk Jan 8, 2025
b678c19
lint
romgrk Jan 8, 2025
fb4edf8
lint
romgrk Jan 8, 2025
685e935
ci: run (empty commit)
romgrk Jan 9, 2025
02f2f1c
Update packages/x-data-grid/src/components/panel/GridPanelFooter.tsx
romgrk Jan 9, 2025
dc9b984
Merge branch 'master' into feat-agnostic-css-variables
romgrk Jan 9, 2025
8d21805
Merge branch 'feat-agnostic-css-variables' of github.com:romgrk/mui-x…
romgrk Jan 9, 2025
049a999
ci: run (empty commit)
romgrk Jan 9, 2025
a9c8b65
fix: quickfilter outside of root
romgrk Jan 9, 2025
2d961be
lint
romgrk Jan 9, 2025
249ee63
refactor: useThemeVariablesClassName => useCSSVariablesClass
romgrk Jan 9, 2025
a0b8119
ci: run (empty commit)
romgrk Jan 10, 2025
83655b4
ci: run (empty commit)
romgrk Jan 10, 2025
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
Expand Up @@ -8,7 +8,7 @@ import {
GridColumnHeaderParams,
GridColumnHeaderTitle,
} from '@mui/x-data-grid';
import type { GridBaseColDef } from '@mui/x-data-grid/internals';
import { vars, type GridBaseColDef } from '@mui/x-data-grid/internals';
import { getAggregationFunctionLabel } from '../hooks/features/aggregation/gridAggregationUtils';
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
Expand Down Expand Up @@ -37,14 +37,11 @@ const GridAggregationHeaderRoot = styled('div', {
const GridAggregationFunctionLabel = styled('div', {
name: 'MuiDataGrid',
slot: 'AggregationColumnHeaderLabel',
overridesResolver: (_, styles) => styles.aggregationColumnHeaderLabel,
})<{ ownerState: OwnerState }>(({ theme }) => {
return {
fontSize: theme.typography.caption.fontSize,
lineHeight: 'normal',
color: theme.palette.text.secondary,
marginTop: -1,
};
})<{ ownerState: OwnerState }>({
fontSize: vars.typography.small.fontSize,
lineHeight: 'normal',
color: vars.colors.foreground.muted,
marginTop: -1,
});

const useUtilityClasses = (ownerState: OwnerState) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import Box from '@mui/material/Box';
import { useGridPrivateApiContext } from '@mui/x-data-grid-pro/internals';
import { vars, useGridPrivateApiContext } from '@mui/x-data-grid-pro/internals';
import {
useGridSelector,
getDataGridUtilityClass,
Expand Down Expand Up @@ -124,8 +124,7 @@ export function GridDataSourceGroupingCriteriaCell(props: GridGroupingCriteriaCe
ml:
rootProps.rowGroupingColumnMode === 'multiple'
? 0
: (theme) =>
`calc(var(--DataGrid-cellOffsetMultiplier) * ${theme.spacing(rowNode.depth)})`,
: `calc(var(--DataGrid-cellOffsetMultiplier) * ${vars.spacing(rowNode.depth)})`,
}}
>
<div className={classes.toggle}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { getDataGridUtilityClass, GridRenderCellParams } from '@mui/x-data-grid';
import { vars } from '@mui/x-data-grid/internals';
import { styled, Theme } from '@mui/material/styles';
import { SxProps } from '@mui/system';
import composeClasses from '@mui/utils/composeClasses';
Expand All @@ -10,10 +11,10 @@ const GridFooterCellRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'FooterCell',
overridesResolver: (_, styles) => styles.footerCell,
})<{ ownerState: OwnerState }>(({ theme }) => ({
fontWeight: theme.typography.fontWeightMedium,
color: (theme.vars || theme).palette.primary.dark,
}));
})<{ ownerState: OwnerState }>({
fontWeight: vars.typography.fontWeight.medium,
color: vars.colors.foreground.accent,
});
Comment on lines -13 to +17
Copy link
Member

@oliviertassinari oliviertassinari Jan 12, 2025

Choose a reason for hiding this comment

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

I'm confused. Why are we changing this?

What I see:

  • the Data Grid version for Material UI needs to follow the Material UI API and conventions so the data grid deeply integrates with it. So this doesn't work in that case?
  • the unstyled version of the data grid can't force any styles on users to be able to natively integrate with Mantine, Shadcn UI, etc. So this doesn't work in that case?

As I understand it for unstyled:

  • we could have demo with all the slots styled, userland, no style in the npm package.
  • we could do what react-data-grid do, offer a CSS file that the developer can or not import.
  • we can't do what AG Grid do, it doesn't work with SSR, streaming, it can't be tree shake, it makes it impossible to have native integration with other libraries.


interface GridFooterCellProps extends GridRenderCellParams {
sx?: SxProps<Theme>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { vars } from '@mui/x-data-grid/internals';
import { GridRenderCellParams } from '@mui/x-data-grid-pro';
import { SxProps, Theme } from '@mui/system';
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
Expand All @@ -13,8 +14,7 @@ function GridGroupingColumnFooterCell(props: GridRenderCellParams) {
} else if (rootProps.rowGroupingColumnMode === 'multiple') {
sx.ml = 2;
} else {
sx.ml = (theme) =>
`calc(var(--DataGrid-cellOffsetMultiplier) * ${theme.spacing(props.rowNode.depth)})`;
sx.ml = `calc(var(--DataGrid-cellOffsetMultiplier) * ${vars.spacing(props.rowNode.depth)})`;
}

return <GridFooterCell sx={sx} {...props} />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { vars } from '@mui/x-data-grid/internals';
import { GridRenderCellParams } from '@mui/x-data-grid-pro';
import { useGridRootProps } from '../hooks/utils/useGridRootProps';

Expand All @@ -14,9 +15,9 @@ function GridGroupingColumnLeafCell(props: GridRenderCellParams) {
? {
ml: 1,
}
: (theme) => ({
ml: `calc(var(--DataGrid-cellOffsetMultiplier) * var(--depth) * ${theme.spacing(1)})`,
}),
: {
ml: `calc(var(--DataGrid-cellOffsetMultiplier) * var(--depth) * ${vars.spacing(1)})`,
},
]}
style={{ '--depth': rowNode.depth } as any}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import composeClasses from '@mui/utils/composeClasses';
import Box from '@mui/material/Box';
import { vars } from '@mui/x-data-grid/internals';
import {
useGridSelector,
gridFilteredDescendantCountLookupSelector,
Expand Down Expand Up @@ -80,9 +81,9 @@ export function GridGroupingCriteriaCell(props: GridGroupingCriteriaCellProps) {
? {
ml: 0,
}
: (theme) => ({
ml: `calc(var(--DataGrid-cellOffsetMultiplier) * var(--depth) * ${theme.spacing(1)})`,
}),
: {
ml: `calc(var(--DataGrid-cellOffsetMultiplier) * var(--depth) * ${vars.spacing(1)})`,
},
]}
style={{ '--depth': rowNode.depth } as any}
>
Expand Down
4 changes: 2 additions & 2 deletions packages/x-data-grid-pro/src/components/GridColumnHeaders.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import { GridBaseColumnHeaders, UseGridColumnHeadersProps } from '@mui/x-data-grid/internals';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { vars, GridBaseColumnHeaders, UseGridColumnHeadersProps } from '@mui/x-data-grid/internals';
import { useGridColumnHeaders } from '../hooks/features/columnHeaders/useGridColumnHeaders';

const Filler = styled('div')({
flex: 1,
backgroundColor: 'var(--DataGrid-containerBackground)',
backgroundColor: vars.colors.background.base,
});

export interface GridColumnHeadersProps
Expand Down
7 changes: 4 additions & 3 deletions packages/x-data-grid-pro/src/components/GridDetailPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
import { GridRowId } from '@mui/x-data-grid';
import { vars } from '@mui/x-data-grid/internals';
import { useResizeObserver } from '@mui/x-internals/useResizeObserver';
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
import { useGridPrivateApiContext } from '../hooks/utils/useGridPrivateApiContext';
Expand All @@ -12,12 +13,12 @@ const DetailPanel = styled('div', {
name: 'MuiDataGrid',
slot: 'DetailPanel',
overridesResolver: (props, styles) => styles.detailPanel,
})<{ ownerState: OwnerState }>(({ theme }) => ({
})<{ ownerState: OwnerState }>({
width:
'calc(var(--DataGrid-rowWidth) - var(--DataGrid-hasScrollY) * var(--DataGrid-scrollbarSize))',
backgroundColor: (theme.vars || theme).palette.background.default,
backgroundColor: vars.colors.background.base,
overflow: 'auto',
}));
});

interface GridDetailPanelProps
extends Pick<React.HTMLAttributes<HTMLDivElement>, 'className' | 'children'> {
Expand Down
9 changes: 5 additions & 4 deletions packages/x-data-grid/src/components/GridPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TablePagination, {
LabelDisplayedRowsArgs,
} from '@mui/material/TablePagination';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { vars } from '../constants/cssVariables';
import { useGridSelector } from '../hooks/utils/useGridSelector';
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
Expand All @@ -16,22 +17,22 @@ import {
gridPageCountSelector,
} from '../hooks/features/pagination/gridPaginationSelector';

const GridPaginationRoot = styled(TablePagination)(({ theme }) => ({
const GridPaginationRoot = styled(TablePagination)({
maxHeight: 'calc(100% + 1px)', // border width
flexGrow: 1,
[`& .${tablePaginationClasses.selectLabel}`]: {
display: 'none',
[theme.breakpoints.up('sm')]: {
[vars.breakpoints.up('sm')]: {
display: 'block',
},
},
[`& .${tablePaginationClasses.input}`]: {
display: 'none',
[theme.breakpoints.up('sm')]: {
[vars.breakpoints.up('sm')]: {
display: 'inline-flex',
},
},
})) as typeof TablePagination;
}) as typeof TablePagination;

export type WrappedLabelDisplayedRows = (
args: LabelDisplayedRowsArgs & { estimated?: number },
Expand Down
7 changes: 4 additions & 3 deletions packages/x-data-grid/src/components/GridRowCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import { styled, SxProps, Theme } from '@mui/system';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { vars } from '../constants/cssVariables';
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
import { getDataGridUtilityClass } from '../constants/gridClasses';
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
Expand Down Expand Up @@ -35,11 +36,11 @@ const GridRowCountRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'RowCount',
overridesResolver: (props, styles) => styles.rowCount,
})<{ ownerState: OwnerState }>(({ theme }) => ({
})<{ ownerState: OwnerState }>({
alignItems: 'center',
display: 'flex',
margin: theme.spacing(0, 2),
}));
margin: vars.spacing(0, 2),
});

const GridRowCount = forwardRef<HTMLDivElement, GridRowCountProps>(
function GridRowCount(props, ref) {
Expand Down
9 changes: 5 additions & 4 deletions packages/x-data-grid/src/components/GridSelectedRowCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import clsx from 'clsx';
import composeClasses from '@mui/utils/composeClasses';
import { styled, SxProps, Theme } from '@mui/system';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { vars } from '../constants/cssVariables';
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
import { getDataGridUtilityClass } from '../constants/gridClasses';
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
Expand Down Expand Up @@ -34,19 +35,19 @@ const GridSelectedRowCountRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'SelectedRowCount',
overridesResolver: (props, styles) => styles.selectedRowCount,
})<{ ownerState: OwnerState }>(({ theme }) => ({
})<{ ownerState: OwnerState }>({
alignItems: 'center',
display: 'flex',
margin: theme.spacing(0, 2),
margin: vars.spacing(0, 2),
visibility: 'hidden',
width: 0,
height: 0,
[theme.breakpoints.up('sm')]: {
[vars.breakpoints.up('sm')]: {
visibility: 'visible',
width: 'auto',
height: 'auto',
},
}));
});

const GridSelectedRowCount = forwardRef<HTMLDivElement, GridSelectedRowCountProps>(
function GridSelectedRowCount(props, ref) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { styled } from '@mui/material/styles';
import InputBase, { InputBaseProps } from '@mui/material/InputBase';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { vars } from '../../constants/cssVariables';
import { GridRenderEditCellParams } from '../../models/params/gridCellParams';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
Expand All @@ -28,15 +29,14 @@ const useUtilityClasses = (ownerState: OwnerState) => {
const GridEditInputCellRoot = styled(InputBase, {
name: 'MuiDataGrid',
slot: 'EditInputCell',
overridesResolver: (props, styles) => styles.editInputCell,
})<{ ownerState: OwnerState }>(({ theme }) => ({
...theme.typography.body2,
})<{ ownerState: OwnerState }>({
...vars.typography.body,
padding: '1px 0',
'& input': {
padding: '0 16px',
height: '100%',
},
}));
});

export interface GridEditInputCellProps
extends GridRenderEditCellParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FormControlLabel from '@mui/material/FormControlLabel';
import { styled } from '@mui/material/styles';
import TextField, { TextFieldProps } from '@mui/material/TextField';
import { inputBaseClasses } from '@mui/material/InputBase';
import { vars } from '../../constants/cssVariables';
import {
gridColumnDefinitionsSelector,
gridColumnVisibilityModelSelector,
Expand Down Expand Up @@ -373,56 +374,52 @@ GridColumnsManagement.propTypes = {
const GridColumnsManagementBody = styled('div', {
name: 'MuiDataGrid',
slot: 'ColumnsManagement',
overridesResolver: (props, styles) => styles.columnsManagement,
})<{ ownerState: OwnerState }>(({ theme }) => ({
padding: theme.spacing(0, 3, 1.5),
})<{ ownerState: OwnerState }>({
padding: vars.spacing(0, 3, 1.5),
display: 'flex',
flexDirection: 'column',
overflow: 'auto',
flex: '1 1',
maxHeight: 400,
alignItems: 'flex-start',
}));
});

const GridColumnsManagementHeader = styled('div', {
name: 'MuiDataGrid',
slot: 'ColumnsManagementHeader',
overridesResolver: (props, styles) => styles.columnsManagementHeader,
})<{ ownerState: OwnerState }>(({ theme }) => ({
padding: theme.spacing(1.5, 3),
}));
})<{ ownerState: OwnerState }>({
padding: vars.spacing(1.5, 3),
});

const SearchInput = styled(TextField, {
name: 'MuiDataGrid',
slot: 'ColumnsManagementSearchInput',
overridesResolver: (props, styles) => styles.columnsManagementSearchInput,
})<{ ownerState: OwnerState }>(({ theme }) => ({
})<{ ownerState: OwnerState }>({
[`& .${inputBaseClasses.root}`]: {
padding: theme.spacing(0, 1.5, 0, 1.5),
padding: vars.spacing(0, 1.5, 0, 1.5),
},
[`& .${inputBaseClasses.input}::-webkit-search-decoration,
& .${inputBaseClasses.input}::-webkit-search-cancel-button,
& .${inputBaseClasses.input}::-webkit-search-results-button,
& .${inputBaseClasses.input}::-webkit-search-results-decoration`]: {
& .${inputBaseClasses.input}::-webkit-search-cancel-button,
& .${inputBaseClasses.input}::-webkit-search-results-button,
& .${inputBaseClasses.input}::-webkit-search-results-decoration`]: {
/* clears the 'X' icon from Chrome */
display: 'none',
},
}));
});

const GridColumnsManagementFooter = styled('div', {
name: 'MuiDataGrid',
slot: 'ColumnsManagementFooter',
overridesResolver: (props, styles) => styles.columnsManagementFooter,
})<{ ownerState: OwnerState }>(({ theme }) => ({
padding: theme.spacing(0.5, 1, 0.5, 3),
})<{ ownerState: OwnerState }>({
padding: vars.spacing(0.5, 1, 0.5, 3),
display: 'flex',
justifyContent: 'space-between',
borderTop: `1px solid ${theme.palette.divider}`,
}));
borderTop: `1px solid ${vars.colors.border.base}`,
});

const GridColumnsManagementEmptyText = styled('div')<{ ownerState: OwnerState }>(({ theme }) => ({
padding: theme.spacing(0.5, 0),
color: theme.palette.grey[500],
}));
const GridColumnsManagementEmptyText = styled('div')<{ ownerState: OwnerState }>({
padding: vars.spacing(0.5, 0),
color: vars.colors.foreground.muted,
});

export { GridColumnsManagement };
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import composeClasses from '@mui/utils/composeClasses';
import { Theme, SxProps, styled } from '@mui/system';
import { forwardRef } from '@mui/x-internals/forwardRef';
import type { DataGridProcessedProps } from '../../models/props/DataGridProps';
import { vars } from '../../constants/cssVariables';
import { getDataGridUtilityClass } from '../../constants/gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';

Expand Down Expand Up @@ -35,7 +36,7 @@ const GridOverlayRoot = styled('div', {
alignSelf: 'center',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'var(--unstable_DataGrid-overlayBackground)',
backgroundColor: vars.colors.background.backdrop,
});

const GridOverlay = forwardRef<HTMLDivElement, GridOverlayProps>(function GridOverlay(props, ref) {
Expand Down
Loading
Loading