From 8944bfcd37e7a778c21ddfac8ab583cbd7f39bfe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=ADctor=20Casas?=
<57921784+vicasas@users.noreply.github.com>
Date: Wed, 4 May 2022 12:44:37 -0400
Subject: [PATCH] [Table, TableRow] Add support for CSS variables (#32614)
---
docs/pages/experiments/material-ui/table.tsx | 96 +++++++++++++++++++
packages/mui-material/src/Table/Table.js | 2 +-
.../mui-material/src/TableRow/TableRow.js | 16 ++--
3 files changed, 107 insertions(+), 7 deletions(-)
create mode 100644 docs/pages/experiments/material-ui/table.tsx
diff --git a/docs/pages/experiments/material-ui/table.tsx b/docs/pages/experiments/material-ui/table.tsx
new file mode 100644
index 00000000000000..1304bb14e8f3d0
--- /dev/null
+++ b/docs/pages/experiments/material-ui/table.tsx
@@ -0,0 +1,96 @@
+import * as React from 'react';
+import {
+ Experimental_CssVarsProvider as CssVarsProvider,
+ useColorScheme,
+} from '@mui/material/styles';
+import CssBaseline from '@mui/material/CssBaseline';
+import Box from '@mui/material/Box';
+import Button from '@mui/material/Button';
+import Container from '@mui/material/Container';
+import Moon from '@mui/icons-material/DarkMode';
+import Sun from '@mui/icons-material/LightMode';
+import Table from '@mui/material/Table';
+import { TableBody, TableHead, TableRow } from '@mui/material';
+
+const ColorSchemePicker = () => {
+ const { mode, setMode } = useColorScheme();
+ const [mounted, setMounted] = React.useState(false);
+ React.useEffect(() => {
+ setMounted(true);
+ }, []);
+ if (!mounted) {
+ return null;
+ }
+
+ return (
+
+ );
+};
+
+export default function CssVarsTemplate() {
+ return (
+
+
+
+
+
+
+ div': {
+ placeSelf: 'center',
+ },
+ }}
+ >
+
+
+
+ Hi, I am a row
+
+
+ Hi, I am a row
+
+
+
+
+
+
+ Hello, I am row
+
+
+ Hello, I am a selected row
+
+
+
+
+
+
+ Hello, I am a row
+
+
+
+ Hello, I am a selected and hover row
+
+
+
+
+
+
+
+ );
+}
diff --git a/packages/mui-material/src/Table/Table.js b/packages/mui-material/src/Table/Table.js
index 94fbd548971959..d52434210764e6 100644
--- a/packages/mui-material/src/Table/Table.js
+++ b/packages/mui-material/src/Table/Table.js
@@ -33,7 +33,7 @@ const TableRoot = styled('table', {
'& caption': {
...theme.typography.body2,
padding: theme.spacing(2),
- color: theme.palette.text.secondary,
+ color: (theme.vars || theme).palette.text.secondary,
textAlign: 'left',
captionSide: 'bottom',
},
diff --git a/packages/mui-material/src/TableRow/TableRow.js b/packages/mui-material/src/TableRow/TableRow.js
index 2ac54e89ae4502..b0607c73ebab5d 100644
--- a/packages/mui-material/src/TableRow/TableRow.js
+++ b/packages/mui-material/src/TableRow/TableRow.js
@@ -33,15 +33,19 @@ const TableRowRoot = styled('tr', {
// We disable the focus ring for mouse, touch and keyboard users.
outline: 0,
[`&.${tableRowClasses.hover}:hover`]: {
- backgroundColor: theme.palette.action.hover,
+ backgroundColor: (theme.vars || theme).palette.action.hover,
},
[`&.${tableRowClasses.selected}`]: {
- backgroundColor: alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
+ backgroundColor: theme.vars
+ ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})`
+ : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
'&:hover': {
- backgroundColor: alpha(
- theme.palette.primary.main,
- theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity,
- ),
+ backgroundColor: theme.vars
+ ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.hoverOpacity}))`
+ : alpha(
+ theme.palette.primary.main,
+ theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity,
+ ),
},
},
}));