-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcolumn.js
More file actions
65 lines (54 loc) · 2.04 KB
/
column.js
File metadata and controls
65 lines (54 loc) · 2.04 KB
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
import React, { PropTypes } from 'react';
import classnames from 'classnames';
import { compose, shouldUpdate, getContext, mapProps } from 'recompose';
const Column = compose(
//Only update if forceUpdate is true or the values don't match
shouldUpdate(({ value }, nextProps) => (nextProps.value !== value || nextProps.forceUpdate === true )),
//We are using the following contexts:
getContext({ utils: PropTypes.object }),
//Build new props in addition to the ones that are passed in
mapProps(props => ({
classNames: classnames(props.utils.getStyleProperties(props, 'column'), props.cssClassName),
//This is the inline styles object to use
columnStyles: props.styles.getStyle({
styles: props.styles.inlineStyles,
styleName: 'column',
mergeStyles: {
...((props.width || props.alignment || props.styles) ?
Object.assign({ width: props.width || null,
textAlign: props.alignment }) : {})
}
}),
//Click callback
handleClick: (e) => {
if (props.onClick) { props.onClick(e) };
props.events.columnClick(props.dataKey, props.value, props.rowIndex, props.rowData);
},
//hover callback
handleHover: (e) => {
props.events.columnHover(props.dataKey, props.value, props.rowIndex, props.rowData);
},
columnValue: (props.hasOwnProperty('customComponent') ?
<props.customComponent
data={props.value}
rowData={props.rowData}
originalData={props.originalRowData}
rowIndex={props.rowIndex}
absoluteRowIndex={props.absoluteRowIndex}
extraData={props.extraData} /> :
props.value),
//Return all the props
...props
}))
)(({ columnValue, handleHover, handleClick, classNames, columnStyles, dataKey, rowIndex }) => (
<td
style={columnStyles}
key={dataKey}
rowIndex={rowIndex}
onClick={handleClick}
onMouseOver={handleHover}
className={classNames}>
{columnValue}
</td>
))
export default Column;