-
Notifications
You must be signed in to change notification settings - Fork 839
/
Copy pathtable_row_cell.js
119 lines (109 loc) · 3.22 KB
/
table_row_cell.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import {
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
CENTER_ALIGNMENT
} from '../../services';
const ALIGNMENT = [
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
CENTER_ALIGNMENT
];
export const EuiTableRowCell = ({
align,
children,
className,
truncateText,
showOnHover,
textOnly,
colSpan,
header,
hideForMobile,
isMobileHeader,
isMobileFullWidth,
hasActions,
isExpander,
...rest
}) => {
const cellClasses = classNames('euiTableRowCell', {
'euiTableRowCell--hideForMobile': hideForMobile,
'euiTableRowCell--isMobileHeader': isMobileHeader,
'euiTableRowCell--hasActions': hasActions,
'euiTableRowCell--isMobileFullWidth': isMobileFullWidth,
'euiTableRowCell--isExpander': isExpander,
});
const contentClasses = classNames('euiTableCellContent', className, {
'euiTableCellContent--alignRight': align === RIGHT_ALIGNMENT,
'euiTableCellContent--alignCenter': align === CENTER_ALIGNMENT,
'euiTableCellContent--showOnHover': showOnHover,
'euiTableCellContent--truncateText': truncateText,
// We're doing this rigamarole instead of creating `euiTableCellContent--textOnly` for BWC
// purposes for the time-being.
'euiTableCellContent--overflowingContent': textOnly !== true,
});
const childClasses = classNames({
'euiTableCellContent__text': textOnly === true,
'euiTableCellContent__hoverItem': showOnHover,
});
let modifiedChildren = children;
if(textOnly === true) {
modifiedChildren = <span className={childClasses}>{children}</span>;
} else if(React.isValidElement(modifiedChildren)) {
modifiedChildren = React.Children.map(
children,
child => React.cloneElement(
child,
{ className: classNames(child.props.className, childClasses) }
)
);
}
return (
<td className={cellClasses} colSpan={colSpan} data-header={header} {...rest}>
<div className={contentClasses}>
{modifiedChildren}
</div>
</td>
);
};
EuiTableRowCell.propTypes = {
align: PropTypes.oneOf(ALIGNMENT),
showOnHover: PropTypes.bool,
truncateText: PropTypes.bool,
children: PropTypes.node,
className: PropTypes.string,
textOnly: PropTypes.bool,
colSpan: PropTypes.number,
/**
* The column's header title for use in mobile view (will be added as a data-attr)
*/
header: PropTypes.string,
/**
* Indicates if the column was created to be the row's heading in mobile view
* (this column will be hidden at larger screens)
*/
isMobileHeader: PropTypes.bool,
/**
* Indicates if the column should not show for mobile users
* (typically hidden because a custom mobile header utilizes the column's contents)
*/
hideForMobile: PropTypes.bool,
/**
* Allocates 100% of the width of the container in mobile view
* (typically cells are contained to 50%)
*/
isMobileFullWidth: PropTypes.bool,
/**
* Indicates if the column is dedicated to icon-only actions (affects mobile only)
*/
hasActions: PropTypes.bool,
/**
* Indicates if the column is dedicated as the expandable row toggle
*/
isExpander: PropTypes.bool,
};
EuiTableRowCell.defaultProps = {
align: LEFT_ALIGNMENT,
textOnly: true
};