UNPKG

@nex-ui/react

Version:

🎉 A beautiful, modern, and reliable React component library.

29 lines (26 loc) • 899 B
"use client"; import { isValidElement, cloneElement } from 'react'; import { useModal } from './ModalContext.mjs'; const ModalClose = ({ children })=>{ const { setOpen } = useModal(); if (!/*#__PURE__*/ isValidElement(children)) { return children; } const element = children; return /*#__PURE__*/ cloneElement(element, { 'aria-label': element.props['aria-label'] || 'Close', onClick: ()=>{ const { onClick } = element.props; if (onClick) { const result = onClick(); // Check if the result is a Promise if (result && result instanceof Promise && typeof result.then === 'function') { result.then(()=>setOpen(false)).catch(()=>{}); return; } } setOpen(false); } }); }; export { ModalClose };