1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import TableContext from "./TableContext.js";
|
8 | import { styled } from "../zero-styled/index.js";
|
9 | import memoTheme from "../utils/memoTheme.js";
|
10 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
11 | import { getTableUtilityClass } from "./tableClasses.js";
|
12 | import { jsx as _jsx } from "react/jsx-runtime";
|
13 | const useUtilityClasses = ownerState => {
|
14 | const {
|
15 | classes,
|
16 | stickyHeader
|
17 | } = ownerState;
|
18 | const slots = {
|
19 | root: ['root', stickyHeader && 'stickyHeader']
|
20 | };
|
21 | return composeClasses(slots, getTableUtilityClass, classes);
|
22 | };
|
23 | const TableRoot = styled('table', {
|
24 | name: 'MuiTable',
|
25 | slot: 'Root',
|
26 | overridesResolver: (props, styles) => {
|
27 | const {
|
28 | ownerState
|
29 | } = props;
|
30 | return [styles.root, ownerState.stickyHeader && styles.stickyHeader];
|
31 | }
|
32 | })(memoTheme(({
|
33 | theme
|
34 | }) => ({
|
35 | display: 'table',
|
36 | width: '100%',
|
37 | borderCollapse: 'collapse',
|
38 | borderSpacing: 0,
|
39 | '& caption': {
|
40 | ...theme.typography.body2,
|
41 | padding: theme.spacing(2),
|
42 | color: (theme.vars || theme).palette.text.secondary,
|
43 | textAlign: 'left',
|
44 | captionSide: 'bottom'
|
45 | },
|
46 | variants: [{
|
47 | props: ({
|
48 | ownerState
|
49 | }) => ownerState.stickyHeader,
|
50 | style: {
|
51 | borderCollapse: 'separate'
|
52 | }
|
53 | }]
|
54 | })));
|
55 | const defaultComponent = 'table';
|
56 | const Table = React.forwardRef(function Table(inProps, ref) {
|
57 | const props = useDefaultProps({
|
58 | props: inProps,
|
59 | name: 'MuiTable'
|
60 | });
|
61 | const {
|
62 | className,
|
63 | component = defaultComponent,
|
64 | padding = 'normal',
|
65 | size = 'medium',
|
66 | stickyHeader = false,
|
67 | ...other
|
68 | } = props;
|
69 | const ownerState = {
|
70 | ...props,
|
71 | component,
|
72 | padding,
|
73 | size,
|
74 | stickyHeader
|
75 | };
|
76 | const classes = useUtilityClasses(ownerState);
|
77 | const table = React.useMemo(() => ({
|
78 | padding,
|
79 | size,
|
80 | stickyHeader
|
81 | }), [padding, size, stickyHeader]);
|
82 | return _jsx(TableContext.Provider, {
|
83 | value: table,
|
84 | children: _jsx(TableRoot, {
|
85 | as: component,
|
86 | role: component === defaultComponent ? null : 'table',
|
87 | ref: ref,
|
88 | className: clsx(classes.root, className),
|
89 | ownerState: ownerState,
|
90 | ...other
|
91 | })
|
92 | });
|
93 | });
|
94 | process.env.NODE_ENV !== "production" ? Table.propTypes = {
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | |
100 |
|
101 |
|
102 | children: PropTypes.node,
|
103 | |
104 |
|
105 |
|
106 | classes: PropTypes.object,
|
107 | |
108 |
|
109 |
|
110 | className: PropTypes.string,
|
111 | |
112 |
|
113 |
|
114 |
|
115 | component: PropTypes.elementType,
|
116 | |
117 |
|
118 |
|
119 |
|
120 | padding: PropTypes.oneOf(['checkbox', 'none', 'normal']),
|
121 | |
122 |
|
123 |
|
124 |
|
125 | size: PropTypes .oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
|
126 | |
127 |
|
128 |
|
129 |
|
130 | stickyHeader: PropTypes.bool,
|
131 | |
132 |
|
133 |
|
134 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
|
135 | } : void 0;
|
136 | export default Table; |
\ | No newline at end of file |