UNPKG

dh-c

Version:

The front-end development engineers jimberton gulp react component

122 lines (94 loc) 4.05 kB
'use strict'; exports.__esModule = true; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var DatasheetCell = function (_React$Component) { _inherits(DatasheetCell, _React$Component); function DatasheetCell(props) { _classCallCheck(this, DatasheetCell); // this.state = { // value: props.value // }; var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.handleClick = _this.handleClick.bind(_this); _this.handleKeyDown = _this.handleKeyDown.bind(_this); // this.handleChange = this.handleChange.bind(this); _this.handleBlur = _this.handleBlur.bind(_this); _this.handleDoubleClick = _this.handleDoubleClick.bind(_this); return _this; } DatasheetCell.prototype.componentDidUpdate = function componentDidUpdate(prevProps) { var _props = this.props, rIndex = _props.rIndex, index = _props.index; if (this.props.editable && this.props.selected) { var ref = this.refs['input_' + rIndex + '_' + index]; //ref.focus(); // let val = ref.value; // ref.value = ''; // ref.value = val; } }; DatasheetCell.prototype.handleDoubleClick = function handleDoubleClick() { var _props2 = this.props, rIndex = _props2.rIndex, index = _props2.index; this.props.onDoubleClick(rIndex, index); }; DatasheetCell.prototype.handleClick = function handleClick() { var _props3 = this.props, rIndex = _props3.rIndex, index = _props3.index; this.props.onClick(rIndex, index); }; DatasheetCell.prototype.handleKeyDown = function handleKeyDown() { var _props4 = this.props, rIndex = _props4.rIndex, index = _props4.index; this.props.onEditable(rIndex, index); }; // handleChange(e) { // this.setState({ value: e.target.value }); // } DatasheetCell.prototype.handleBlur = function handleBlur(e) { var value = e.target.value; var _props5 = this.props, rIndex = _props5.rIndex, index = _props5.index; if (this.props.value + '' !== value) { this.props.onChange(rIndex, index, value); } }; DatasheetCell.prototype.render = function render() { var props = this.props; var value = props.value; return _react2.default.createElement( 'td', { className: props.selected ? 'selected' : '', onClick: this.handleDoubleClick // onClick={this.handleClick} }, props.editable ? _react2.default.createElement('input', { className: 'editable', ref: 'input_' + props.rIndex + '_' + props.index, defaultValue: value // onChange={this.handleChange} , onBlur: this.handleBlur }) : null, _react2.default.createElement( 'span', null, value || '-' ) ); }; return DatasheetCell; }(_react2.default.Component); exports.default = DatasheetCell;