lole-ui
Version:
React UI Component which like a love letter
83 lines (82 loc) • 4.08 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React from "react";
import classNames from "classnames";
import Icon from "../Icon/icon";
import Animator from "../Animator/animator";
var Alert = function (props) {
var _a;
var className = props.className, message = props.message, description = props.description, action = props.action, type = props.type, closeable = props.closeable, closeText = props.closeText, closeIcon = props.closeIcon, showIcon = props.showIcon, icon = props.icon, width = props.width, bordered = props.bordered, restProps = __rest(props, ["className", "message", "description", "action", "type", "closeable", "closeText", "closeIcon", "showIcon", "icon", "width", "bordered"]);
var _b = React.useState(false), closed = _b[0], setClosed = _b[1];
var isClosable = closeText ? true : closeable;
var handleClose = function (e) {
e.preventDefault();
setClosed(true);
//props.onClose?.(e);
};
var classes = classNames('alert', className, (_a = {},
_a["alert-".concat(type)] = type,
_a["alert-".concat(bordered)] = bordered,
_a));
/** 由Animator组件控制 */
var showStyle = function () {
return closed ? { display: 'none' } : {};
};
var renderIconNode = function () {
var icon = props.icon;
/** 判断iconType用于渲染实心还是空心icon */
if (icon)
return icon;
else
return React.createElement("span", { className: "alert-icon" },
React.createElement(Icon, { icon: 'info' }));
/*if (icon){
return replaceElement(icon, <span className={`alert-icon`} ><Icon icon='info'/></span>,()=>({
className: classNames(`alert-icon`,{}),
}));
}*/
};
var renderCloseIcon = function () {
return isClosable ? (React.createElement("button", { type: 'button', onClick: handleClose, className: 'alert-close-icon' }, closeText ? React.createElement("span", { className: 'alert-close-text' }, closeText) : closeIcon)) : null;
};
return (React.createElement(React.Fragment, null,
React.createElement("div", { style: { width: width } },
React.createElement(Animator, { in: !closed, timeout: 300, animation: 'zoom-in-left' },
React.createElement("div", __assign({ className: classes }, restProps),
showIcon ? renderIconNode() : null,
React.createElement("div", { className: 'alert-container' },
message ? React.createElement("div", { className: 'alert-message' }, message) : null,
description ? React.createElement("div", { className: 'alert-description' }, description) : null,
action ? React.createElement("div", { className: 'alert-action' }, action) : null),
renderCloseIcon())))));
};
Alert.defaultProps = {
type: 'info',
message: 'Please Input Message.',
closeable: false,
width: '50%',
bordered: 'default',
showIcon: false,
closeIcon: React.createElement(Icon, { icon: 'close' }),
};
export default Alert;