UNPKG

@material-ui/core

Version:

React components that implement Google's Material Design.

76 lines (70 loc) 2.25 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import withStyles from '../styles/withStyles'; import TableContext from './TableContext'; export var styles = { /* Styles applied to the root element. */ root: { display: 'table', width: '100%', borderCollapse: 'collapse', borderSpacing: 0 } }; var Table = React.forwardRef(function Table(props, ref) { var classes = props.classes, className = props.className, _props$component = props.component, Component = _props$component === void 0 ? 'table' : _props$component, _props$padding = props.padding, padding = _props$padding === void 0 ? 'default' : _props$padding, _props$size = props.size, size = _props$size === void 0 ? 'medium' : _props$size, other = _objectWithoutProperties(props, ["classes", "className", "component", "padding", "size"]); var table = React.useMemo(function () { return { padding: padding, size: size }; }, [padding, size]); return React.createElement(TableContext.Provider, { value: table }, React.createElement(Component, _extends({ ref: ref, className: clsx(classes.root, className) }, other))); }); process.env.NODE_ENV !== "production" ? Table.propTypes = { /** * The content of the table, normally `TableHead` and `TableBody`. */ children: PropTypes.node.isRequired, /** * Override or extend the styles applied to the component. * See [CSS API](#css) below for more details. */ classes: PropTypes.object.isRequired, /** * @ignore */ className: PropTypes.string, /** * The component used for the root node. * Either a string to use a DOM element or a component. */ component: PropTypes.elementType, /** * Allows TableCells to inherit padding of the Table. */ padding: PropTypes.oneOf(['default', 'checkbox', 'none']), /** * Allows TableCells to inherit size of the Table. */ size: PropTypes.oneOf(['small', 'medium']) } : void 0; export default withStyles(styles, { name: 'MuiTable' })(Table);