@yamada-ui/modal
Version:
Yamada UI modal component
191 lines (184 loc) • 6.37 kB
JavaScript
"use client"
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/modal-content.tsx
var modal_content_exports = {};
__export(modal_content_exports, {
ModalContent: () => ModalContent
});
module.exports = __toCommonJS(modal_content_exports);
var import_motion = require("@yamada-ui/motion");
var import_transitions = require("@yamada-ui/transitions");
var import_utils4 = require("@yamada-ui/utils");
// src/dialog-close-button.tsx
var import_core2 = require("@yamada-ui/core");
var import_utils3 = require("@yamada-ui/utils");
// src/modal-close-button.tsx
var import_close_button = require("@yamada-ui/close-button");
var import_core = require("@yamada-ui/core");
var import_utils2 = require("@yamada-ui/utils");
// src/modal-context.ts
var import_utils = require("@yamada-ui/utils");
var [ModalProvider, useModal] = (0, import_utils.createContext)({
name: `ModalContext`,
errorMessage: `useModal returned is 'undefined'. Seems you forgot to wrap the components in "<Modal />" `
});
var [DialogProvider, useDialog] = (0, import_utils.createContext)({
name: `DialogContext`,
errorMessage: `useDialog returned is 'undefined'. Seems you forgot to wrap the components in "<Dialog />" `
});
var [DrawerProvider, useDrawer] = (0, import_utils.createContext)({
name: `DrawerContext`,
errorMessage: `useDrawer returned is 'undefined'. Seems you forgot to wrap the components in "<Drawer />" `
});
// src/modal-close-button.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var ModalCloseButton = (0, import_core.forwardRef)(
({ onClick, __css, ...rest }, ref) => {
const { styles, onClose } = useModal();
const css = {
position: "absolute",
...__css ? __css : styles.closeButton
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_close_button.CloseButton,
{
ref,
className: (0, import_utils2.cx)("ui-modal__close-button"),
"aria-label": "Close modal",
onClick: (0, import_utils2.handlerAll)(onClick, (ev) => {
ev.stopPropagation();
onClose == null ? void 0 : onClose();
}),
__css: css,
...rest
}
);
}
);
ModalCloseButton.displayName = "ModalCloseButton";
ModalCloseButton.__ui__ = "ModalCloseButton";
// src/dialog-close-button.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var DialogCloseButton = (0, import_core2.forwardRef)(
({ className, ...rest }, ref) => {
const styles = useDialog();
const css = { ...styles.closeButton };
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
ModalCloseButton,
{
ref,
className: (0, import_utils3.cx)("ui-dialog__close-button", className),
"aria-label": "Close dialog",
__css: css,
...rest
}
);
}
);
DialogCloseButton.displayName = "DialogCloseButton";
DialogCloseButton.__ui__ = "DialogCloseButton";
// src/modal-content.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
var getModalContentProps = (animation = "scale", duration) => {
switch (animation) {
case "scale":
return {
...import_transitions.scaleFadeProps,
custom: { duration, reverse: true, scale: 0.95 }
};
case "top":
return {
...import_transitions.slideFadeProps,
custom: { duration, offsetY: -16, reverse: true }
};
case "right":
return {
...import_transitions.slideFadeProps,
custom: { duration, offsetX: 16, reverse: true }
};
case "left":
return {
...import_transitions.slideFadeProps,
custom: { duration, offsetX: -16, reverse: true }
};
case "bottom":
return {
...import_transitions.slideFadeProps,
custom: { duration, offsetY: 16, reverse: true }
};
}
};
var ModalContent = (0, import_motion.motionForwardRef)(
({ className, children, __css, ...rest }, ref) => {
var _a, _b;
const {
animation,
bodyRef,
duration,
headerRef,
scrollBehavior,
styles,
withCloseButton,
onClose
} = useModal();
const validChildren = (0, import_utils4.getValidChildren)(children);
const [customModalCloseButton, ...cloneChildren] = (0, import_utils4.findChildren)(
validChildren,
ModalCloseButton,
DialogCloseButton
);
const props = animation !== "none" ? getModalContentProps(animation, duration) : {};
const css = {
display: "flex",
flexDirection: "column",
maxH: "100%",
outline: 0,
overflow: scrollBehavior === "inside" ? "hidden" : "auto",
position: "relative",
...__css ? __css : styles.container
};
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
import_motion.motion.section,
{
ref,
className: (0, import_utils4.cx)("ui-modal", className),
"aria-describedby": (_a = bodyRef.current) == null ? void 0 : _a.id,
"aria-labelledby": (_b = headerRef.current) == null ? void 0 : _b.id,
"aria-modal": "true",
role: "dialog",
tabIndex: -1,
__css: css,
...props,
...rest,
children: [
customModalCloseButton != null ? customModalCloseButton : withCloseButton && onClose ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ModalCloseButton, {}) : null,
cloneChildren
]
}
);
}
);
ModalContent.displayName = "ModalContent";
ModalContent.__ui__ = "ModalContent";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ModalContent
});
//# sourceMappingURL=modal-content.js.map