UNPKG

4.12 kBJavaScriptView Raw
1import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2import _extends from "@babel/runtime/helpers/esm/extends";
3const _excluded = ["className", "component", "padding", "size", "stickyHeader"];
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import TableContext from './TableContext';
9import useThemeProps from '../styles/useThemeProps';
10import styled from '../styles/styled';
11import { getTableUtilityClass } from './tableClasses';
12import { jsx as _jsx } from "react/jsx-runtime";
13
14const useUtilityClasses = ownerState => {
15 const {
16 classes,
17 stickyHeader
18 } = ownerState;
19 const slots = {
20 root: ['root', stickyHeader && 'stickyHeader']
21 };
22 return composeClasses(slots, getTableUtilityClass, classes);
23};
24
25const TableRoot = styled('table', {
26 name: 'MuiTable',
27 slot: 'Root',
28 overridesResolver: (props, styles) => {
29 const {
30 ownerState
31 } = props;
32 return [styles.root, ownerState.stickyHeader && styles.stickyHeader];
33 }
34})(({
35 theme,
36 ownerState
37}) => _extends({
38 display: 'table',
39 width: '100%',
40 borderCollapse: 'collapse',
41 borderSpacing: 0,
42 '& caption': _extends({}, theme.typography.body2, {
43 padding: theme.spacing(2),
44 color: (theme.vars || theme).palette.text.secondary,
45 textAlign: 'left',
46 captionSide: 'bottom'
47 })
48}, ownerState.stickyHeader && {
49 borderCollapse: 'separate'
50}));
51const defaultComponent = 'table';
52const Table = /*#__PURE__*/React.forwardRef(function Table(inProps, ref) {
53 const props = useThemeProps({
54 props: inProps,
55 name: 'MuiTable'
56 });
57
58 const {
59 className,
60 component = defaultComponent,
61 padding = 'normal',
62 size = 'medium',
63 stickyHeader = false
64 } = props,
65 other = _objectWithoutPropertiesLoose(props, _excluded);
66
67 const ownerState = _extends({}, props, {
68 component,
69 padding,
70 size,
71 stickyHeader
72 });
73
74 const classes = useUtilityClasses(ownerState);
75 const table = React.useMemo(() => ({
76 padding,
77 size,
78 stickyHeader
79 }), [padding, size, stickyHeader]);
80 return /*#__PURE__*/_jsx(TableContext.Provider, {
81 value: table,
82 children: /*#__PURE__*/_jsx(TableRoot, _extends({
83 as: component,
84 role: component === defaultComponent ? null : 'table',
85 ref: ref,
86 className: clsx(classes.root, className),
87 ownerState: ownerState
88 }, other))
89 });
90});
91process.env.NODE_ENV !== "production" ? Table.propTypes
92/* remove-proptypes */
93= {
94 // ----------------------------- Warning --------------------------------
95 // | These PropTypes are generated from the TypeScript type definitions |
96 // | To update them edit the d.ts file and run "yarn proptypes" |
97 // ----------------------------------------------------------------------
98
99 /**
100 * The content of the table, normally `TableHead` and `TableBody`.
101 */
102 children: PropTypes.node,
103
104 /**
105 * Override or extend the styles applied to the component.
106 */
107 classes: PropTypes.object,
108
109 /**
110 * @ignore
111 */
112 className: PropTypes.string,
113
114 /**
115 * The component used for the root node.
116 * Either a string to use a HTML element or a component.
117 */
118 component: PropTypes.elementType,
119
120 /**
121 * Allows TableCells to inherit padding of the Table.
122 * @default 'normal'
123 */
124 padding: PropTypes.oneOf(['checkbox', 'none', 'normal']),
125
126 /**
127 * Allows TableCells to inherit size of the Table.
128 * @default 'medium'
129 */
130 size: PropTypes
131 /* @typescript-to-proptypes-ignore */
132 .oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
133
134 /**
135 * Set the header sticky.
136 *
137 * ⚠️ It doesn't work with IE11.
138 * @default false
139 */
140 stickyHeader: PropTypes.bool,
141
142 /**
143 * The system prop that allows defining system overrides as well as additional CSS styles.
144 */
145 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
146} : void 0;
147export default Table;
\No newline at end of file