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

[core] Prepare for material v6 #14143

Merged
merged 13 commits into from
Aug 21, 2024
10 changes: 8 additions & 2 deletions docs/data/charts/styling/SxStyling.js
Copy link
Member

Choose a reason for hiding this comment

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

There are some components that I don't know how to migrate, e.g.

export const BarElementPath = styled(animated.rect, {
name: 'MuiBarElement',
slot: 'Root',
overridesResolver: (_, styles) => styles.root,
})<{ ownerState: BarElementOwnerState }>(({ ownerState }) => ({
stroke: 'none',
fill: ownerState.isHighlighted
? d3Color(ownerState.color)!.brighter(0.5).formatHex()
: ownerState.color,
transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
opacity: (ownerState.isFaded && 0.3) || 1,
}));

Any ideas?
@LukasTy @siriwatknp @DiegoAndai

Copy link
Member

@DiegoAndai DiegoAndai Aug 20, 2024

Choose a reason for hiding this comment

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

I think this should work:

export const BarElementPath = styled(animated.rect, {
  name: 'MuiBarElement',
  slot: 'Root',
  overridesResolver: (_, styles) => styles.root,
})<{ ownerState: BarElementOwnerState }>(() => ({
  stroke: 'none',
  transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
  opacity: 1, // might not be required, but I'm not familiar with the animation
  variants: [
    {
      props: { isHighlighted: true },
      style: ({ ownerState }) => ({
        fill: d3Color(ownerState.color)!.brighter(0.5).formatHex()
      })
    },
    {
      props: { isHighlighted: false },
      style: ({ ownerState }) => ({
        fill: ownerState.color
      })
    },
    {
      props: { isFaded: true },
      style: { opacity: 0.3 },
    },
  ],
}));

The props and ownerState are also available in the style callback, here's a demo: https://codesandbox.io/p/sandbox/epic-ioana-v8hmlc?file=%2Fsrc%2FApp.tsx%3A12%2C32

@siriwatknp can confirm if this is the correct usage.

Copy link
Member

Choose a reason for hiding this comment

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

This won't work with Pigment, the ownerState usage is still dynamic. It should be:

export const BarElementPath = styled(animated.rect, {
  name: 'MuiBarElement',
  slot: 'Root',
  overridesResolver: (_, styles) => styles.root,
})<{ ownerState: BarElementOwnerState }>(() => ({
  stroke: 'none',
  transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
  opacity: 1, // might not be required, but I'm not familiar with the animation
  fill: 'var(--_fill)', // the `_` is a convention in CSS to indicates that the variable is private.
  variants: [
    {
      props: { isFaded: true },
      style: { opacity: 0.3 },
    },
  ],
}));

<BarElementPath style={{
  '--_fill': isHighlighted ? d3Color(ownerState.color)!.brighter(0.5).formatHex() : color,
}}>

Copy link
Member Author

@LukasTy LukasTy Aug 21, 2024

Choose a reason for hiding this comment

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

@cherniavskii Supporting PigmentCSS is not in the scope of this PR.
"Full support" for it is in the plans only for TreeView and Pickers, which have most of the work done.
I've only applied changes that were made by codemod, but for full support, we potentially need way more work and attention for it.
Personally, I would prefer omitting any manual changes for Pigment support to reduce the scope of the PR, need for review and the potential of errors. 🙈
WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

