Skip to content

Commit

Permalink
migrate tableHead to emotion
Browse files Browse the repository at this point in the history
  • Loading branch information
natac13 committed Jan 30, 2021
1 parent e127eb9 commit 6b2d19f
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 22 deletions.
5 changes: 3 additions & 2 deletions docs/pages/api-docs/table-head.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"props": {
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" } },
"component": { "type": { "name": "elementType" } }
"component": { "type": { "name": "elementType" } },
"sx": { "type": { "name": "object" } }
},
"name": "TableHead",
"styles": { "classes": ["root"], "globalClasses": {}, "name": "MuiTableHead" },
Expand All @@ -11,6 +12,6 @@
"filename": "/packages/material-ui/src/TableHead/TableHead.js",
"inheritance": null,
"demos": "<ul><li><a href=\"/components/tables/\">Tables</a></li></ul>",
"styledComponent": false,
"styledComponent": true,
"cssComponent": false
}
3 changes: 2 additions & 1 deletion docs/translations/api-docs/table-head/table-head.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"propDescriptions": {
"children": "The content of the component, normally <code>TableRow</code>.",
"classes": "Override or extend the styles applied to the component. See <a href=\"#css\">CSS API</a> below for more details.",
"component": "The component used for the root node. Either a string to use a HTML element or a component."
"component": "The component used for the root node. Either a string to use a HTML element or a component.",
"sx": "The system prop that allows defining system overrides as well as additional CSS styles. See the <a href=\"/system/basics/#the-sx-prop\">`sx` page</a> for more details."
},
"classDescriptions": { "root": { "description": "Styles applied to the root element." } }
}
6 changes: 6 additions & 0 deletions packages/material-ui/src/TableHead/TableHead.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { SxProps } from '@material-ui/system';
import * as React from 'react';
import { Theme } from '..';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';

export interface TableHeadTypeMap<P = {}, D extends React.ElementType = 'thead'> {
Expand All @@ -14,6 +16,10 @@ export interface TableHeadTypeMap<P = {}, D extends React.ElementType = 'thead'>
/** Styles applied to the root element. */
root?: string;
};
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
};
defaultComponent: D;
}
Expand Down
57 changes: 46 additions & 11 deletions packages/material-ui/src/TableHead/TableHead.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled';
import Tablelvl2Context from '../Table/Tablelvl2Context';
import useThemeProps from '../styles/useThemeProps';
import experimentalStyled from '../styles/experimentalStyled';
import { getTableHeadUtilityClass } from './tableHeadClasses';

export const styles = {
/* Styles applied to the root element. */
root: {
display: 'table-header-group',
},
const overridesResolver = (props, styles) => styles.root || {};

const useUtilityClasses = (styleProps) => {
const { classes } = styleProps;

const slots = {
root: ['root'],
};

return composeClasses(slots, getTableHeadUtilityClass, classes);
};

const TableHeadRoot = experimentalStyled(
'thead',
{},
{
name: 'MuiTableHead',
slot: 'Root',
overridesResolver,
},
)({
/* Styles applied to the root element. */
display: 'table-header-group',
});

const tablelvl2 = {
variant: 'head',
};

const defaultComponent = 'thead';

const TableHead = React.forwardRef(function TableHead(props, ref) {
const { classes, className, component: Component = defaultComponent, ...other } = props;
const TableHead = React.forwardRef(function TableHead(inProps, ref) {
const props = useThemeProps({ props: inProps, name: 'MuiTableHead' });
const { className, component = defaultComponent, ...other } = props;

const styleProps = {
...props,
component,
};

const classes = useUtilityClasses(styleProps);

return (
<Tablelvl2Context.Provider value={tablelvl2}>
<Component
<TableHeadRoot
as={component}
className={clsx(classes.root, className)}
ref={ref}
role={Component === defaultComponent ? null : 'rowgroup'}
role={component === defaultComponent ? null : 'rowgroup'}
styleProps={styleProps}
{...other}
/>
</Tablelvl2Context.Provider>
Expand Down Expand Up @@ -54,6 +85,10 @@ TableHead.propTypes = {
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.object,
};

export default withStyles(styles, { name: 'MuiTableHead' })(TableHead);
export default TableHead;
18 changes: 10 additions & 8 deletions packages/material-ui/src/TableHead/TableHead.test.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import * as React from 'react';
import { expect } from 'chai';
import { getClasses, createMount, createClientRender, describeConformance } from 'test/utils';
import { createMount, createClientRender, describeConformanceV5 } from 'test/utils';
import TableHead from './TableHead';
import Tablelvl2Context from '../Table/Tablelvl2Context';
import classes from './tableHeadClasses';

describe('<TableHead />', () => {
const mount = createMount();
let classes;
const render = createClientRender();
function renderInTable(node) {
return render(<table>{node}</table>);
}

before(() => {
classes = getClasses(<TableHead>foo</TableHead>);
});

describeConformance(<TableHead />, () => ({
describeConformanceV5(<TableHead />, () => ({
classes,
inheritComponent: 'thead',
mount: (node) => {
const wrapper = mount(<table>{node}</table>);
return wrapper.find('table').childAt(0);
},

render: (node) => {
const { container, ...rest } = render(<table>{node}</table>);
return { container: container.firstChild, ...rest };
},
muiName: 'MuiTableHead',
testVariantProps: { variant: 'foo' },
refInstanceof: window.HTMLTableSectionElement,
testComponentPropWith: 'tbody',
skip: ['componentsProp'],
}));

it('should render children', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/material-ui/src/TableHead/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export { default } from './TableHead';
export * from './TableHead';

export { default as tableHeadClasses } from './tableHeadClasses';
export * from './tableHeadClasses';
3 changes: 3 additions & 0 deletions packages/material-ui/src/TableHead/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { default } from './TableHead';

export { default as tableHeadClasses } from './tableHeadClasses';
export * from './tableHeadClasses';
7 changes: 7 additions & 0 deletions packages/material-ui/src/TableHead/tableHeadClasses.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TableHeadClassKey } from './TableHead';

declare const tableHeadClasses: Record<TableHeadClassKey, string>;

export function getTableHeadUtilityClass(slot: string): string;

export default tableHeadClasses;
9 changes: 9 additions & 0 deletions packages/material-ui/src/TableHead/tableHeadClasses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { generateUtilityClass, generateUtilityClasses } from '@material-ui/unstyled';

export function getTableHeadUtilityClass(slot) {
return generateUtilityClass('MuiTableHead', slot);
}

const tableHeadClasses = generateUtilityClasses('MuiTableHead', ['root']);

export default tableHeadClasses;

0 comments on commit 6b2d19f

Please sign in to comment.