forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableRow.tsx
72 lines (64 loc) · 1.71 KB
/
TableRow.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import PropTypes from 'prop-types';
import omit from 'lodash.omit';
import cx from 'classnames';
import { usePrefix } from '../../internal/usePrefix';
import { ReactAttr } from '../../types/common';
export interface TableRowProps extends ReactAttr<HTMLTableRowElement> {
/**
* Specify an optional className to be applied to the container node
*/
className?: string;
/**
* Specify if the row is selected
*/
isSelected?: boolean;
}
const TableRow = (props: TableRowProps) => {
const prefix = usePrefix();
let rowHasSlug;
if (props?.children) {
React.Children.toArray(props.children).map((child: any) => {
if (child.type?.displayName === 'TableSlugRow') {
if (child.props.slug) {
rowHasSlug = true;
}
}
});
}
// Remove unnecessary props if provided to this component, these are
// only useful in `TableExpandRow`
const className = cx(props.className, {
[`${prefix}--data-table--selected`]: props.isSelected,
[`${prefix}--data-table--slug-row`]: rowHasSlug,
});
const cleanProps = {
...omit(props, [
'ariaLabel',
'aria-label',
'aria-controls',
'onExpand',
'isExpanded',
'isSelected',
]),
className: className || undefined,
};
return <tr {...cleanProps} />;
};
TableRow.propTypes = {
/**
* Specify an optional className to be applied to the container node
*/
className: PropTypes.string,
/**
* Specify if the row is selected
*/
isSelected: PropTypes.bool,
};
export default TableRow;