UNPKG

1.84 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @format
8 *
9 * @emails oncall+draft_js
10 */
11'use strict';
12
13function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
14
15var React = require("react");
16
17var cx = require("fbjs/lib/cx");
18
19/**
20 * This component is responsible for rendering placeholder text for the
21 * `DraftEditor` component.
22 *
23 * Override placeholder style via CSS.
24 */
25var DraftEditorPlaceholder = /*#__PURE__*/function (_React$Component) {
26 _inheritsLoose(DraftEditorPlaceholder, _React$Component);
27
28 function DraftEditorPlaceholder() {
29 return _React$Component.apply(this, arguments) || this;
30 }
31
32 var _proto = DraftEditorPlaceholder.prototype;
33
34 _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
35 return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
36 };
37
38 _proto.render = function render() {
39 var hasFocus = this.props.editorState.getSelection().getHasFocus();
40 var className = cx({
41 'public/DraftEditorPlaceholder/root': true,
42 'public/DraftEditorPlaceholder/hasFocus': hasFocus
43 });
44 var contentStyle = {
45 whiteSpace: 'pre-wrap'
46 };
47 return React.createElement("div", {
48 className: className
49 }, React.createElement("div", {
50 className: cx('public/DraftEditorPlaceholder/inner'),
51 id: this.props.accessibilityID,
52 style: contentStyle
53 }, this.props.text));
54 };
55
56 return DraftEditorPlaceholder;
57}(React.Component);
58
59module.exports = DraftEditorPlaceholder;
\No newline at end of file