UNPKG

4.17 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import TableContext from "./TableContext.js";
8import { styled } from "../zero-styled/index.js";
9import memoTheme from "../utils/memoTheme.js";
10import { useDefaultProps } from "../DefaultPropsProvider/index.js";
11import { getTableUtilityClass } from "./tableClasses.js";
12import { jsx as _jsx } from "react/jsx-runtime";
13const 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};
23const 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})));
55const defaultComponent = 'table';
56const Table = /*#__PURE__*/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 /*#__PURE__*/_jsx(TableContext.Provider, {
83 value: table,
84 children: /*#__PURE__*/_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});
94process.env.NODE_ENV !== "production" ? Table.propTypes /* remove-proptypes */ = {
95 // ┌────────────────────────────── Warning ──────────────────────────────┐
96 // │ These PropTypes are generated from the TypeScript type definitions. │
97 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
98 // └─────────────────────────────────────────────────────────────────────┘
99 /**
100 * The content of the table, normally `TableHead` and `TableBody`.
101 */
102 children: PropTypes.node,
103 /**
104 * Override or extend the styles applied to the component.
105 */
106 classes: PropTypes.object,
107 /**
108 * @ignore
109 */
110 className: PropTypes.string,
111 /**
112 * The component used for the root node.
113 * Either a string to use a HTML element or a component.
114 */
115 component: PropTypes.elementType,
116 /**
117 * Allows TableCells to inherit padding of the Table.
118 * @default 'normal'
119 */
120 padding: PropTypes.oneOf(['checkbox', 'none', 'normal']),
121 /**
122 * Allows TableCells to inherit size of the Table.
123 * @default 'medium'
124 */
125 size: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
126 /**
127 * Set the header sticky.
128 * @default false
129 */
130 stickyHeader: PropTypes.bool,
131 /**
132 * The system prop that allows defining system overrides as well as additional CSS styles.
133 */
134 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
135} : void 0;
136export default Table;
\No newline at end of file