UNPKG

4.58 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 { alpha } from '@mui/system/colorManipulator';
8import Tablelvl2Context from "../Table/Tablelvl2Context.js";
9import { styled } from "../zero-styled/index.js";
10import memoTheme from "../utils/memoTheme.js";
11import { useDefaultProps } from "../DefaultPropsProvider/index.js";
12import tableRowClasses, { getTableRowUtilityClass } from "./tableRowClasses.js";
13import { jsx as _jsx } from "react/jsx-runtime";
14const useUtilityClasses = ownerState => {
15 const {
16 classes,
17 selected,
18 hover,
19 head,
20 footer
21 } = ownerState;
22 const slots = {
23 root: ['root', selected && 'selected', hover && 'hover', head && 'head', footer && 'footer']
24 };
25 return composeClasses(slots, getTableRowUtilityClass, classes);
26};
27const TableRowRoot = styled('tr', {
28 name: 'MuiTableRow',
29 slot: 'Root',
30 overridesResolver: (props, styles) => {
31 const {
32 ownerState
33 } = props;
34 return [styles.root, ownerState.head && styles.head, ownerState.footer && styles.footer];
35 }
36})(memoTheme(({
37 theme
38}) => ({
39 color: 'inherit',
40 display: 'table-row',
41 verticalAlign: 'middle',
42 // We disable the focus ring for mouse, touch and keyboard users.
43 outline: 0,
44 [`&.${tableRowClasses.hover}:hover`]: {
45 backgroundColor: (theme.vars || theme).palette.action.hover
46 },
47 [`&.${tableRowClasses.selected}`]: {
48 backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / ${theme.vars.palette.action.selectedOpacity})` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity),
49 '&:hover': {
50 backgroundColor: theme.vars ? `rgba(${theme.vars.palette.primary.mainChannel} / calc(${theme.vars.palette.action.selectedOpacity} + ${theme.vars.palette.action.hoverOpacity}))` : alpha(theme.palette.primary.main, theme.palette.action.selectedOpacity + theme.palette.action.hoverOpacity)
51 }
52 }
53})));
54const defaultComponent = 'tr';
55/**
56 * Will automatically set dynamic row height
57 * based on the material table element parent (head, body, etc).
58 */
59const TableRow = /*#__PURE__*/React.forwardRef(function TableRow(inProps, ref) {
60 const props = useDefaultProps({
61 props: inProps,
62 name: 'MuiTableRow'
63 });
64 const {
65 className,
66 component = defaultComponent,
67 hover = false,
68 selected = false,
69 ...other
70 } = props;
71 const tablelvl2 = React.useContext(Tablelvl2Context);
72 const ownerState = {
73 ...props,
74 component,
75 hover,
76 selected,
77 head: tablelvl2 && tablelvl2.variant === 'head',
78 footer: tablelvl2 && tablelvl2.variant === 'footer'
79 };
80 const classes = useUtilityClasses(ownerState);
81 return /*#__PURE__*/_jsx(TableRowRoot, {
82 as: component,
83 ref: ref,
84 className: clsx(classes.root, className),
85 role: component === defaultComponent ? null : 'row',
86 ownerState: ownerState,
87 ...other
88 });
89});
90process.env.NODE_ENV !== "production" ? TableRow.propTypes /* remove-proptypes */ = {
91 // ┌────────────────────────────── Warning ──────────────────────────────┐
92 // │ These PropTypes are generated from the TypeScript type definitions. │
93 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
94 // └─────────────────────────────────────────────────────────────────────┘
95 /**
96 * Should be valid `<tr>` children such as `TableCell`.
97 */
98 children: PropTypes.node,
99 /**
100 * Override or extend the styles applied to the component.
101 */
102 classes: PropTypes.object,
103 /**
104 * @ignore
105 */
106 className: PropTypes.string,
107 /**
108 * The component used for the root node.
109 * Either a string to use a HTML element or a component.
110 */
111 component: PropTypes.elementType,
112 /**
113 * If `true`, the table row will shade on hover.
114 * @default false
115 */
116 hover: PropTypes.bool,
117 /**
118 * If `true`, the table row will have the selected shading.
119 * @default false
120 */
121 selected: PropTypes.bool,
122 /**
123 * The system prop that allows defining system overrides as well as additional CSS styles.
124 */
125 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
126} : void 0;
127export default TableRow;
\No newline at end of file