Skip to content

Commit

Permalink
[TableCell] Enable variant overrides via TypeScript module augmentati…
Browse files Browse the repository at this point in the history
…on (mui#33856)

* [TableCell] Enable variant overrides (mui#33793)

* added prettier (mui#33793)

* fix redundant module declaration
  • Loading branch information
arjunvkurup authored and Daniel Rabe committed Nov 29, 2022
1 parent e007319 commit 9e9df5c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/pages/material-ui/api/table-cell.json
Expand Up @@ -34,8 +34,8 @@
},
"variant": {
"type": {
"name": "enum",
"description": "'body'<br>&#124;&nbsp;'footer'<br>&#124;&nbsp;'head'"
"name": "union",
"description": "'body'<br>&#124;&nbsp;'footer'<br>&#124;&nbsp;'head'<br>&#124;&nbsp;string"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-material/src/TableCell/TableCell.d.ts
Expand Up @@ -5,6 +5,7 @@ import { InternalStandardProps as StandardProps, Theme } from '..';
import { TableCellClasses } from './tableCellClasses';

export interface TableCellPropsSizeOverrides {}
export interface TableCellPropsVariantOverrides {}

/**
* `<TableCell>` will be rendered as an `<th>`or `<td>` depending
Expand Down Expand Up @@ -62,7 +63,7 @@ export interface TableCellProps extends StandardProps<TableCellBaseProps, 'align
* Specify the cell type.
* The prop defaults to the value inherited from the parent TableHead, TableBody, or TableFooter components.
*/
variant?: 'head' | 'body' | 'footer';
variant?: OverridableStringUnion<'head' | 'body' | 'footer', TableCellPropsVariantOverrides>;
}

export type TableCellBaseProps = React.ThHTMLAttributes<HTMLTableCellElement> &
Expand Down
5 changes: 4 additions & 1 deletion packages/mui-material/src/TableCell/TableCell.js
Expand Up @@ -240,7 +240,10 @@ TableCell.propTypes /* remove-proptypes */ = {
* Specify the cell type.
* The prop defaults to the value inherited from the parent TableHead, TableBody, or TableFooter components.
*/
variant: PropTypes.oneOf(['body', 'footer', 'head']),
variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
PropTypes.oneOf(['body', 'footer', 'head']),
PropTypes.string,
]),
};

export default TableCell;
Expand Up @@ -13,6 +13,9 @@ declare module '@mui/material/TableCell' {
interface TableCellPropsSizeOverrides {
large: true;
}
interface TableCellPropsVariantOverrides {
tableBody: true;
}
}

// theme typings should work as expected
Expand All @@ -26,10 +29,28 @@ const theme = createTheme({
}),
}),
},
variants: [
{
props: { variant: 'tableBody' },
style: {
fontSize: '1.2em',
color: '#C1D3FF',
},
},
],
},
},
});

<Table size="large">
<TableCell size="large" />
</Table>;

<Table size="large">
<TableCell variant="tableBody">Foo</TableCell>;
</Table>;

<Table size="large">
{/* @ts-expect-error unknown variant */}
<TableCell variant="tableHeading">Bar</TableCell>;
</Table>;

0 comments on commit 9e9df5c

Please sign in to comment.