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 { darken, alpha, lighten } from '@mui/system/colorManipulator';
|
8 | import capitalize from "../utils/capitalize.js";
|
9 | import TableContext from "../Table/TableContext.js";
|
10 | import Tablelvl2Context from "../Table/Tablelvl2Context.js";
|
11 | import { styled } from "../zero-styled/index.js";
|
12 | import memoTheme from "../utils/memoTheme.js";
|
13 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
14 | import tableCellClasses, { getTableCellUtilityClass } from "./tableCellClasses.js";
|
15 | import { jsx as _jsx } from "react/jsx-runtime";
|
16 | const useUtilityClasses = ownerState => {
|
17 | const {
|
18 | classes,
|
19 | variant,
|
20 | align,
|
21 | padding,
|
22 | size,
|
23 | stickyHeader
|
24 | } = ownerState;
|
25 | const slots = {
|
26 | root: ['root', variant, stickyHeader && 'stickyHeader', align !== 'inherit' && `align${capitalize(align)}`, padding !== 'normal' && `padding${capitalize(padding)}`, `size${capitalize(size)}`]
|
27 | };
|
28 | return composeClasses(slots, getTableCellUtilityClass, classes);
|
29 | };
|
30 | const TableCellRoot = styled('td', {
|
31 | name: 'MuiTableCell',
|
32 | slot: 'Root',
|
33 | overridesResolver: (props, styles) => {
|
34 | const {
|
35 | ownerState
|
36 | } = props;
|
37 | return [styles.root, styles[ownerState.variant], styles[`size${capitalize(ownerState.size)}`], ownerState.padding !== 'normal' && styles[`padding${capitalize(ownerState.padding)}`], ownerState.align !== 'inherit' && styles[`align${capitalize(ownerState.align)}`], ownerState.stickyHeader && styles.stickyHeader];
|
38 | }
|
39 | })(memoTheme(({
|
40 | theme
|
41 | }) => ({
|
42 | ...theme.typography.body2,
|
43 | display: 'table-cell',
|
44 | verticalAlign: 'inherit',
|
45 |
|
46 |
|
47 | borderBottom: theme.vars ? `1px solid ${theme.vars.palette.TableCell.border}` : `1px solid
|
48 | ${theme.palette.mode === 'light' ? lighten(alpha(theme.palette.divider, 1), 0.88) : darken(alpha(theme.palette.divider, 1), 0.68)}`,
|
49 | textAlign: 'left',
|
50 | padding: 16,
|
51 | variants: [{
|
52 | props: {
|
53 | variant: 'head'
|
54 | },
|
55 | style: {
|
56 | color: (theme.vars || theme).palette.text.primary,
|
57 | lineHeight: theme.typography.pxToRem(24),
|
58 | fontWeight: theme.typography.fontWeightMedium
|
59 | }
|
60 | }, {
|
61 | props: {
|
62 | variant: 'body'
|
63 | },
|
64 | style: {
|
65 | color: (theme.vars || theme).palette.text.primary
|
66 | }
|
67 | }, {
|
68 | props: {
|
69 | variant: 'footer'
|
70 | },
|
71 | style: {
|
72 | color: (theme.vars || theme).palette.text.secondary,
|
73 | lineHeight: theme.typography.pxToRem(21),
|
74 | fontSize: theme.typography.pxToRem(12)
|
75 | }
|
76 | }, {
|
77 | props: {
|
78 | size: 'small'
|
79 | },
|
80 | style: {
|
81 | padding: '6px 16px',
|
82 | [`&.${tableCellClasses.paddingCheckbox}`]: {
|
83 | width: 24,
|
84 |
|
85 | padding: '0 12px 0 16px',
|
86 | '& > *': {
|
87 | padding: 0
|
88 | }
|
89 | }
|
90 | }
|
91 | }, {
|
92 | props: {
|
93 | padding: 'checkbox'
|
94 | },
|
95 | style: {
|
96 | width: 48,
|
97 |
|
98 | padding: '0 0 0 4px'
|
99 | }
|
100 | }, {
|
101 | props: {
|
102 | padding: 'none'
|
103 | },
|
104 | style: {
|
105 | padding: 0
|
106 | }
|
107 | }, {
|
108 | props: {
|
109 | align: 'left'
|
110 | },
|
111 | style: {
|
112 | textAlign: 'left'
|
113 | }
|
114 | }, {
|
115 | props: {
|
116 | align: 'center'
|
117 | },
|
118 | style: {
|
119 | textAlign: 'center'
|
120 | }
|
121 | }, {
|
122 | props: {
|
123 | align: 'right'
|
124 | },
|
125 | style: {
|
126 | textAlign: 'right',
|
127 | flexDirection: 'row-reverse'
|
128 | }
|
129 | }, {
|
130 | props: {
|
131 | align: 'justify'
|
132 | },
|
133 | style: {
|
134 | textAlign: 'justify'
|
135 | }
|
136 | }, {
|
137 | props: ({
|
138 | ownerState
|
139 | }) => ownerState.stickyHeader,
|
140 | style: {
|
141 | position: 'sticky',
|
142 | top: 0,
|
143 | zIndex: 2,
|
144 | backgroundColor: (theme.vars || theme).palette.background.default
|
145 | }
|
146 | }]
|
147 | })));
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | const TableCell = React.forwardRef(function TableCell(inProps, ref) {
|
154 | const props = useDefaultProps({
|
155 | props: inProps,
|
156 | name: 'MuiTableCell'
|
157 | });
|
158 | const {
|
159 | align = 'inherit',
|
160 | className,
|
161 | component: componentProp,
|
162 | padding: paddingProp,
|
163 | scope: scopeProp,
|
164 | size: sizeProp,
|
165 | sortDirection,
|
166 | variant: variantProp,
|
167 | ...other
|
168 | } = props;
|
169 | const table = React.useContext(TableContext);
|
170 | const tablelvl2 = React.useContext(Tablelvl2Context);
|
171 | const isHeadCell = tablelvl2 && tablelvl2.variant === 'head';
|
172 | let component;
|
173 | if (componentProp) {
|
174 | component = componentProp;
|
175 | } else {
|
176 | component = isHeadCell ? 'th' : 'td';
|
177 | }
|
178 | let scope = scopeProp;
|
179 |
|
180 |
|
181 | if (component === 'td') {
|
182 | scope = undefined;
|
183 | } else if (!scope && isHeadCell) {
|
184 | scope = 'col';
|
185 | }
|
186 | const variant = variantProp || tablelvl2 && tablelvl2.variant;
|
187 | const ownerState = {
|
188 | ...props,
|
189 | align,
|
190 | component,
|
191 | padding: paddingProp || (table && table.padding ? table.padding : 'normal'),
|
192 | size: sizeProp || (table && table.size ? table.size : 'medium'),
|
193 | sortDirection,
|
194 | stickyHeader: variant === 'head' && table && table.stickyHeader,
|
195 | variant
|
196 | };
|
197 | const classes = useUtilityClasses(ownerState);
|
198 | let ariaSort = null;
|
199 | if (sortDirection) {
|
200 | ariaSort = sortDirection === 'asc' ? 'ascending' : 'descending';
|
201 | }
|
202 | return _jsx(TableCellRoot, {
|
203 | as: component,
|
204 | ref: ref,
|
205 | className: clsx(classes.root, className),
|
206 | "aria-sort": ariaSort,
|
207 | scope: scope,
|
208 | ownerState: ownerState,
|
209 | ...other
|
210 | });
|
211 | });
|
212 | process.env.NODE_ENV !== "production" ? TableCell.propTypes = {
|
213 |
|
214 |
|
215 |
|
216 |
|
217 | |
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 | align: PropTypes.oneOf(['center', 'inherit', 'justify', 'left', 'right']),
|
225 | |
226 |
|
227 |
|
228 | children: PropTypes.node,
|
229 | |
230 |
|
231 |
|
232 | classes: PropTypes.object,
|
233 | |
234 |
|
235 |
|
236 | className: PropTypes.string,
|
237 | |
238 |
|
239 |
|
240 |
|
241 | component: PropTypes.elementType,
|
242 | |
243 |
|
244 |
|
245 |
|
246 | padding: PropTypes.oneOf(['checkbox', 'none', 'normal']),
|
247 | |
248 |
|
249 |
|
250 | scope: PropTypes.string,
|
251 | |
252 |
|
253 |
|
254 |
|
255 | size: PropTypes .oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
|
256 | |
257 |
|
258 |
|
259 | sortDirection: PropTypes.oneOf(['asc', 'desc', false]),
|
260 | |
261 |
|
262 |
|
263 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
264 | |
265 |
|
266 |
|
267 |
|
268 | variant: PropTypes .oneOfType([PropTypes.oneOf(['body', 'footer', 'head']), PropTypes.string])
|
269 | } : void 0;
|
270 | export default TableCell; |
\ | No newline at end of file |