-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
TablePropsSizeOverrides customization via module augmentation #33802
Comments
I recommend doing this https://codesandbox.io/s/naughty-lake-lp15nu?file=/demo.tsx, but there is a typescript bug on the When you customize the component based on props, use variants MuiTableCell: {
variants: [
{ props: { size: 'small', style: { paddingBlock: 2 },
...
]
} styleOverrides callback MuiTableCell: {
styleOverrides: {
root: ({ ownerState }) => ({
...(ownerState.size === "small" && {
paddingBlock: 2
}),
...(ownerState.size === "medium" && {
paddingBlock: 5
}),
...(ownerState.size === "large" && {
paddingBlock: 10
})
})
}
} |
Suggested fix: diff --git a/packages/mui-material/src/TableCell/TableCell.d.ts b/packages/mui-material/src/TableCell/TableCell.d.ts
index 73f9ba19ed..94b0c32a17 100644
--- a/packages/mui-material/src/TableCell/TableCell.d.ts
+++ b/packages/mui-material/src/TableCell/TableCell.d.ts
@@ -1,8 +1,11 @@
import * as React from 'react';
+import { OverridableStringUnion } from '@mui/types';
import { SxProps } from '@mui/system';
import { InternalStandardProps as StandardProps, Theme } from '..';
import { TableCellClasses } from './tableCellClasses';
+export interface TableCellPropsSizeOverrides {}
+
/**
* `<TableCell>` will be rendered as an `<th>`or `<td>` depending
* on the context it is used in. Where context literally is the
@@ -46,7 +49,7 @@ export interface TableCellProps extends StandardProps<TableCellBaseProps, 'align
* Specify the size of the cell.
* The prop defaults to the value (`'medium'`) inherited from the parent Table component.
*/
- size?: 'small' | 'medium';
+ size?: OverridableStringUnion<'small' | 'medium', TableCellPropsSizeOverrides>;
/**
* Set aria-sort direction.
*/
Need to check the proptypes of Table & TableCell as well |
@siriwatknp Thank you for your input. I have submitted a PR, with the updates that you recommended.
Okay, this is very good information to be aware of. Personally, I prefer the callback style as it seems most direct. Can you briefly clarify what you mean by, "classes will be removed?" Do you just mean from the styleOverrides block in the theme, or that the component CSS API will eventually go away entirely, or perhaps something different? I am happy to read up on it if it has been discussed elsewhere. It sounds like the approach could really help avoid some CSS specificity issues making overrides easier. Thanks! I am assuming that the recommended pattern to target child components in the callback will be to just use their CSS className, yes? fictional example... MuiChip: {
styleOverrides: {
root: ({ ownerState }) => ({
'& .MuiChip-deleteIcon': {
fontSize: theme.typography.pxToRem(14);
...(ownerState.size === "small" && {
fontSize: theme.typography.pxToRem(11)
}),
})
}
} |
Yes, just for the theming point of view. Here is why we want to remove it, those classes do not scale. |
Duplicates
Latest version
Current behavior 😯
I am trying to augment the available Table sizes via module augmentation, to include a "large" size, in addition to the existing "small" and "medium" sizes.
This is currently defined at the top of my custom theme file.
While things render properly, it causes TypeScript issues in the component and in the theme.
Component
Theme
Expected behavior 🤔
I would expect the first 2 errors in the example above to "just work" - that is to say that "large" would be a valid option for the size prop.
I am not sure if that would just work for the TableCell component as well. Perhaps it would require its own augmentation? The TableCell component does however add the "MuiTableCell-sizeLarge" CSS class, so it renders properly.
Steps to reproduce 🕹
https://codesandbox.io/s/trusting-swanson-tpedid?file=/demo.tsx
Context 🔦
I am trying to augment the available Table sizes via module augmentation, to include a "large" size, in addition to the existing "small" and "medium" sizes.
Alternatively, I suppose that I could create wrapper components for the Table and TableCell components and implement the size prop overrides that way. It seemed that module augmentation was the recommended approach however.
Your environment 🌎
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: