|
|
@@ -8,18 +8,6 @@ import Emoji from "./Emoji";
|
|
8
|
8
|
import "./index.css";
|
|
9
|
9
|
|
|
10
|
10
|
const { TextArea } = Input;
|
|
11
|
|
-// // 设置 Editor 组件的默认值
|
|
12
|
|
-// // 不能在 Editor.defaultProps 中设置
|
|
13
|
|
-// // 因为 Editor 在 ComponentInput 中调用
|
|
14
|
|
-// // 在 ComponentInput 中,需要使用 Editor 的 props 覆盖 ComponentInput 传入的 props
|
|
15
|
|
-// const EditorDefaultProps = {
|
|
16
|
|
-// rows: 5,
|
|
17
|
|
-// placeholder: "说点什么吧...",
|
|
18
|
|
-// showEmoji: true,
|
|
19
|
|
-// showUpload: true,
|
|
20
|
|
-// submitText: "发表",
|
|
21
|
|
-// onChange: () => {},
|
|
22
|
|
-// };
|
|
23
|
11
|
|
|
24
|
12
|
class Editor extends React.Component {
|
|
25
|
13
|
constructor(props) {
|
|
|
@@ -48,6 +36,9 @@ class Editor extends React.Component {
|
|
48
|
36
|
*/
|
|
49
|
37
|
handleChange(value) {
|
|
50
|
38
|
this.setState({ value });
|
|
|
39
|
+ if (this.props.onChange) {
|
|
|
40
|
+ this.props.onChange(value);
|
|
|
41
|
+ }
|
|
51
|
42
|
}
|
|
52
|
43
|
|
|
53
|
44
|
/**
|
|
|
@@ -113,24 +104,21 @@ class Editor extends React.Component {
|
|
113
|
104
|
// const props = { ...EditorDefaultProps, ...this.props };
|
|
114
|
105
|
const {
|
|
115
|
106
|
value,
|
|
116
|
|
- onChange,
|
|
117
|
|
- onSubmit,
|
|
118
|
|
- loading,
|
|
119
|
107
|
placeholder,
|
|
120
|
|
- fileList,
|
|
121
|
|
- onChangeFileList,
|
|
122
|
108
|
rows,
|
|
123
|
|
- onUpload,
|
|
124
|
109
|
showEmoji,
|
|
125
|
110
|
showUpload,
|
|
126
|
|
- submitText
|
|
|
111
|
+ btnSubmitText,
|
|
|
112
|
+ btnLoading,
|
|
|
113
|
+ btnDisabled,
|
|
|
114
|
+ button
|
|
127
|
115
|
} = this.props;
|
|
128
|
116
|
// console.log("editor: ", this.props);
|
|
129
|
117
|
|
|
130
|
118
|
return (
|
|
131
|
119
|
<div className="editor">
|
|
132
|
120
|
<TextArea
|
|
133
|
|
- value={this.state.value}
|
|
|
121
|
+ value={value || this.state.value}
|
|
134
|
122
|
onChange={e => this.handleChange(e.target.value)}
|
|
135
|
123
|
rows={rows}
|
|
136
|
124
|
placeholder={placeholder}
|
|
|
@@ -202,13 +190,16 @@ class Editor extends React.Component {
|
|
202
|
190
|
</div>
|
|
203
|
191
|
|
|
204
|
192
|
<div style={{ float: "right", margin: "5px 11px" }}>
|
|
205
|
|
- <Button
|
|
206
|
|
- onClick={() => this.handleSubmit()}
|
|
207
|
|
- type="primary"
|
|
208
|
|
- loading={loading}
|
|
209
|
|
- >
|
|
210
|
|
- {submitText}
|
|
211
|
|
- </Button>
|
|
|
193
|
+ {button || (
|
|
|
194
|
+ <Button
|
|
|
195
|
+ onClick={() => this.handleSubmit()}
|
|
|
196
|
+ type="primary"
|
|
|
197
|
+ loading={btnLoading}
|
|
|
198
|
+ disabled={btnDisabled}
|
|
|
199
|
+ >
|
|
|
200
|
+ {btnSubmitText}
|
|
|
201
|
+ </Button>
|
|
|
202
|
+ )}
|
|
212
|
203
|
</div>
|
|
213
|
204
|
</div>
|
|
214
|
205
|
</div>
|
|
|
@@ -221,8 +212,13 @@ Editor.propTypes = {
|
|
221
|
212
|
placeholder: PropTypes.string,
|
|
222
|
213
|
showEmoji: PropTypes.bool,
|
|
223
|
214
|
showUpload: PropTypes.bool,
|
|
224
|
|
- submitText: PropTypes.string,
|
|
225
|
|
- onChange: PropTypes.func
|
|
|
215
|
+ value: PropTypes.string,
|
|
|
216
|
+ onChange: PropTypes.func,
|
|
|
217
|
+ onSubmit: PropTypes.func,
|
|
|
218
|
+ btnSubmitText: PropTypes.string,
|
|
|
219
|
+ btnLoading: PropTypes.bool,
|
|
|
220
|
+ btnDisabled: PropTypes.bool,
|
|
|
221
|
+ button: PropTypes.node
|
|
226
|
222
|
};
|
|
227
|
223
|
|
|
228
|
224
|
Editor.defaultProps = {
|
|
|
@@ -230,7 +226,9 @@ Editor.defaultProps = {
|
|
230
|
226
|
placeholder: "说点什么吧...",
|
|
231
|
227
|
showEmoji: true,
|
|
232
|
228
|
showUpload: true,
|
|
233
|
|
- submitText: "发表"
|
|
|
229
|
+ btnSubmitText: "发表",
|
|
|
230
|
+ btnLoading: false,
|
|
|
231
|
+ btnDisabled: false
|
|
234
|
232
|
};
|
|
235
|
233
|
|
|
236
|
234
|
export default Editor;
|