-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathCellTitleSelector.component.js
102 lines (94 loc) · 2.46 KB
/
CellTitleSelector.component.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
import PropTypes from 'prop-types';
import { Action } from '../../Actions';
import { cellTitleDisplayModes } from '../utils/constants';
import CellTitleInput from './CellTitleInput.component';
import CellLink from '../CellLink/CellLink.component';
import TooltipTrigger from '../../TooltipTrigger';
const { TITLE_MODE_TEXT, TITLE_MODE_INPUT } = cellTitleDisplayModes;
/**
* Component that selects and renders the requested title display mode
*/
function CellTitleSelector(props) {
const {
id,
cellData,
className,
displayMode,
onClick,
linkAs,
onEditSubmit,
onEditCancel,
rowData,
columnData,
tooltip,
} = props;
if (displayMode === TITLE_MODE_INPUT) {
return (
<CellTitleInput
id={id && `${id}-input`}
cellData={cellData}
rowData={rowData}
onEditSubmit={onEditSubmit}
onEditCancel={onEditCancel}
/>
);
}
if (onClick) {
return (
<Action
{...columnData}
id={id && `${id}-btn`}
icon={undefined}
className={className}
onClick={event => onClick(event, rowData)}
role="link"
bsStyle="link"
label={cellData}
type="button"
tooltip={tooltip || cellData}
/>
);
}
if (linkAs) {
return (
<CellLink
cellData={cellData}
rowData={rowData}
columnData={{ ...columnData, id, linkAs, tooltip }}
className={className}
></CellLink>
);
}
return (
<TooltipTrigger label={tooltip || cellData} tooltipPlacement="top">
<span id={id} className={className}>
{cellData}
</span>
</TooltipTrigger>
);
}
CellTitleSelector.propTypes = {
/** The id prefix. */
id: PropTypes.string,
/** The input value. */
cellData: PropTypes.string.isRequired,
/** The title element className. */
className: PropTypes.string,
/** The display mode. */
displayMode: PropTypes.oneOf([TITLE_MODE_TEXT, TITLE_MODE_INPUT]),
/** The onClick callback triggered on title main button click. */
onClick: PropTypes.func,
// The "as" property expected in a Link to generate a simple href.
linkAs: PropTypes.element,
/** Input mode : the cancel callback on ESC keydown. */
onEditCancel: PropTypes.func,
/** Input mode : the submit callback on ENTER keydown or blur. */
onEditSubmit: PropTypes.func,
/** The column item */
columnData: PropTypes.object, // eslint-disable-line react/forbid-prop-types
/** The collection item. */
rowData: PropTypes.object, // eslint-disable-line react/forbid-prop-types
/** The title element tooltip */
tooltip: PropTypes.string,
};
export default CellTitleSelector;