UNPKG

stofli-ui

Version:

Biblioteca moderna de componentes UI para React con Tailwind CSS y Framer Motion

4 lines (3 loc) 6.76 kB
'use client'; "use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("lucide-react"),o=require("framer-motion"),n=require("clsx"),a=require("tailwind-merge"),i=function(){return i=Object.assign||function(e){for(var r,t=1,o=arguments.length;t<o;t++)for(var n in r=arguments[t])Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n]);return e},i.apply(this,arguments)};function s(e,r,t){if(t||2===arguments.length)for(var o,n=0,a=r.length;n<a;n++)!o&&n in r||(o||(o=Array.prototype.slice.call(r,0,n)),o[n]=r[n]);return e.concat(o||Array.prototype.slice.call(r))}function d(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return a.twMerge(n.clsx(e))}"function"==typeof SuppressedError&&SuppressedError;var c=function(n){var a=n.open,i=n.defaultOpen,s=void 0!==i&&i,c=n.onOpenChange,u=n.title,l=n.description,m=n.variant,f=void 0===m?"default":m,v=n.position,b=void 0===v?"bottom-right":v,p=n.duration,h=void 0===p?5e3:p,g=n.showCloseButton,x=void 0===g||g,k=n.className,w=void 0===k?"":k,y=n.children,N=n.icon,E=n.containerClassName,j=void 0===E?"":E,C=n.toastClassName,I=void 0===C?"":C,T=n.titleClassName,z=void 0===T?"":T,L=n.descriptionClassName,O=void 0===L?"":L,P=n.iconContainerClassName,S=void 0===P?"":P,q=n.contentClassName,A=void 0===q?"":q,B=n.closeButtonClassName,F=void 0===B?"":B,V=n.role,Y=void 0===V?"status":V,_=n.important,D=void 0!==_&&_,H=r.useState(s),K=H[0],M=H[1],R=r.useState(!1),W=R[0],X=R[1],G=r.useRef(null),J=r.useCallback((function(){M(!1),null==c||c(!1)}),[c]);r.useEffect((function(){void 0!==a&&M(a)}),[a]),r.useEffect((function(){return X(!0),function(){return X(!1)}}),[]),r.useEffect((function(){if(K&&h!==Number.POSITIVE_INFINITY){var e,r=function(){e=setTimeout((function(){J()}),h)};r();var t=function(){return clearTimeout(e)},o=function(){return r()},n=function(){return clearTimeout(e)},a=function(){return r()},i=G.current;return i&&(i.addEventListener("focus",t,!0),i.addEventListener("blur",o,!0),i.addEventListener("mouseenter",n),i.addEventListener("mouseleave",a)),function(){clearTimeout(e),i&&(i.removeEventListener("focus",t,!0),i.removeEventListener("blur",o,!0),i.removeEventListener("mouseenter",n),i.removeEventListener("mouseleave",a))}}}),[K,h,J]);var Q,U=r.useCallback((function(e){"Escape"===e.key&&J()}),[J]),Z={hidden:{opacity:0,y:b.includes("top")?-20:20,scale:.9},visible:{opacity:1,y:0,scale:1,transition:{duration:.3,ease:"easeOut"}},exit:{opacity:0,y:b.includes("top")?-20:20,scale:.9,transition:{duration:.2,ease:"easeIn"}}};return W?e.jsx(o.AnimatePresence,{children:K&&e.jsx(o.motion.div,{className:j||d("max-w-sm",w),initial:"hidden",animate:"visible",exit:"exit",variants:Z,ref:G,tabIndex:0,role:Y,"aria-atomic":"true","aria-live":D?"assertive":"polite","aria-label":(Q=u||"","".concat({default:"",primary:"Información: ",secondary:"Nota: ",success:"Éxito: ",warning:"Advertencia: ",danger:"Error: "}[f]).concat(Q)),onKeyDown:U,children:e.jsx("div",{className:d("rounded-lg border px-4 py-3 shadow-lg",I?"":{default:"bg-gradient-to-r from-zinc-200 to-zinc-300 dark:from-zinc-800/90 dark:to-zinc-700/90 text-neutral-800 dark:text-neutral-100 border border-zinc-300 dark:border-zinc-700/50 backdrop-blur-sm shadow-sm",primary:"bg-gradient-to-r from-blue-400 to-blue-500 dark:from-blue-800/90 dark:to-blue-700/90 text-white dark:text-blue-50 border border-blue-400 dark:border-blue-700/50 backdrop-blur-sm shadow-sm",secondary:"bg-gradient-to-r from-purple-400 to-purple-500 dark:from-purple-800/90 dark:to-purple-700/90 text-white dark:text-purple-50 border border-purple-400 dark:border-purple-700/50 backdrop-blur-sm shadow-sm",success:"bg-gradient-to-r from-green-400 to-green-500 dark:from-green-800/90 dark:to-green-700/90 text-white dark:text-green-50 border border-green-400 dark:border-green-700/50 backdrop-blur-sm shadow-sm",warning:"bg-gradient-to-r from-amber-400 to-amber-500 dark:from-amber-800/90 dark:to-amber-700/90 text-white dark:text-amber-50 border border-amber-400 dark:border-amber-700/50 backdrop-blur-sm shadow-sm",danger:"bg-gradient-to-r from-red-400 to-red-500 dark:from-red-800/90 dark:to-red-700/90 text-white dark:text-red-50 border border-red-400 dark:border-red-700/50 backdrop-blur-sm shadow-sm"}[f],I),children:e.jsxs("div",{className:d("flex items-start gap-3"),children:[N&&e.jsx("div",{className:d("shrink-0 mt-0.5",S),"aria-hidden":"true",children:N}),e.jsxs("div",{className:d("flex-1 mr-2",A),children:[u&&e.jsx("h4",{className:d("font-medium mb-1",z),children:u}),l&&e.jsx("p",{className:d("text-sm opacity-90",O),children:l}),y]}),x&&e.jsx("button",{onClick:J,className:d("shrink-0 opacity-70 hover:opacity-100 transition-opacity p-1 rounded-full","hover:bg-white/20","focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-white","dark:focus-visible:ring-offset-zinc-900 focus-visible:ring-zinc-500","dark:focus-visible:ring-zinc-400 outline-none",F),"aria-label":"Cerrar",children:e.jsx(t.X,{className:"h-4 w-4"})})]})})})}):null},u=r.createContext(void 0);exports.Toast=c,exports.ToastProvider=function(t){var o=t.children,n=t.containerClassName,a=r.useState([]),l=a[0],m=a[1],f=r.useId(),v=function(e){m(e?function(r){return r.filter((function(r){return r.id!==e}))}:[])},b={};l.forEach((function(e){var r=e.position||"bottom-right";b[r]||(b[r]=[]),b[r].push(e)}));var p={"top-left":"top-4 left-4","top-right":"top-4 right-4","bottom-left":"bottom-4 left-4","bottom-right":"bottom-4 right-4","top-center":"top-4 left-1/2 -translate-x-1/2","bottom-center":"bottom-4 left-1/2 -translate-x-1/2"};return r.useEffect((function(){var e=function(e){if("Escape"===e.key&&l.length>0){var r=l[l.length-1].id;v(r)}};return document.addEventListener("keydown",e),function(){return document.removeEventListener("keydown",e)}}),[l]),e.jsxs(u.Provider,{value:{open:function(e){var r="toast-".concat(f,"-").concat(l.length),t=e.role||"status";if(e.role||"danger"!==e.variant&&"warning"!==e.variant||(t="alert"),m((function(o){return s(s([],o,!0),[i(i({},e),{id:r,open:!0,role:t})],!1)})),e.duration!==Number.POSITIVE_INFINITY){var o=e.duration||5e3;setTimeout((function(){v(r)}),o)}},close:v},children:[o,Object.entries(b).map((function(r){var t=r[0],o=r[1],a=t.startsWith("bottom")?s([],o,!0).reverse():o;return e.jsx("div",{className:d("fixed z-50 flex flex-col gap-2",p[t],n),style:{maxHeight:"100vh",overflow:"hidden"},children:a.map((function(r,t){return e.jsx("div",{className:"relative",style:{zIndex:a.length-t},children:e.jsx(c,i({},r,{onOpenChange:function(){return v(r.id)},className:"shadow-lg"}))},r.id)}))},t)}))]})},exports.useToast=function(){var e=r.useContext(u);if(void 0===e)throw new Error("useToast debe usarse dentro de un ToastProvider");return e}; //# sourceMappingURL=index.js.map