UNPKG

2.96 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import withStyles from '../styles/withStyles';
7import Tablelvl2Context from '../Table/Tablelvl2Context';
8import { alpha } from '../styles/colorManipulator';
9export const styles = theme => ({
10 /* Styles applied to the root element. */
11 root: {
12 color: 'inherit',
13 display: 'table-row',
14 verticalAlign: 'middle',
15 // We disable the focus ring for mouse, touch and keyboard users.
16 outline: 0,
17 '&$hover:hover': {
18 backgroundColor: theme.palette.action.hover
19 },
20 '&$selected, &$selected:hover': {
21 backgroundColor: alpha(theme.palette.secondary.main, theme.palette.action.selectedOpacity)
22 }
23 },
24
25 /* Pseudo-class applied to the root element if `selected={true}`. */
26 selected: {},
27
28 /* Pseudo-class applied to the root element if `hover={true}`. */
29 hover: {},
30
31 /* Styles applied to the root element if table variant="head". */
32 head: {},
33
34 /* Styles applied to the root element if table variant="footer". */
35 footer: {}
36});
37const defaultComponent = 'tr';
38/**
39 * Will automatically set dynamic row height
40 * based on the material table element parent (head, body, etc).
41 */
42
43const TableRow = /*#__PURE__*/React.forwardRef(function TableRow(props, ref) {
44 const {
45 classes,
46 className,
47 component: Component = defaultComponent,
48 hover = false,
49 selected = false
50 } = props,
51 other = _objectWithoutPropertiesLoose(props, ["classes", "className", "component", "hover", "selected"]);
52
53 const tablelvl2 = React.useContext(Tablelvl2Context);
54 return /*#__PURE__*/React.createElement(Component, _extends({
55 ref: ref,
56 className: clsx(classes.root, className, tablelvl2 && {
57 'head': classes.head,
58 'footer': classes.footer
59 }[tablelvl2.variant], hover && classes.hover, selected && classes.selected),
60 role: Component === defaultComponent ? null : 'row'
61 }, other));
62});
63process.env.NODE_ENV !== "production" ? TableRow.propTypes = {
64 /**
65 * Should be valid <tr> children such as `TableCell`.
66 */
67 children: PropTypes.node,
68
69 /**
70 * Override or extend the styles applied to the component.
71 * See [CSS API](#css) below for more details.
72 */
73 classes: PropTypes.object.isRequired,
74
75 /**
76 * @ignore
77 */
78 className: PropTypes.string,
79
80 /**
81 * The component used for the root node.
82 * Either a string to use a HTML element or a component.
83 */
84 component: PropTypes
85 /* @typescript-to-proptypes-ignore */
86 .elementType,
87
88 /**
89 * If `true`, the table row will shade on hover.
90 */
91 hover: PropTypes.bool,
92
93 /**
94 * If `true`, the table row will have the selected shading.
95 */
96 selected: PropTypes.bool
97} : void 0;
98export default withStyles(styles, {
99 name: 'MuiTableRow'
100})(TableRow);
\No newline at end of file