1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | const _excluded = ["className", "component", "padding", "size", "stickyHeader"];
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import clsx from 'clsx';
|
7 | import { unstable_composeClasses as composeClasses } from '@mui/base';
|
8 | import TableContext from './TableContext';
|
9 | import useThemeProps from '../styles/useThemeProps';
|
10 | import styled from '../styles/styled';
|
11 | import { getTableUtilityClass } from './tableClasses';
|
12 | import { jsx as _jsx } from "react/jsx-runtime";
|
13 |
|
14 | const 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 |
|
25 | const 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 | }));
|
51 | const defaultComponent = 'table';
|
52 | const Table = 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 _jsx(TableContext.Provider, {
|
81 | value: table,
|
82 | children: _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 | });
|
91 | process.env.NODE_ENV !== "production" ? Table.propTypes
|
92 |
|
93 | = {
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | |
100 |
|
101 |
|
102 | children: PropTypes.node,
|
103 |
|
104 | |
105 |
|
106 |
|
107 | classes: PropTypes.object,
|
108 |
|
109 | |
110 |
|
111 |
|
112 | className: PropTypes.string,
|
113 |
|
114 | |
115 |
|
116 |
|
117 |
|
118 | component: PropTypes.elementType,
|
119 |
|
120 | |
121 |
|
122 |
|
123 |
|
124 | padding: PropTypes.oneOf(['checkbox', 'none', 'normal']),
|
125 |
|
126 | |
127 |
|
128 |
|
129 |
|
130 | size: PropTypes
|
131 |
|
132 | .oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
|
133 |
|
134 | |
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | stickyHeader: PropTypes.bool,
|
141 |
|
142 | |
143 |
|
144 |
|
145 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
146 | } : void 0;
|
147 | export default Table; |
\ | No newline at end of file |