UNPKG

rax-tbms-chat-plugin

Version:

tbms-chat-plugin with rax

220 lines (183 loc) 8.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _raxTbmsChatBase = require("rax-tbms-chat-base"); var _raxView = _interopRequireDefault(require("rax-view")); var _raxText = _interopRequireDefault(require("rax-text")); var _raxTextinput = _interopRequireDefault(require("rax-textinput")); var _raxImage = _interopRequireDefault(require("rax-image")); var _icon = _interopRequireDefault(require("./icon")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var MY_FREE_STYLES = { containerHeight: 100, containerInputHeight: 72, inputPadding: 5, iconMargin: 20, pluginIconAddMargin: 30, pluginButtonMarginRight: -10, pluginButtonAddWidth: 30 }; var _default = /*#__PURE__*/ function (_BaseComponent) { _inherits(_default, _BaseComponent); _createClass(_default, [{ key: "handleChangeText", value: function handleChangeText(value) { this.props.onChange && this.props.onChange(value); } }, { key: "handleSubmitText", value: function handleSubmitText(event, value) { event.target.value = ''; this.props.onSubmit && this.props.onSubmit(value); } }]); function _default(props) { var _this; _classCallCheck(this, _default); _this = _possibleConstructorReturn(this, _getPrototypeOf(_default).call(this, props)); _defineProperty(_assertThisInitialized(_this), "styles", { container: { height: 100, paddingLeft: _raxTbmsChatBase.systemStyles.containerPadding, paddingRight: _raxTbmsChatBase.systemStyles.containerPadding, width: 750, flexDirection: 'row', alignItems: 'center', backgroundColor: _raxTbmsChatBase.systemStyles.containerFooterBackgroundColor }, containerInput: { height: MY_FREE_STYLES.containerInputHeight, lineHeight: MY_FREE_STYLES.containerInputHeight - MY_FREE_STYLES.inputPadding * 2, flex: 1, borderRadius: _raxTbmsChatBase.customStyles.border.mainBorderRadius === 0 ? 0 : MY_FREE_STYLES.containerInputHeight / 2, paddingTop: MY_FREE_STYLES.inputPadding, paddingLeft: MY_FREE_STYLES.iconMargin, paddingRight: MY_FREE_STYLES.iconMargin * 4, fontSize: _raxTbmsChatBase.customStyles.font.mainFontSize, color: _raxTbmsChatBase.systemStyles.itemMainFontColor, textAlign: 'left', backgroundColor: '#FFF' }, pluginItem: { height: _raxTbmsChatBase.systemStyles.pluginRectangle, lineHeight: _raxTbmsChatBase.systemStyles.pluginRectangle, width: _raxTbmsChatBase.systemStyles.pluginRectangle, fontSize: _raxTbmsChatBase.systemStyles.pluginRectangle, marginLeft: MY_FREE_STYLES.iconMargin, color: _raxTbmsChatBase.customStyles.font.mainFontColor }, pluginButton: { color: _raxTbmsChatBase.customStyles.font.systemFontColor, textAlign: 'center', fontSize: _raxTbmsChatBase.systemStyles.mainButtonFontSize, width: _raxTbmsChatBase.systemStyles.pluginRectangle + MY_FREE_STYLES.pluginButtonAddWidth, marginRight: MY_FREE_STYLES.pluginButtonMarginRight, backgroundImage: _raxTbmsChatBase.customStyles.color.linearGradientColor }, pluginEmojiItem: { display: 'block', position: 'absolute', right: _raxTbmsChatBase.systemStyles.containerPadding + _raxTbmsChatBase.systemStyles.pluginRectangle + MY_FREE_STYLES.pluginIconAddMargin, width: _raxTbmsChatBase.systemStyles.pluginRectangle }, pluginMoreItem: { marginRight: 0 } }); _defineProperty(_assertThisInitialized(_this), "handlePluginChange", function (type) { _this.props.onPluginChange && _this.props.onPluginChange(type); }); _defineProperty(_assertThisInitialized(_this), "handleKeyUp", function (event) { var value = event.target.value; if (event.keyCode === 13 && value) { _this.handleSubmitText(event, value); } }); _defineProperty(_assertThisInitialized(_this), "handleBlur", function (event) { var value = event.target.value; if (value) { _this.handleChangeText(value); } }); if (!props.showPlugin) { _this.styles.pluginEmojiItem.right += MY_FREE_STYLES.iconMargin; } _this.state = {}; return _this; } _createClass(_default, [{ key: "renderEmojiPlugin", value: function renderEmojiPlugin() { var styles = this.styles; return (0, _raxTbmsChatBase.createElement)(_raxImage.default, { source: { uri: _icon.default.EMOJI_ICON }, style: [styles.pluginItem, styles.pluginEmojiItem], resizeMode: "cover", onClick: this.handlePluginChange.bind(this, 'emoji') }); } }, { key: "renderAddPlugin", value: function renderAddPlugin() { var styles = this.styles; return (0, _raxTbmsChatBase.createElement)(_raxImage.default, { source: { uri: _icon.default.MORE_ICON }, style: [styles.pluginItem, styles.pluginMoreItem], resizeMode: "cover", onClick: this.handlePluginChange.bind(this, 'add') }); } }, { key: "renderSendButton", value: function renderSendButton() { var _this2 = this; var styles = this.styles; return (0, _raxTbmsChatBase.createElement)(_raxText.default, { style: [styles.pluginItem, styles.pluginButton], onClick: function onClick(event) { _this2.handleSubmitText(event); } }, "\u53D1\u9001"); } }, { key: "render", value: function render() { var styles = this.styles; return (0, _raxTbmsChatBase.createElement)(_raxView.default, { style: styles.container }, (0, _raxTbmsChatBase.createElement)(_raxTextinput.default, { autoFocus: true, onFocus: this.props.onFocus, defaultValue: this.props.text, style: styles.containerInput, onKeyup: this.handleKeyUp, onBlur: this.handleBlur }), this.renderEmojiPlugin(), this.props.showPlugin ? this.renderAddPlugin() : this.renderSendButton()); } }]); return _default; }(_raxTbmsChatBase.BaseComponent); exports.default = _default; _defineProperty(_default, "defaultProps", { onPluginChange: function onPluginChange() {}, onFocus: function onFocus() {}, showPlugin: false });