feat: 提交edittype组件render

This commit is contained in:
huyueb 2017-09-22 14:47:12 +08:00
parent bab9b12301
commit 9c056474ca
4 changed files with 135 additions and 0 deletions

View File

@ -0,0 +1,59 @@
import React, { Component } from "react";
import Icon from "bee-icon";
import Checkbox from "bee-checkbox";
export default class CheckboxRender extends Component {
state = {
value: this.props.value,
editable: false
};
handleChange = e => {
const value = e.target.value;
this.setState({ value });
};
check = () => {
this.setState({ editable: false });
if (this.props.onChange) {
this.props.onChange(this.state.value);
}
};
edit = () => {
this.setState({ editable: true });
};
handleKeydown = event => {
console.log(event.keyCode);
if (event.keyCode == 13) {
this.check();
}
};
render() {
const { value, editable } = this.state;
let { isclickTrigger } = this.props;
let cellContent = "";
if (editable) {
cellContent = (
<div className="editable-cell-input-wrapper">
<Checkbox
onChange={this.handleChange}
onKeyDown={this.handleKeydown}
onBlur={this.check}
autoFocus
value={value}
/>
</div>
);
} else {
cellContent = (
<div className="editable-cell-text-wrapper">
{value || " "}
<Icon
type="uf-pencil"
className="editable-cell-icon"
onClick={this.edit}
/>
</div>
);
}
return <div className="editable-cell">{cellContent}</div>;
}
}

0
src/render/DateRender.js Normal file
View File

76
src/render/InputRender.js Normal file
View File

@ -0,0 +1,76 @@
import React, { Component } from "react";
import Icon from "bee-icon";
import Input from "bee-form-control";
export default class InputRender extends Component {
state = {
value: this.props.value,
editable: false
};
handleChange = e => {
const value = e.target.value;
this.setState({ value });
};
check = () => {
this.setState({ editable: false });
if (this.props.onChange) {
this.props.onChange(this.state.value);
}
};
edit = () => {
this.setState({ editable: true });
};
handleKeydown = event => {
console.log(event.keyCode);
if (event.keyCode == 13) {
this.check();
}
};
render() {
const { value, editable } = this.state;
let { isclickTrigger } = this.props;
let cellContent = "";
if (editable) {
cellContent = isclickTrigger ? (
<div className="editable-cell-input-wrapper">
<Input
onChange={this.handleChange}
onKeyDown={this.handleKeydown}
onBlur={this.check}
autoFocus
value={value}
/>
</div>
) : (
<div className="editable-cell-input-wrapper">
<Input
value={value}
onChange={this.handleChange}
onKeyDown={this.handleKeydown}
/>
<Icon
type="uf-correct"
className="editable-cell-icon-check"
onClick={this.check}
/>
</div>
);
} else {
cellContent = isclickTrigger ? (
<div className="editable-cell-text-wrapper" onClick={this.edit}>
{value || " "}
</div>
) : (
<div className="editable-cell-text-wrapper">
{value || " "}
<Icon
type="uf-pencil"
className="editable-cell-icon"
onClick={this.edit}
/>
</div>
);
}
return <div className="editable-cell">{cellContent}</div>;
}
}

View File