@cherniavskii I've removed the additional changes you introduced to avoid potential problems.
They would not be enough for PigmentCSS support anyways. 🙈
I think that support for it should be handled separately.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the example I gave here was out of curiosity 👍🏻

Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ export default function SxStyling() {
fill: '#006BD6',
},
},
border: `1px solid rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1)`,
backgroundImage: `linear-gradient(rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1) 1px, transparent 1px)`,
border: '1px solid rgba(0, 0, 0, 0.1)',
backgroundImage:
'linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, 0.1) 1px, transparent 1px)',
backgroundSize: '35px 35px',
backgroundPosition: '20px 20px, 20px 20px',
...theme.applyStyles('dark', {
borderColor: 'rgba(255,255,255, 0.1)',
backgroundImage:
'linear-gradient(rgba(255,255,255, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255, 0.1) 1px, transparent 1px)',
}),
})}
xAxis={[{ scaleType: 'band', data: labels }]}
series={[
Expand Down
11 changes: 8 additions & 3 deletions docs/data/charts/styling/SxStyling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ export default function SxStyling(): React.JSX.Element {
fill: '#006BD6',
},
},

border: `1px solid rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1)`,
backgroundImage: `linear-gradient(rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(${theme.palette.mode === 'dark' ? '255,255,255' : '0, 0, 0'}, 0.1) 1px, transparent 1px)`,
border: '1px solid rgba(0, 0, 0, 0.1)',
backgroundImage:
'linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, 0.1) 1px, transparent 1px)',
backgroundSize: '35px 35px',
backgroundPosition: '20px 20px, 20px 20px',
...theme.applyStyles('dark', {
borderColor: 'rgba(255,255,255, 0.1)',
backgroundImage:
'linear-gradient(rgba(255,255,255, 0.1) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255, 0.1) 1px, transparent 1px)',
}),
})}
xAxis={[{ scaleType: 'band', data: labels }]}
series={[
Expand Down
14 changes: 8 additions & 6 deletions docs/data/data-grid/cell-selection/CellSelectionRangeStyling.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import { DataGridPremium, gridClasses } from '@mui/x-data-grid-premium';
import { useDemoData } from '@mui/x-data-grid-generator';

const StyledDataGridPremium = styled(DataGridPremium)(({ theme }) => {
const borderColor =
theme.palette.mode === 'light'
? lighten(alpha(theme.palette.divider, 1), 0.88)
: darken(alpha(theme.palette.divider, 1), 0.68);
const lightBorderColor = lighten(alpha(theme.palette.divider, 1), 0.88);
const darkBorderColor = darken(alpha(theme.palette.divider, 1), 0.68);

const selectedCellBorder = alpha(theme.palette.primary.main, 0.5);

return {
[`& .${gridClasses.cell}`]: {
border: `1px solid transparent`,
borderRight: `1px solid ${borderColor}`,
borderBottom: `1px solid ${borderColor}`,
borderRight: `1px solid ${lightBorderColor}`,
borderBottom: `1px solid ${lightBorderColor}`,
...theme.applyStyles('dark', {
borderRightColor: `${darkBorderColor}`,
borderBottomColor: `${darkBorderColor}`,
}),
},
[`& .${gridClasses.cell}.Mui-selected`]: {
borderColor: alpha(theme.palette.primary.main, 0.1),
Expand Down
14 changes: 8 additions & 6 deletions docs/data/data-grid/cell-selection/CellSelectionRangeStyling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import { DataGridPremium, gridClasses } from '@mui/x-data-grid-premium';
import { useDemoData } from '@mui/x-data-grid-generator';

const StyledDataGridPremium = styled(DataGridPremium)(({ theme }) => {
const borderColor =
theme.palette.mode === 'light'
? lighten(alpha(theme.palette.divider, 1), 0.88)
: darken(alpha(theme.palette.divider, 1), 0.68);
const lightBorderColor = lighten(alpha(theme.palette.divider, 1), 0.88);
const darkBorderColor = darken(alpha(theme.palette.divider, 1), 0.68);

const selectedCellBorder = alpha(theme.palette.primary.main, 0.5);

return {
[`& .${gridClasses.cell}`]: {
border: `1px solid transparent`,
borderRight: `1px solid ${borderColor}`,
borderBottom: `1px solid ${borderColor}`,
borderRight: `1px solid ${lightBorderColor}`,
borderBottom: `1px solid ${lightBorderColor}`,
...theme.applyStyles('dark', {
borderRightColor: `${darkBorderColor}`,
borderBottomColor: `${darkBorderColor}`,
}),
},
[`& .${gridClasses.cell}.Mui-selected`]: {
borderColor: alpha(theme.palette.primary.main, 0.1),
Expand Down
68 changes: 42 additions & 26 deletions docs/data/data-grid/demo/FullFeaturedDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select';

const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
border: `1px solid ${theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'}`,
color:
theme.palette.mode === 'light' ? 'rgba(0,0,0,.85)' : 'rgba(255,255,255,0.85)',
border: '1px solid #303030',
color: 'rgba(255,255,255,0.85)',
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
Expand All @@ -33,24 +32,28 @@ const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
WebkitFontSmoothing: 'auto',
letterSpacing: 'normal',
'& .MuiDataGrid-columnsContainer': {
backgroundColor: theme.palette.mode === 'light' ? '#fafafa' : '#1d1d1d',
backgroundColor: '#1d1d1d',
...theme.applyStyles('light', {
backgroundColor: '#fafafa',
}),
},
'& .MuiDataGrid-iconSeparator': {
display: 'none',
},
'& .MuiDataGrid-columnHeader, .MuiDataGrid-cell': {
borderRight: `1px solid ${
theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'
}`,
borderRight: '1px solid #303030',
...theme.applyStyles('light', {
borderRightColor: '#f0f0f0',
}),
},
'& .MuiDataGrid-columnsContainer, .MuiDataGrid-cell': {
borderBottom: `1px solid ${
theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'
}`,
borderBottom: '1px solid #303030',
...theme.applyStyles('light', {
borderBottomColor: '#f0f0f0',
}),
},
'& .MuiDataGrid-cell': {
color:
theme.palette.mode === 'light' ? 'rgba(0,0,0,.85)' : 'rgba(255,255,255,0.85)',
color: 'rgba(255,255,255,0.85)',
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
Expand All @@ -66,26 +69,31 @@ const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
WebkitFontSmoothing: 'auto',
letterSpacing: 'normal',
'& .MuiDataGrid-columnsContainer': {
backgroundColor: theme.palette.mode === 'light' ? '#fafafa' : '#1d1d1d',
backgroundColor: '#1d1d1d',
...theme.applyStyles('light', {
backgroundColor: '#fafafa',
}),
},
'& .MuiDataGrid-iconSeparator': {
display: 'none',
},
'& .MuiDataGrid-colCell, .MuiDataGrid-cell': {
borderRight: `1px solid ${
theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'
}`,
borderRight: '1px solid #303030',
...theme.applyStyles('light', {
borderRightColor: '#f0f0f0',
}),
},
'& .MuiDataGrid-columnsContainer, .MuiDataGrid-cell': {
borderBottom: `1px solid ${
theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'
}`,
borderBottom: '1px solid #303030',
...theme.applyStyles('light', {
borderBottomColor: '#f0f0f0',
}),
},
'& .MuiDataGrid-cell': {
color:
theme.palette.mode === 'light'
? 'rgba(0,0,0,.85)'
: 'rgba(255,255,255,0.65)',
color: 'rgba(255,255,255,0.65)',
...theme.applyStyles('light', {
color: 'rgba(0,0,0,.85)',
}),
},
'& .MuiPaginationItem-root': {
borderRadius: 0,
Expand All @@ -94,10 +102,11 @@ const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
width: 16,
height: 16,
backgroundColor: 'transparent',
border: `1px solid ${
theme.palette.mode === 'light' ? '#d9d9d9' : 'rgb(67, 67, 67)'
}`,
border: '1px solid rgb(67, 67, 67)',
borderRadius: 2,
...theme.applyStyles('light', {
borderColor: '#d9d9d9',
}),
},
'& .MuiCheckbox-root svg path': {
display: 'none',
Expand Down Expand Up @@ -129,7 +138,14 @@ const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
top: '39%',
border: 0,
},
...theme.applyStyles('light', {
color: 'rgba(0,0,0,.85)',
}),
},
...theme.applyStyles('light', {
borderColor: '#f0f0f0',
color: 'rgba(0,0,0,.85)',
}),
}));

const StyledBox = styled('div')(({ theme }) => ({
Expand Down
68 changes: 42 additions & 26 deletions docs/data/data-grid/demo/FullFeaturedDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import MenuItem from '@mui/material/MenuItem';
import Select, { SelectProps } from '@mui/material/Select';

const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
border: `1px solid ${theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'}`,
color:
theme.palette.mode === 'light' ? 'rgba(0,0,0,.85)' : 'rgba(255,255,255,0.85)',
border: '1px solid #303030',
color: 'rgba(255,255,255,0.85)',
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
Expand All @@ -33,24 +32,28 @@ const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
WebkitFontSmoothing: 'auto',
letterSpacing: 'normal',
'& .MuiDataGrid-columnsContainer': {
backgroundColor: theme.palette.mode === 'light' ? '#fafafa' : '#1d1d1d',
backgroundColor: '#1d1d1d',
...theme.applyStyles('light', {
backgroundColor: '#fafafa',
}),
},
'& .MuiDataGrid-iconSeparator': {
display: 'none',
},
'& .MuiDataGrid-columnHeader, .MuiDataGrid-cell': {
borderRight: `1px solid ${
theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'
}`,
borderRight: '1px solid #303030',
...theme.applyStyles('light', {
borderRightColor: '#f0f0f0',
}),
},
'& .MuiDataGrid-columnsContainer, .MuiDataGrid-cell': {
borderBottom: `1px solid ${
theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'
}`,
borderBottom: '1px solid #303030',
...theme.applyStyles('light', {
borderBottomColor: '#f0f0f0',
}),
},
'& .MuiDataGrid-cell': {
color:
theme.palette.mode === 'light' ? 'rgba(0,0,0,.85)' : 'rgba(255,255,255,0.85)',
color: 'rgba(255,255,255,0.85)',
fontFamily: [
'-apple-system',
'BlinkMacSystemFont',
Expand All @@ -66,26 +69,31 @@ const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
WebkitFontSmoothing: 'auto',
letterSpacing: 'normal',
'& .MuiDataGrid-columnsContainer': {
backgroundColor: theme.palette.mode === 'light' ? '#fafafa' : '#1d1d1d',
backgroundColor: '#1d1d1d',
...theme.applyStyles('light', {
backgroundColor: '#fafafa',
}),
},
'& .MuiDataGrid-iconSeparator': {
display: 'none',
},
'& .MuiDataGrid-colCell, .MuiDataGrid-cell': {
borderRight: `1px solid ${
theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'
}`,
borderRight: '1px solid #303030',
...theme.applyStyles('light', {
borderRightColor: '#f0f0f0',
}),
},
'& .MuiDataGrid-columnsContainer, .MuiDataGrid-cell': {
borderBottom: `1px solid ${
theme.palette.mode === 'light' ? '#f0f0f0' : '#303030'
}`,
borderBottom: '1px solid #303030',
...theme.applyStyles('light', {
borderBottomColor: '#f0f0f0',
}),
},
'& .MuiDataGrid-cell': {
color:
theme.palette.mode === 'light'
? 'rgba(0,0,0,.85)'
: 'rgba(255,255,255,0.65)',
color: 'rgba(255,255,255,0.65)',
...theme.applyStyles('light', {
color: 'rgba(0,0,0,.85)',
}),
},
'& .MuiPaginationItem-root': {
borderRadius: 0,
Expand All @@ -94,10 +102,11 @@ const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
width: 16,
height: 16,
backgroundColor: 'transparent',
border: `1px solid ${
theme.palette.mode === 'light' ? '#d9d9d9' : 'rgb(67, 67, 67)'
}`,
border: '1px solid rgb(67, 67, 67)',
borderRadius: 2,
...theme.applyStyles('light', {
borderColor: '#d9d9d9',
}),
},
'& .MuiCheckbox-root svg path': {
display: 'none',
Expand Down Expand Up @@ -129,7 +138,14 @@ const AntDesignStyledDataGridPro = styled(DataGridPro)(({ theme }) => ({
top: '39%',
border: 0,
},
...theme.applyStyles('light', {
color: 'rgba(0,0,0,.85)',
}),
},
...theme.applyStyles('light', {
borderColor: '#f0f0f0',
color: 'rgba(0,0,0,.85)',
}),
}));

const StyledBox = styled('div')(({ theme }) => ({
Expand Down
10 changes: 6 additions & 4 deletions docs/data/data-grid/editing/IsCellEditableGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import {
export default function IsCellEditableGrid() {
return (
<Box
sx={{
sx={(theme) => ({
height: 400,
width: '100%',
'& .MuiDataGrid-cell--editable': {
bgcolor: (theme) =>
theme.palette.mode === 'dark' ? '#376331' : 'rgb(217 243 190)',
bgcolor: 'rgb(217 243 190)',
...theme.applyStyles('dark', {
bgcolor: '#376331',
}),
},
}}
})}
>
<DataGrid
rows={rows}
Expand Down
10 changes: 6 additions & 4 deletions docs/data/data-grid/editing/IsCellEditableGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import {
export default function IsCellEditableGrid() {
return (
<Box
sx={{
sx={(theme) => ({
height: 400,
width: '100%',
'& .MuiDataGrid-cell--editable': {
bgcolor: (theme) =>
theme.palette.mode === 'dark' ? '#376331' : 'rgb(217 243 190)',
bgcolor: 'rgb(217 243 190)',
...theme.applyStyles('dark', {
bgcolor: '#376331',
}),
},
}}
})}
>
<DataGrid
rows={rows}
Expand Down
Loading