mirror of
https://github.com/element-hq/element-web
synced 2024-11-26 11:15:53 +03:00
implement editor placeholder
This commit is contained in:
parent
e2e4ea493f
commit
f9992a1fc6
4 changed files with 26 additions and 0 deletions
|
@ -16,6 +16,17 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.mx_BasicMessageComposer {
|
.mx_BasicMessageComposer {
|
||||||
|
.mx_BasicMessageComposer_inputEmpty > :first-child:before {
|
||||||
|
content: var(--placeholder);
|
||||||
|
opacity: 0.333;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
overflow: visible;
|
||||||
|
display: inline-block;
|
||||||
|
pointer-events: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
.mx_BasicMessageComposer_input {
|
.mx_BasicMessageComposer_input {
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
|
|
|
@ -54,6 +54,16 @@ export default class BasicMessageEditor extends React.Component {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.props.placeholder) {
|
||||||
|
const {isEmpty} = this.props.model;
|
||||||
|
if (isEmpty) {
|
||||||
|
this._editorRef.style.setProperty("--placeholder", `'${this.props.placeholder}'`);
|
||||||
|
this._editorRef.classList.add("mx_BasicMessageComposer_inputEmpty");
|
||||||
|
} else {
|
||||||
|
this._editorRef.classList.remove("mx_BasicMessageComposer_inputEmpty");
|
||||||
|
this._editorRef.style.removeProperty("--placeholder");
|
||||||
|
}
|
||||||
|
}
|
||||||
this.setState({autoComplete: this.props.model.autoComplete});
|
this.setState({autoComplete: this.props.model.autoComplete});
|
||||||
this.historyManager.tryPush(this.props.model, caret, inputType, diff);
|
this.historyManager.tryPush(this.props.model, caret, inputType, diff);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,7 @@ export default class SendMessageComposer extends React.Component {
|
||||||
model={this.model}
|
model={this.model}
|
||||||
room={this.props.room}
|
room={this.props.room}
|
||||||
label={_t("Send message")}
|
label={_t("Send message")}
|
||||||
|
placeholder={this.props.placeholder}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -35,6 +35,10 @@ export default class EditorModel {
|
||||||
return this._partCreator;
|
return this._partCreator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isEmpty() {
|
||||||
|
return this._parts.reduce((len, part) => len + part.text.length, 0) === 0;
|
||||||
|
}
|
||||||
|
|
||||||
clone() {
|
clone() {
|
||||||
return new EditorModel(this._parts, this._partCreator, this._updateCallback);
|
return new EditorModel(this._parts, this._partCreator, this._updateCallback);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue