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

[TableCell] Enable variant overrides via TypeScript module augmentation #33856

Merged
merged 4 commits into from Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
ZeeshanTamboli marked this conversation as resolved.
Show resolved Hide resolved
}

// 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>;