/
Editor.js
159 lines (142 loc) · 3.75 KB
/
Editor.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import React, { Component } from "react";
import styled from "@emotion/styled";
import Tabs from "./tabs";
import NewEditor from "./newEditor";
import 'draft-js/dist/Draft.css'
const EditorContainer = styled.div`
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
min-width: 272px;
min-height: 71px;
max-height: 250px;
height: auto;
overflow: auto;
background-color: white;
box-sizing: border-box;
max-width: inherit;
word-wrap: break-word;
border-top: 1px solid rgb(223, 225, 230);
border-image: initial;
-webkit-animation: none;
animation: none;
//padding: 10px;
//border: 1px solid #ccc;
//border-radius: 2px;
//margin-top: 1px;
.inlineTooltip-button{
width: 30px;
height: 30px;
}
.tooltip-icon svg {
width: 20px;
height: 20px;
display: flex;
margin-left: 6px;
}
`;
const EditorActions = styled.div`
box-sizing: border-box;
-webkit-box-pack: end;
justify-content: flex-end;
-webkit-box-align: center;
align-items: center;
display: flex;
padding: 12px 1px;
`;
const EditorWrapper = styled.div`
width: 100%;
`;
export default class ConversationEditor extends Component {
state = {
loading: false,
sendMode: 'enter'
};
fallbackEditor = false;
delayTimer = null;
submitData = (formats, options) => {
// DANTE does not provide a way to update contentState from outside ?
// hide and show editor hack
this.setState(
{
loading: true,
},
() => {
options.note
? this.props.insertNote(formats, this.enable)
: this.props.insertComment(formats, this.enable);
}
);
};
enable = () => {
this.setState({
loading: false,
});
};
toggleSendMode = (e)=>{
this.setState({
sendMode: this.state.sendMode === 'enter' ? '' : 'enter'
})
}
handleTyping = (content) => {
// means if content empty
if (content.html === '<p className="graf graf--p"></p>') return;
clearTimeout(this.delayTimer);
this.delayTimer = setTimeout(() => {
this.props.typingNotifier();
}, 400);
};
renderEditor = (opts) => {
return (
<EditorWrapper>
<EditorContainer
note={opts.note}
style={opts.note ? { background: "lemonchiffon" } : {}}
>
{!this.state.loading ? (
<NewEditor
insertAppBlockComment={this.props.insertAppBlockComment}
submitData={(formats) => this.submitData(formats, opts)}
saveContentCallback={(content) => this.handleTyping(content)}
sendMode={ this.state.sendMode }
{...this.props}
/>
) : null}
</EditorContainer>
</EditorWrapper>
);
};
render() {
const tabs = [
{ label: "Reply", content: this.renderEditor({}) },
{ label: "Note", content: this.renderEditor({ note: true }) },
];
return (
<Tabs
tabs={tabs}
onSelect={(tab, index) => console.log("Selected Tab", index + 1)}
buttons={()=>(
<div className="flex flex-grow items-center justify-end pr-3">
<input
id="send_mode"
type="checkbox"
checked={this.state.sendMode === 'enter'}
onChange={(e)=>{ this.toggleSendMode(e)}}
className="form-checkbox h-4 w-4 text-indigo-600 transition duration-150 ease-in-out"
/>
<label
htmlFor="send_mode"
className="ml-2 block text-xs leading-5 text-gray-900"
>
{I18n.t('common.send_on_enter')}
</label>
</div>
)}
/>
);
}
}