2019-11-15 09:18:35 +00:00
|
|
|
import React from "react";
|
|
|
|
import styled from "styled-components";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import isEqual from "lodash/isEqual";
|
|
|
|
import Checkbox from "../checkbox";
|
|
|
|
import ContextMenuButton from "../context-menu-button";
|
|
|
|
import { tablet } from "../../utils/device";
|
2019-08-20 13:07:30 +00:00
|
|
|
|
|
|
|
const StyledRow = styled.div`
|
|
|
|
cursor: default;
|
2019-11-15 09:18:35 +00:00
|
|
|
|
2019-08-20 13:07:30 +00:00
|
|
|
min-height: 50px;
|
|
|
|
width: 100%;
|
2019-11-15 09:18:35 +00:00
|
|
|
border-bottom: 1px solid #eceef1;
|
2019-08-20 13:07:30 +00:00
|
|
|
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
|
|
|
align-content: center;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledContent = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-basis: 100%;
|
|
|
|
|
|
|
|
min-width: 160px;
|
|
|
|
|
2019-10-29 10:25:24 +00:00
|
|
|
@media ${tablet} {
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
2019-08-20 13:07:30 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledCheckbox = styled.div`
|
|
|
|
flex: 0 0 16px;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledElement = styled.div`
|
|
|
|
flex: 0 0 auto;
|
|
|
|
display: flex;
|
|
|
|
margin-right: 8px;
|
2019-09-13 08:41:06 +00:00
|
|
|
margin-left: 2px;
|
2019-08-20 13:07:30 +00:00
|
|
|
user-select: none;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const StyledOptionButton = styled.div`
|
|
|
|
flex: 0 0 18px;
|
|
|
|
display: flex;
|
|
|
|
margin-left: 8px;
|
|
|
|
margin-right: 16px;
|
|
|
|
`;
|
|
|
|
|
2019-09-13 12:37:26 +00:00
|
|
|
// eslint-disable-next-line react/display-name
|
2019-11-15 09:18:35 +00:00
|
|
|
|
|
|
|
class Row extends React.Component {
|
|
|
|
shouldComponentUpdate(nextProps) {
|
2019-11-19 11:33:33 +00:00
|
|
|
if (this.props.needForUpdate) {
|
|
|
|
return this.props.needForUpdate(this.props, nextProps);
|
|
|
|
}
|
2019-11-15 09:18:35 +00:00
|
|
|
return !isEqual(this.props, nextProps);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
//console.log("Row render");
|
|
|
|
const {
|
|
|
|
checked,
|
|
|
|
element,
|
|
|
|
children,
|
|
|
|
data,
|
|
|
|
contextOptions,
|
|
|
|
onSelect
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const renderCheckbox = Object.prototype.hasOwnProperty.call(
|
|
|
|
this.props,
|
|
|
|
"checked"
|
|
|
|
);
|
|
|
|
|
|
|
|
const renderElement = Object.prototype.hasOwnProperty.call(
|
|
|
|
this.props,
|
|
|
|
"element"
|
|
|
|
);
|
|
|
|
|
|
|
|
const renderContext =
|
|
|
|
Object.prototype.hasOwnProperty.call(this.props, "contextOptions") &&
|
|
|
|
contextOptions.length > 0;
|
|
|
|
|
|
|
|
const changeCheckbox = e => {
|
|
|
|
onSelect && onSelect(e.target.checked, data);
|
|
|
|
};
|
|
|
|
|
|
|
|
const getOptions = () => contextOptions;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StyledRow {...this.props}>
|
|
|
|
{renderCheckbox && (
|
|
|
|
<StyledCheckbox>
|
|
|
|
<Checkbox isChecked={checked} onChange={changeCheckbox} />
|
|
|
|
</StyledCheckbox>
|
|
|
|
)}
|
|
|
|
{renderElement && <StyledElement>{element}</StyledElement>}
|
|
|
|
<StyledContent>{children}</StyledContent>
|
|
|
|
<StyledOptionButton>
|
|
|
|
{renderContext && (
|
|
|
|
<ContextMenuButton directionX="right" getData={getOptions} />
|
|
|
|
)}
|
|
|
|
</StyledOptionButton>
|
|
|
|
</StyledRow>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-20 13:07:30 +00:00
|
|
|
|
|
|
|
Row.propTypes = {
|
|
|
|
checked: PropTypes.bool,
|
|
|
|
element: PropTypes.element,
|
|
|
|
children: PropTypes.element,
|
|
|
|
data: PropTypes.object,
|
|
|
|
contextOptions: PropTypes.array,
|
2019-11-19 11:33:33 +00:00
|
|
|
onSelect: PropTypes.func,
|
|
|
|
needForUpdate: PropTypes.func
|
2019-08-20 13:07:30 +00:00
|
|
|
};
|
|
|
|
|
2019-11-15 09:18:35 +00:00
|
|
|
export default Row;
|