Skip to content

Commit fd249d5

Browse files
authored
[TableCell] Enable size prop overrides via module augmentation (#33816)
1 parent 87c1948 commit fd249d5

5 files changed

Lines changed: 53 additions & 3 deletions

File tree

docs/pages/material-ui/api/table-cell.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
}
1818
},
1919
"scope": { "type": { "name": "string" } },
20-
"size": { "type": { "name": "enum", "description": "'small'<br>&#124;&nbsp;'medium'" } },
20+
"size": {
21+
"type": {
22+
"name": "union",
23+
"description": "'medium'<br>&#124;&nbsp;'small'<br>&#124;&nbsp;string"
24+
}
25+
},
2126
"sortDirection": {
2227
"type": { "name": "enum", "description": "'asc'<br>&#124;&nbsp;'desc'<br>&#124;&nbsp;false" }
2328
},

packages/mui-material/src/TableCell/TableCell.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import * as React from 'react';
2+
import { OverridableStringUnion } from '@mui/types';
23
import { SxProps } from '@mui/system';
34
import { InternalStandardProps as StandardProps, Theme } from '..';
45
import { TableCellClasses } from './tableCellClasses';
56

7+
export interface TableCellPropsSizeOverrides {}
8+
69
/**
710
* `<TableCell>` will be rendered as an `<th>`or `<td>` depending
811
* on the context it is used in. Where context literally is the
@@ -46,7 +49,7 @@ export interface TableCellProps extends StandardProps<TableCellBaseProps, 'align
4649
* Specify the size of the cell.
4750
* The prop defaults to the value (`'medium'`) inherited from the parent Table component.
4851
*/
49-
size?: 'small' | 'medium';
52+
size?: OverridableStringUnion<'small' | 'medium', TableCellPropsSizeOverrides>;
5053
/**
5154
* Set aria-sort direction.
5255
*/

packages/mui-material/src/TableCell/TableCell.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ TableCell.propTypes /* remove-proptypes */ = {
220220
* Specify the size of the cell.
221221
* The prop defaults to the value (`'medium'`) inherited from the parent Table component.
222222
*/
223-
size: PropTypes.oneOf(['small', 'medium']),
223+
size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
224+
PropTypes.oneOf(['medium', 'small']),
225+
PropTypes.string,
226+
]),
224227
/**
225228
* Set aria-sort direction.
226229
*/
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as React from 'react';
2+
import Table from '@mui/material/Table';
3+
import TableCell from '@mui/material/TableCell';
4+
import { createTheme } from '@mui/material/styles';
5+
6+
declare module '@mui/material/Table' {
7+
interface TablePropsSizeOverrides {
8+
large: true;
9+
}
10+
}
11+
12+
declare module '@mui/material/TableCell' {
13+
interface TableCellPropsSizeOverrides {
14+
large: true;
15+
}
16+
}
17+
18+
// theme typings should work as expected
19+
const theme = createTheme({
20+
components: {
21+
MuiTableCell: {
22+
styleOverrides: {
23+
root: ({ ownerState }) => ({
24+
...(ownerState.size === 'large' && {
25+
paddingBlock: '1rem',
26+
}),
27+
}),
28+
},
29+
},
30+
},
31+
});
32+
33+
<Table size="large">
34+
<TableCell size="large" />
35+
</Table>;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../../../../tsconfig",
3+
"files": ["tableCellCustomProps.spec.tsx"]
4+
}

0 commit comments

Comments
 (0)