-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathEditorTitle.js
More file actions
44 lines (35 loc) · 1.12 KB
/
EditorTitle.js
File metadata and controls
44 lines (35 loc) · 1.12 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
import { createElement } from '../utils/dom.js';
import { isNew, isString } from '../utils/errorHandler.js';
function EditorTitle({ div, initialState, onChangeTitle }) {
isNew(new.target);
const editorTitle = createElement('div');
editorTitle.className = 'editor-title';
this.state = initialState;
div.appendChild(editorTitle);
this.setState = (nextState) => {
this.state = nextState;
const { title } = this.state;
this.render();
editorTitle.querySelector('.title').value = title && title;
};
this.render = () => {
const { title } = this.state;
editorTitle.innerHTML = `<input type="text" name="title" class="title" placeholder="제목 없음" value="${title}"/>`;
div.appendChild(editorTitle);
};
const onKeyupEditorTitle = () => {
editorTitle.addEventListener('keyup', (e) => {
const { name } = e.target;
const titleValue = e.target.value;
isString(titleValue);
const nextState = {
...this.state,
[name]: titleValue,
};
onChangeTitle(nextState);
});
};
this.render();
onKeyupEditorTitle();
}
export default EditorTitle;