通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _button = require("antd/es/button");
  6. var _button2 = _interopRequireDefault(_button);
  7. var _popover = require("antd/es/popover");
  8. var _popover2 = _interopRequireDefault(_popover);
  9. var _icon = require("antd/es/icon");
  10. var _icon2 = _interopRequireDefault(_icon);
  11. var _input = require("antd/es/input");
  12. var _input2 = _interopRequireDefault(_input);
  13. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  14. require("antd/es/button/style/css");
  15. require("antd/es/popover/style/css");
  16. require("antd/es/icon/style/css");
  17. require("antd/es/input/style/css");
  18. var _react = require("react");
  19. var _react2 = _interopRequireDefault(_react);
  20. var _constant = require("../../constant");
  21. var _Upload = require("./Upload");
  22. var _Upload2 = _interopRequireDefault(_Upload);
  23. var _Emoji = require("./Emoji");
  24. var _Emoji2 = _interopRequireDefault(_Emoji);
  25. require("./index.css");
  26. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  27. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  29. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // https://github.com/lovasoa/react-contenteditable/blob/master/src/react-contenteditable.js
  30. // import styles from "./index.less";
  31. var TextArea = _input2.default.TextArea;
  32. var Editor = function (_React$Component) {
  33. _inherits(Editor, _React$Component);
  34. function Editor(props) {
  35. _classCallCheck(this, Editor);
  36. var _this = _possibleConstructorReturn(this, (Editor.__proto__ || Object.getPrototypeOf(Editor)).call(this, props));
  37. _this.state = {
  38. showUpload: false
  39. };
  40. _this.handleClickEmoji = _this.handleClickEmoji.bind(_this);
  41. _this.handleShowUpload = _this.handleShowUpload.bind(_this);
  42. return _this;
  43. }
  44. _createClass(Editor, [{
  45. key: "componentDidMount",
  46. value: function componentDidMount() {}
  47. }, {
  48. key: "handleClickEmoji",
  49. value: function handleClickEmoji(emojiId) {
  50. this.props.onChangeEmoji(emojiId);
  51. }
  52. }, {
  53. key: "handleShowUpload",
  54. value: function handleShowUpload(showUpload) {
  55. if (typeof showUpload === "boolean") {
  56. this.setState({ showUpload: showUpload });
  57. } else {
  58. this.setState({ showUpload: !this.state.showUpload });
  59. }
  60. }
  61. }, {
  62. key: "render",
  63. value: function render() {
  64. var _this2 = this;
  65. var _props = this.props,
  66. value = _props.value,
  67. onChange = _props.onChange,
  68. placeholder = _props.placeholder,
  69. fileList = _props.fileList,
  70. onChangeFileList = _props.onChangeFileList,
  71. onUpload = _props.onUpload;
  72. return _react2.default.createElement(
  73. "div",
  74. { className: "editor" },
  75. _react2.default.createElement(TextArea, {
  76. value: value,
  77. onChange: onChange,
  78. rows: 5,
  79. placeholder: placeholder
  80. }),
  81. _react2.default.createElement(
  82. "div",
  83. { className: "toolbar" },
  84. _react2.default.createElement(
  85. "div",
  86. { style: { float: "left", margin: "8px 11px" } },
  87. _react2.default.createElement(
  88. _popover2.default,
  89. {
  90. trigger: "click",
  91. placement: "bottomLeft",
  92. autoAdjustOverflow: false,
  93. content: _react2.default.createElement(
  94. "div",
  95. { style: { width: 200 } },
  96. _react2.default.createElement(_Emoji2.default, { onClick: this.handleClickEmoji })
  97. ),
  98. overlayClassName: "feed"
  99. },
  100. _react2.default.createElement(_icon2.default, { type: "smile-o", className: "icon" })
  101. ),
  102. _react2.default.createElement(
  103. _popover2.default,
  104. {
  105. visible: this.state.showUpload,
  106. overlayStyle: { zIndex: 999 },
  107. content: _react2.default.createElement(
  108. "div",
  109. { style: { width: 112 * _constant.MAX_UPLOAD_NUMBER, minHeight: 100 } },
  110. _react2.default.createElement(_Upload2.default, {
  111. onChangeFileList: onChangeFileList,
  112. onUpload: onUpload,
  113. fileList: fileList
  114. })
  115. ),
  116. placement: "bottomLeft",
  117. title: _react2.default.createElement(
  118. "div",
  119. { style: { margin: "5px auto" } },
  120. _react2.default.createElement(
  121. "span",
  122. null,
  123. "\u4E0A\u4F20\u56FE\u7247",
  124. _react2.default.createElement(
  125. "span",
  126. { style: { color: "#666", fontWeight: 400 } },
  127. "(\u60A8\u8FD8\u80FD\u4E0A\u4F20",
  128. _constant.MAX_UPLOAD_NUMBER - fileList.length,
  129. "\u5F20\u56FE\u7247)"
  130. )
  131. ),
  132. _react2.default.createElement(_icon2.default, {
  133. type: "close",
  134. onClick: function onClick() {
  135. return _this2.handleShowUpload(false);
  136. },
  137. style: {
  138. float: "right",
  139. cursor: "pointer",
  140. marginTop: 4
  141. }
  142. })
  143. )
  144. },
  145. _react2.default.createElement(_icon2.default, {
  146. type: "picture",
  147. className: "icon",
  148. style: { marginLeft: 10 },
  149. onClick: function onClick() {
  150. return _this2.handleShowUpload(true);
  151. }
  152. })
  153. )
  154. ),
  155. _react2.default.createElement(
  156. "div",
  157. { style: { float: "right", margin: "5px 11px" } },
  158. _react2.default.createElement(
  159. _button2.default,
  160. {
  161. onClick: this.props.onSubmit,
  162. type: "primary",
  163. loading: this.props.loading
  164. },
  165. "\u53D1\u8868"
  166. )
  167. )
  168. )
  169. );
  170. }
  171. }]);
  172. return Editor;
  173. }(_react2.default.Component);
  174. exports.default = Editor;
  175. //# sourceMappingURL=index.js.map