infinity-forge
Version:
103 lines • 4.73 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToastItem = ToastItem;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var ui_1 = require("../../../../ui/index.js");
var S = __importStar(require("./styles.js"));
function ToastItem(props) {
var status = props.status;
var animationDuration = props.duration || 5000;
var _a = (0, react_1.useState)(100), progressWidth = _a[0], setProgressWidth = _a[1];
var statusColors = {
success: '#07bc0c',
error: '#e74c3c',
info: '#3498db',
warning: '#f1c40f',
};
function closeToast() {
props.setToast(function (s) { return s === null || s === void 0 ? void 0 : s.filter(function (st) { return st.uid !== props.uid; }); });
}
(0, react_1.useEffect)(function () {
var startTime;
var animate = function (timestamp) {
if (!startTime) {
startTime = timestamp;
}
var elapsed = timestamp - startTime;
var progress = Math.min(1, elapsed / animationDuration);
setProgressWidth(100 - progress * 100);
if (1 > progress) {
requestAnimationFrame(animate);
}
else {
closeToast();
}
};
var animation = requestAnimationFrame(animate);
return function () { return cancelAnimationFrame(animation); };
}, [animationDuration]);
function iconToast() {
switch (status) {
case 'success':
return (0, jsx_runtime_1.jsx)(ui_1.Icon, { name: 'CheckListIcon', color: statusColors.success });
case 'error':
return (0, jsx_runtime_1.jsx)(ui_1.Icon, { name: 'IconBlock', color: statusColors.error });
case 'info':
return (0, jsx_runtime_1.jsx)(ui_1.Icon, { name: 'IconInfo', color: statusColors.info });
case 'warning':
return (0, jsx_runtime_1.jsx)(ui_1.Icon, { name: 'IconWarning', color: statusColors.warning });
default:
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
}
}
return ((0, jsx_runtime_1.jsxs)(S.ToastItem, { children: [(0, jsx_runtime_1.jsxs)("div", { className: 'toast-content', children: [iconToast(), (props === null || props === void 0 ? void 0 : props.Component) ? ((0, jsx_runtime_1.jsx)(props.Component, __assign({}, props, { closeToast: closeToast, progressWidth: progressWidth }))) : ((0, jsx_runtime_1.jsx)("span", { children: props === null || props === void 0 ? void 0 : props.message }))] }), (0, jsx_runtime_1.jsx)("div", { className: 'progressbar_container', children: (0, jsx_runtime_1.jsx)("div", { className: 'progressbar', style: {
width: "".concat(progressWidth, "%"),
backgroundColor: statusColors[status],
} }) })] }));
}
//# sourceMappingURL=index.js.map