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.
213 lines • 11.4 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.AlertDialogCancel = exports.AlertDialogAction = exports.AlertDialogDescription = exports.AlertDialogTitle = exports.AlertDialogFooter = exports.AlertDialogHeader = exports.AlertDialogContent = exports.AlertDialogTrigger = exports.AlertDialogOverlay = exports.AlertDialogPortal = exports.AlertDialog = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const React = __importStar(require("react"));
const utils_1 = require("@/components/lib/utils");
const button_1 = require("./button");
const framer_motion_1 = require("framer-motion"); // Import motion and AnimatePresence
const AlertDialogContext = React.createContext(undefined);
const AlertDialog = ({ 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)(AlertDialogContext.Provider, { value: { open, setOpen }, children: children }));
};
exports.AlertDialog = AlertDialog;
const AlertDialogTrigger = React.forwardRef(({ children, asChild = false, ...props }, ref) => {
const context = React.useContext(AlertDialogContext);
if (!context) {
throw new Error("AlertDialogTrigger must be used within an AlertDialog");
}
const { setOpen } = context;
const handleClick = (e) => {
setOpen(true);
// Call the original onClick if it exists
if (props.onClick) {
props.onClick(e);
}
};
// Remove onClick from props to avoid duplicate handlers
const { onClick, ...otherProps } = props;
if (asChild) {
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: React.Children.map(children, child => {
if (React.isValidElement(child)) {
const element = child;
return React.cloneElement(element, {
...element.props,
ref,
onClick: handleClick
});
}
return child;
}) }));
}
return ((0, jsx_runtime_1.jsx)("button", { ref: ref, type: "button", onClick: handleClick, ...otherProps, children: children }));
});
exports.AlertDialogTrigger = AlertDialogTrigger;
AlertDialogTrigger.displayName = "AlertDialogTrigger";
const AlertDialogPortal = ({ children }) => {
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children });
};
exports.AlertDialogPortal = AlertDialogPortal;
const AlertDialogOverlay = React.forwardRef(({ className, ...props }, ref) => {
const context = React.useContext(AlertDialogContext);
if (!context) {
throw new Error("AlertDialogOverlay must be used within an AlertDialog");
}
const { open } = context;
// It's less likely for AlertDialogOverlay to have conflicting props,
// but if the error points here, apply the same filtering.
// For now, we'll assume the primary issue is in AlertDialogContent.
return ((0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { children: open && ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { ref: ref, initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, transition: { duration: 0.2 }, className: (0, utils_1.cn)("fixed inset-0 z-50 bg-background/80 backdrop-blur-sm", className), ...Object.keys(props).reduce((acc, key) => {
if (key === 'onDrag' || key === 'onAnimationStart' || key === 'onTransitionEnd') {
return acc;
}
acc[key] = props[key];
return acc;
}, {}) })) }));
});
exports.AlertDialogOverlay = AlertDialogOverlay;
AlertDialogOverlay.displayName = "AlertDialogOverlay";
const AlertDialogContent = React.forwardRef(({ className, children, ...props }, ref) => {
const context = React.useContext(AlertDialogContext);
if (!context) {
throw new Error("AlertDialogContent must be used within an AlertDialog");
}
const { open, setOpen } = context;
// Add click outside functionality
const contentRef = React.useRef(null);
React.useEffect(() => {
if (!open)
return;
const handleClickOutside = (event) => {
if (contentRef.current && !contentRef.current.contains(event.target)) {
setOpen(false);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () => {
document.removeEventListener("mousedown", handleClickOutside);
};
}, [open, setOpen]);
// Use AnimatePresence and motion.div for animation
return ((0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { children: open && ((0, jsx_runtime_1.jsxs)(AlertDialogPortal, { children: [(0, jsx_runtime_1.jsx)(AlertDialogOverlay, {}), (0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { ref: (node) => {
// Standard ref handling
if (typeof ref === "function") {
ref(node);
}
else if (ref) {
ref.current = node;
}
// Content ref for click outside
contentRef.current = node;
}, className: (0, utils_1.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg sm:rounded-lg", className), initial: { opacity: 0, scale: 0.3, x: "-50%", y: "-50%" }, animate: { opacity: 1, scale: 1, x: "-50%", y: "-50%" }, exit: { opacity: 0, scale: 0.3, x: "-50%", y: "-50%" }, transition: {
type: "spring",
damping: 25,
stiffness: 400,
opacity: { duration: 0.2 }
}, ...Object.keys(props).reduce((acc, key) => {
// Add any other conflicting HTML attributes you might discover here.
// 'onDrag' is the most common one.
if (key === 'onDrag' || key === 'onAnimationStart' || key === 'onTransitionEnd') {
return acc; // Omit this property
}
acc[key] = props[key]; // Keep other properties
return acc;
}, {}), children: children })] })) }));
});
exports.AlertDialogContent = AlertDialogContent;
AlertDialogContent.displayName = "AlertDialogContent";
const AlertDialogHeader = ({ className, ...props }) => ((0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)("flex flex-col space-y-2 text-center sm:text-left", className), ...props }));
exports.AlertDialogHeader = AlertDialogHeader;
AlertDialogHeader.displayName = "AlertDialogHeader";
const AlertDialogFooter = ({ className, ...props }) => ((0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className), ...props }));
exports.AlertDialogFooter = AlertDialogFooter;
AlertDialogFooter.displayName = "AlertDialogFooter";
const AlertDialogTitle = React.forwardRef(({ className, ...props }, ref) => ((0, jsx_runtime_1.jsx)("h2", { ref: ref, className: (0, utils_1.cn)("text-lg font-semibold", className), ...props })));
exports.AlertDialogTitle = AlertDialogTitle;
AlertDialogTitle.displayName = "AlertDialogTitle";
const AlertDialogDescription = React.forwardRef(({ className, ...props }, ref) => ((0, jsx_runtime_1.jsx)("p", { ref: ref, className: (0, utils_1.cn)("text-sm text-muted-foreground", className), ...props })));
exports.AlertDialogDescription = AlertDialogDescription;
AlertDialogDescription.displayName = "AlertDialogDescription";
const AlertDialogAction = React.forwardRef(({ className, ...props }, ref) => {
const context = React.useContext(AlertDialogContext);
if (!context) {
throw new Error("AlertDialogAction must be used within an AlertDialog");
}
const { setOpen } = context;
const handleClick = (e) => {
setOpen(false);
// Call the original onClick if it exists
if (props.onClick) {
props.onClick(e);
}
};
// Remove onClick from props to avoid duplicate handlers
const { onClick, ...otherProps } = props;
return ((0, jsx_runtime_1.jsx)("button", { ref: ref, className: (0, utils_1.cn)((0, button_1.buttonVariants)(), className), onClick: handleClick, ...otherProps }));
});
exports.AlertDialogAction = AlertDialogAction;
AlertDialogAction.displayName = "AlertDialogAction";
const AlertDialogCancel = React.forwardRef(({ className, ...props }, ref) => {
const context = React.useContext(AlertDialogContext);
if (!context) {
throw new Error("AlertDialogCancel must be used within an AlertDialog");
}
const { setOpen } = context;
const handleClick = (e) => {
setOpen(false);
// Call the original onClick if it exists
if (props.onClick) {
props.onClick(e);
}
};
// Remove onClick from props to avoid duplicate handlers
const { onClick, ...otherProps } = props;
return ((0, jsx_runtime_1.jsx)("button", { ref: ref, className: (0, utils_1.cn)((0, button_1.buttonVariants)({ variant: "outline" }), "mt-2 sm:mt-0", className), onClick: handleClick, ...otherProps }));
});
exports.AlertDialogCancel = AlertDialogCancel;
AlertDialogCancel.displayName = "AlertDialogCancel";
//# sourceMappingURL=alert-dialog.js.map