@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
116 lines (115 loc) • 6.63 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import * as React from 'react';
import PropTypes from 'prop-types';
import { observable, action, computed } from 'mobx';
import { observer } from 'mobx-react';
import classnames from 'classnames';
import { EditOutlined, InfoCircleOutlined } from '@ant-design/icons';
import { Tooltip, Popover } from 'antd';
import Modal from 'antd-mobile/es/modal';
import DOMPurify from 'dompurify';
import { Button } from '../../../components/Common';
import BasicComponent from '../../../components/Base/BasicComponent';
import bind from '../../../utils/bind';
import errorBoundary from '../../../hocs/errorBoundary';
import { formatString } from '../../../services/language';
import { DashboardLocale } from '../../../constants/language/dashboard/type';
import ModalVisibleCtl from '../../../stores/ModalVisibleCtl';
import { isMobileDevice } from '../../../utils/env';
import InfoModal from './InfoModal';
import * as style from './style.mless';
import 'antd-mobile/lib/modal/style/css';
var Title = /** @class */ (function (_super) {
__extends(Title, _super);
function Title() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.modalCtl = new ModalVisibleCtl();
_this.editing = false;
return _this;
}
Title.prototype.setEditing = function (editing) {
this.editing = editing;
};
Object.defineProperty(Title.prototype, "descriptionHtml", {
get: function () {
return { __html: DOMPurify.sanitize(this.props.value.description || '') };
},
enumerable: false,
configurable: true
});
Title.prototype.render = function () {
var _this = this;
var _a;
var _b = this.props, className = _b.className, editable = _b.editable, value = _b.value, onChange = _b.onChange, themeService = _b.themeService;
var _c = value.title, title = _c === void 0 ? '' : _c, titleColor = value.titleColor, description = value.description;
var rootCls = classnames(style.root, className);
var replaceVariable = this.context.replaceVariable;
var titleText = replaceVariable ? replaceVariable(title) : title;
var _d = this.modalCtl, hideModal = _d.hideModal, showModal = _d.showModal, visible = _d.visible;
var infoIcon = description &&
(isMobileDevice() ? (React.createElement(InfoCircleOutlined, { onClick: showModal, className: style.icon })) : (React.createElement(Popover, { overlayClassName: style.descriptionContainter, content: React.createElement("div", { className: style.description, dangerouslySetInnerHTML: this.descriptionHtml }), title: null },
React.createElement(InfoCircleOutlined, { className: style.icon }))));
return (React.createElement("div", { className: rootCls, ref: this.setRootRef },
React.createElement("div", { className: style.icons },
infoIcon,
editable && (React.createElement(Tooltip, { title: formatString(DashboardLocale.edit.chart.title.title) },
React.createElement(EditOutlined, { className: style.icon, onClick: function () { return _this.setEditing(true); } })))),
React.createElement("div", { className: classnames(style.title, 'single-line'), style: {
color: titleColor || 'inhert'
} },
React.createElement(Tooltip, { title: titleText || formatString(DashboardLocale.edit.name_display) }, titleText || formatString(DashboardLocale.edit.name_display))),
React.createElement(Modal, { onClose: hideModal, visible: visible, closable: false, transparent: true, animationType: "slide-up", wrapClassName: style.descriptionModal },
React.createElement("div", { className: style.mobileDescription, dangerouslySetInnerHTML: this.descriptionHtml }),
React.createElement("div", { className: style.footer },
React.createElement("div", { className: style.modalButtonContainter },
React.createElement(Button, { onClick: hideModal, className: style.modalButton }, formatString(DashboardLocale.edit.description_button))))),
this.editing && (React.createElement(InfoModal, { onClose: function () { return _this.setEditing(false); }, value: value, onChange: onChange, themeService: themeService || ((_a = this.context.chartContainerService) === null || _a === void 0 ? void 0 : _a.themeService) }))));
};
Title.contextTypes = {
replaceVariable: PropTypes.func,
chartContainerService: PropTypes.object
};
__decorate([
observable,
__metadata("design:type", Object)
], Title.prototype, "editing", void 0);
__decorate([
bind,
action,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Boolean]),
__metadata("design:returntype", void 0)
], Title.prototype, "setEditing", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Title.prototype, "descriptionHtml", null);
Title = __decorate([
observer
], Title);
return Title;
}(BasicComponent));
export { Title };
export default errorBoundary(Title);