1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import { chainPropTypes } from '@material-ui/utils';
|
7 | import withStyles from '../styles/withStyles';
|
8 | import TableContext from './TableContext';
|
9 | export const styles = theme => ({
|
10 |
|
11 | root: {
|
12 | display: 'table',
|
13 | width: '100%',
|
14 | borderCollapse: 'collapse',
|
15 | borderSpacing: 0,
|
16 | '& caption': _extends({}, theme.typography.body2, {
|
17 | padding: theme.spacing(2),
|
18 | color: theme.palette.text.secondary,
|
19 | textAlign: 'left',
|
20 | captionSide: 'bottom'
|
21 | })
|
22 | },
|
23 |
|
24 |
|
25 | stickyHeader: {
|
26 | borderCollapse: 'separate'
|
27 | }
|
28 | });
|
29 | const defaultComponent = 'table';
|
30 | const Table = React.forwardRef(function Table(props, ref) {
|
31 | const {
|
32 | classes,
|
33 | className,
|
34 | component: Component = defaultComponent,
|
35 | padding = 'normal',
|
36 | size = 'medium',
|
37 | stickyHeader = false
|
38 | } = props,
|
39 | other = _objectWithoutPropertiesLoose(props, ["classes", "className", "component", "padding", "size", "stickyHeader"]);
|
40 |
|
41 | const table = React.useMemo(() => ({
|
42 | padding,
|
43 | size,
|
44 | stickyHeader
|
45 | }), [padding, size, stickyHeader]);
|
46 | return React.createElement(TableContext.Provider, {
|
47 | value: table
|
48 | }, React.createElement(Component, _extends({
|
49 | role: Component === defaultComponent ? null : 'table',
|
50 | ref: ref,
|
51 | className: clsx(classes.root, className, stickyHeader && classes.stickyHeader)
|
52 | }, other)));
|
53 | });
|
54 | process.env.NODE_ENV !== "production" ? Table.propTypes = {
|
55 | |
56 |
|
57 |
|
58 | children: PropTypes.node.isRequired,
|
59 |
|
60 | |
61 |
|
62 |
|
63 |
|
64 | classes: PropTypes.object.isRequired,
|
65 |
|
66 | |
67 |
|
68 |
|
69 | className: PropTypes.string,
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 | component: PropTypes
|
76 |
|
77 | .elementType,
|
78 |
|
79 | |
80 |
|
81 |
|
82 |
|
83 | padding: chainPropTypes(PropTypes.oneOf(['normal', 'checkbox', 'none', 'default']), props => {
|
84 | if (props.padding === 'default') {
|
85 | return new Error('Material-UI: padding="default" was renamed to padding="normal" for consistency.');
|
86 | }
|
87 |
|
88 | return null;
|
89 | }),
|
90 |
|
91 | |
92 |
|
93 |
|
94 | size: PropTypes.oneOf(['small', 'medium']),
|
95 |
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 | stickyHeader: PropTypes.bool
|
102 | } : void 0;
|
103 | export default withStyles(styles, {
|
104 | name: 'MuiTable'
|
105 | })(Table); |
\ | No newline at end of file |