lightswind
Version:
A collection of beautifully crafted React Components, Blocks & Templates for Modern Developers. Create stunning web applications effortlessly by using our 160+ professional and animated react components.
149 lines • 8.27 kB
JavaScript
;
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.DialogClose = exports.DialogFooter = exports.DialogDescription = exports.DialogTitle = exports.DialogHeader = exports.DialogContent = exports.DialogTrigger = exports.Dialog = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const React = __importStar(require("react"));
const ReactDOM = __importStar(require("react-dom"));
const utils_1 = require("@/components/lib/utils"); // Assuming a utility for classnames
const lucide_react_1 = require("lucide-react");
const framer_motion_1 = require("framer-motion");
// Helper for cn if not provided
const dummyCn = (...inputs) => {
return inputs.filter(Boolean).join(' ');
};
const cnFunction = typeof utils_1.cn !== 'undefined' ? utils_1.cn : dummyCn;
const DialogContext = React.createContext(undefined);
const Dialog = ({ children, defaultOpen = false, open: controlledOpen, onOpenChange, }) => {
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
const isControlled = controlledOpen !== undefined;
const open = isControlled ? controlledOpen : uncontrolledOpen;
const setOpen = React.useCallback((value) => {
if (!isControlled) {
setUncontrolledOpen(value);
}
if (onOpenChange) {
const newValue = typeof value === "function" ? value(open) : value;
onOpenChange(newValue);
}
}, [isControlled, onOpenChange, open]);
return ((0, jsx_runtime_1.jsx)(DialogContext.Provider, { value: { open, setOpen }, children: children }));
};
exports.Dialog = Dialog;
const DialogTrigger = React.forwardRef(({ children, asChild = false, ...props }, ref) => {
const context = React.useContext(DialogContext);
if (!context) {
throw new Error("DialogTrigger must be used within a Dialog");
}
const { setOpen } = context;
const handleClick = (e) => {
e.preventDefault();
setOpen(true);
if (props.onClick) {
props.onClick(e);
}
};
const { onClick, ...otherProps } = props;
if (asChild) {
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, onClick: handleClick, ...otherProps, children: React.Children.map(children, child => {
if (React.isValidElement(child)) {
const element = child;
return React.cloneElement(element, {
...element.props
});
}
return child;
}) }));
}
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, onClick: handleClick, ...otherProps, children: children }));
});
exports.DialogTrigger = DialogTrigger;
DialogTrigger.displayName = "DialogTrigger";
const DialogContent = React.forwardRef(({ className, children, hideCloseButton, ...props }, ref) => {
const context = React.useContext(DialogContext);
if (!context) {
throw new Error("DialogContent must be used within a Dialog");
}
const { open, setOpen } = context;
const [mounted, setMounted] = React.useState(false);
React.useEffect(() => {
setMounted(true);
}, []);
React.useEffect(() => {
if (open) {
document.body.style.overflow = "hidden";
}
else {
document.body.style.overflow = "";
}
return () => {
document.body.style.overflow = "";
};
}, [open]);
if (!mounted)
return null;
return ReactDOM.createPortal((0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { children: open && ((0, jsx_runtime_1.jsxs)("div", { className: "fixed inset-0 z-[9999] flex items-center justify-center p-4", children: [(0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.2 }, className: "absolute inset-0 bg-background/80 backdrop-blur-sm", onClick: () => setOpen(false) }), (0, jsx_runtime_1.jsxs)(framer_motion_1.motion.div, { ref: ref, initial: { opacity: 0, scale: 0.3 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.3 }, transition: {
type: "spring",
damping: 25,
stiffness: 400,
opacity: { duration: 0.2 }
}, className: cnFunction(`relative z-[9999] w-full max-w-lg rounded-2xl border
bg-background p-6 shadow-lg max-h-[90vh] overflow-y-auto`, className), role: "dialog", "aria-modal": "true", "data-lenis-prevent": true, ...props, children: [children, !hideCloseButton && ((0, jsx_runtime_1.jsxs)("button", { onClick: () => setOpen(false), className: "absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none", "aria-label": "Close dialog", children: [(0, jsx_runtime_1.jsx)(lucide_react_1.X, { className: "h-4 w-4" }), (0, jsx_runtime_1.jsx)("span", { className: "sr-only", children: "Close" })] }))] })] })) }), document.body);
});
exports.DialogContent = DialogContent;
DialogContent.displayName = "DialogContent";
const DialogHeader = React.forwardRef(({ className, ...props }, ref) => ((0, jsx_runtime_1.jsx)("div", { ref: ref, className: cnFunction("flex flex-col space-y-1.5 text-center sm:text-left", className), ...props })));
exports.DialogHeader = DialogHeader;
DialogHeader.displayName = "DialogHeader";
const DialogTitle = React.forwardRef(({ className, ...props }, ref) => ((0, jsx_runtime_1.jsx)("h2", { ref: ref, className: cnFunction("text-lg font-semibold leading-none tracking-tight", className), ...props })));
exports.DialogTitle = DialogTitle;
DialogTitle.displayName = "DialogTitle";
const DialogDescription = React.forwardRef(({ className, ...props }, ref) => ((0, jsx_runtime_1.jsx)("p", { ref: ref, className: cnFunction("text-sm text-muted-foreground", className), ...props })));
exports.DialogDescription = DialogDescription;
DialogDescription.displayName = "DialogDescription";
const DialogFooter = React.forwardRef(({ className, ...props }, ref) => ((0, jsx_runtime_1.jsx)("div", { ref: ref, className: cnFunction("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className), ...props })));
exports.DialogFooter = DialogFooter;
DialogFooter.displayName = "DialogFooter";
const DialogClose = React.forwardRef(({ className, ...props }, ref) => {
const context = React.useContext(DialogContext);
const setOpen = context ? context.setOpen : () => { };
return ((0, jsx_runtime_1.jsx)("button", { ref: ref, type: "button", className: className, onClick: (e) => {
setOpen(false);
props.onClick?.(e);
}, ...props }));
});
exports.DialogClose = DialogClose;
DialogClose.displayName = "DialogClose";
//# sourceMappingURL=dialog.js.map