fastlion-amis
Version:
一种MIS页面生成工具
92 lines (91 loc) • 4.54 kB
JavaScript
/**
* @file Alert2
* @author fex
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Alert = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var theme_1 = require("../theme");
var icons_1 = require("./icons");
var Alert = /** @class */ (function (_super) {
(0, tslib_1.__extends)(Alert, _super);
function Alert(props) {
var _this = _super.call(this, props) || this;
_this.alertRef = react_1.default.createRef();
_this.handleClick = _this.handleClick.bind(_this);
// this.handleHideToday = this.handleHideToday.bind(this);
// this.handleJudgeHideToday = this.handleJudgeHideToday.bind(this);
_this.handleFoldContent = _this.handleFoldContent.bind(_this);
_this.setFoldAll = _this.setFoldAll.bind(_this);
_this.setShowFold = _this.setShowFold.bind(_this);
_this.state = { show: true, foldAll: false, showFold: false };
return _this;
// 判断今天是否显示
// this.handleJudgeHideToday();
}
Alert.prototype.handleClick = function () {
this.setState({
show: false
}, this.props.onClose);
};
Alert.prototype.getDefaultStorageItem = function () {
return {
timeStamp: new Date().getTime()
};
};
Alert.prototype.setFoldAll = function (foldAll) {
this.setState({ foldAll: foldAll });
};
Alert.prototype.setShowFold = function (showFold) {
this.setState({ showFold: showFold });
};
/** 执行折叠 */
Alert.prototype.handleFoldContent = function (e) {
e.stopPropagation();
this.setFoldAll(!this.state.foldAll);
};
Alert.prototype.componentDidMount = function () {
var _this = this;
// 延迟一下计算的时机 防止计算出错
setTimeout(function () {
requestAnimationFrame(function () {
var _a;
var realHigh = ((_a = _this.alertRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight) || 0;
_this.setShowFold(48 < realHigh);
});
}, 800);
};
Alert.prototype.render = function () {
var _a;
var _b = this.props, cx = _b.classnames, className = _b.className, level = _b.level, children = _b.children, showCloseButton = _b.showCloseButton, title = _b.title, icon = _b.icon, showIcon = _b.showIcon, iconClassName = _b.iconClassName, closeButtonClassName = _b.closeButtonClassName, todayAlter = _b.todayAlter;
var iconNode = icon ? (typeof icon === 'string' ? (react_1.default.createElement(icons_1.Icon, { icon: icon, className: cx("Alert-icon icon") })) : react_1.default.isValidElement(icon) ? (react_1.default.cloneElement(icon, {
className: cx("Alert-icon", (_a = icon.props) === null || _a === void 0 ? void 0 : _a.className)
})) : null) : showIcon ? (react_1.default.createElement(icons_1.Icon, { icon: "alert-" + level, className: cx("Alert-icon icon") })) : null;
return this.state.show ? (react_1.default.createElement("div", { ref: this.alertRef, className: cx('Alert', level ? "Alert--" + level : '', className) },
showIcon && iconNode ? (react_1.default.createElement("div", { className: cx('Alert-icon', iconClassName) }, iconNode)) : null,
react_1.default.createElement("div", { className: cx('Alert-content'), style: {
maxHeight: this.state.foldAll ? '32px' : 'unset'
} },
title ? react_1.default.createElement("div", { className: cx('Alert-title') }, title) : null,
react_1.default.createElement("div", { className: cx('Alert-desc') }, children)),
showCloseButton ? (react_1.default.createElement("button", { className: cx('Alert-close', closeButtonClassName), onClick: this.handleClick, type: "button" },
react_1.default.createElement(icons_1.Icon, { icon: "close", className: "icon" }))) : null)) : null;
};
Alert.defaultProps = {
level: 'info',
className: '',
showCloseButton: false
};
Alert.propsList = [
'level',
'className',
'showCloseButton',
'onClose'
];
return Alert;
}(react_1.default.Component));
exports.Alert = Alert;
exports.default = (0, theme_1.themeable)(Alert);
//# sourceMappingURL=./components/Alert2.js.map
;