analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
101 lines (96 loc) • 4.03 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});
var _chunkTN3AYOMVjs = require('./chunk-TN3AYOMV.js');
// src/components/Toast/Toast.tsx
var _react = require('react');
var _CheckCircle = require('@phosphor-icons/react/dist/csr/CheckCircle');
var _WarningCircle = require('@phosphor-icons/react/dist/csr/WarningCircle');
var _Info = require('@phosphor-icons/react/dist/csr/Info');
var _X = require('@phosphor-icons/react/dist/csr/X');
var _jsxruntime = require('react/jsx-runtime');
var DEFAULT_TOAST_DURATION_MS = 3e3;
var VARIANT_ACTION_CLASSES = {
solid: {
warning: "bg-warning text-warning-600 border-none focus-visible:outline-none",
success: "bg-success text-success-800 border-none focus-visible:outline-none",
info: "bg-info text-info-600 border-none focus-visible:outline-none"
},
outlined: {
warning: "bg-warning text-warning-600 border border-warning-300 focus-visible:outline-none",
success: "bg-success text-success-800 border border-success-200 focus-visible:outline-none",
info: "bg-info text-info-600 border border-info-600 focus-visible:outline-none"
}
};
var iconMap = {
success: _CheckCircle.CheckCircleIcon,
info: _Info.InfoIcon,
warning: _WarningCircle.WarningCircleIcon
};
var Toast = ({
variant = "outlined",
action = "success",
className = "",
onClose,
title,
description,
position = "default",
duration = DEFAULT_TOAST_DURATION_MS,
...props
}) => {
const onCloseRef = _react.useRef.call(void 0, onClose);
_react.useEffect.call(void 0, () => {
onCloseRef.current = onClose;
}, [onClose]);
_react.useEffect.call(void 0, () => {
if (duration <= 0) return;
const timer = setTimeout(() => onCloseRef.current(), duration);
return () => clearTimeout(timer);
}, [duration]);
const variantClasses = VARIANT_ACTION_CLASSES[variant][action];
const positionClasses = {
"top-left": "fixed top-4 left-4",
"top-center": "fixed top-4 left-1/2 transform -translate-x-1/2",
"top-right": "fixed top-4 right-4",
"bottom-left": "fixed bottom-4 left-4",
"bottom-center": "fixed bottom-4 left-1/2 transform -translate-x-1/2",
"bottom-right": "fixed bottom-4 right-4",
default: ""
};
const IconAction = iconMap[action] || iconMap["success"];
const baseClasses = "max-w-[390px] w-full flex flex-row items-start justify-between shadow-lg rounded-lg border p-4 gap-6 group z-50";
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
"div",
{
role: "alert",
"aria-live": "assertive",
"aria-atomic": "true",
className: _chunkTN3AYOMVjs.cn.call(void 0,
baseClasses,
positionClasses[position],
variantClasses,
className
),
...props,
children: [
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-row items-start gap-3", children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "mt-1", "data-testid": `toast-icon-${action}`, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, IconAction, {}) }),
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col items-start justify-start", children: [
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "font-semibold text-md", children: title }),
description && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "text-md text-text-900", children: description })
] })
] }),
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
"button",
{
onClick: onClose,
"aria-label": "Dismiss notification",
className: "text-background-500 cursor-pointer opacity-0 group-hover:opacity-100 transition-opacity",
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _X.XIcon, {})
}
)
]
}
);
};
var Toast_default = Toast;
exports.Toast_default = Toast_default;
//# sourceMappingURL=chunk-QOF47WYZ.js.map