Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

57 строки
1.5 KiB

  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. * @flow strict-local
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. import type { DraftTextAlignment } from "./DraftTextAlignment";
  13. import type EditorState from "./EditorState";
  14. const React = require("react");
  15. const cx = require("fbjs/lib/cx");
  16. type Props = {
  17. accessibilityID: string,
  18. editorState: EditorState,
  19. text: string,
  20. textAlignment: DraftTextAlignment,
  21. ...
  22. };
  23. /**
  24. * This component is responsible for rendering placeholder text for the
  25. * `DraftEditor` component.
  26. *
  27. * Override placeholder style via CSS.
  28. */
  29. class DraftEditorPlaceholder extends React.Component<Props> {
  30. shouldComponentUpdate(nextProps: Props): boolean {
  31. return this.props.text !== nextProps.text || this.props.editorState.getSelection().getHasFocus() !== nextProps.editorState.getSelection().getHasFocus();
  32. }
  33. render(): React.Node {
  34. const hasFocus = this.props.editorState.getSelection().getHasFocus();
  35. const className = cx({
  36. 'public/DraftEditorPlaceholder/root': true,
  37. 'public/DraftEditorPlaceholder/hasFocus': hasFocus
  38. });
  39. const contentStyle = {
  40. whiteSpace: 'pre-wrap'
  41. };
  42. return <div className={className}>
  43. <div className={cx('public/DraftEditorPlaceholder/inner')} id={this.props.accessibilityID} style={contentStyle}>
  44. {this.props.text}
  45. </div>
  46. </div>;
  47. }
  48. }
  49. module.exports = DraftEditorPlaceholder;