@vela-ui/react
Version:
Vela UI React components
288 lines (282 loc) • 8.65 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/components/dialog.tsx
var dialog_exports = {};
__export(dialog_exports, {
Dialog: () => Dialog,
DialogCloseIcon: () => DialogCloseIcon,
DialogContent: () => DialogContent,
DialogDescription: () => DialogDescription,
DialogFooter: () => DialogFooter,
DialogHeader: () => DialogHeader,
DialogTitle: () => DialogTitle,
DialogTrigger: () => DialogTrigger
});
module.exports = __toCommonJS(dialog_exports);
var import_react_aria_components3 = require("react-aria-components");
// src/icons/close.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var CloseIcon = (props) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
"svg",
{
fill: "none",
stroke: "currentColor",
strokeWidth: 2,
strokeLinecap: "round",
strokeLinejoin: "round",
width: "1em",
height: "1em",
viewBox: "0 0 24 24",
xmlns: "http://www.w3.org/2000/svg",
...props,
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M18 6 6 18" }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m6 6 12 12" })
]
}
);
};
// src/lib/utils.ts
var import_clsx = require("clsx");
var import_react_aria_components = require("react-aria-components");
var import_tailwind_merge = require("tailwind-merge");
var cn = (...inputs) => (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(...inputs));
function composeTailwindRenderProps(className, tailwind) {
return (0, import_react_aria_components.composeRenderProps)(className, (className2) => (0, import_tailwind_merge.twMerge)(tailwind, className2));
}
// src/components/modal.tsx
var import_react_aria_components2 = require("react-aria-components");
var import_tailwind_variants = require("tailwind-variants");
var import_jsx_runtime2 = require("react/jsx-runtime");
var modalOverlayVariants = (0, import_tailwind_variants.tv)({
base: "fixed top-0 left-0 isolate z-50 flex w-full items-center justify-center bg-black/50 duration-200",
variants: {
placement: {
top: "items-start",
center: "items-center",
bottom: "items-end"
},
scrollBehavior: {
inside: "overflow-hidden",
outside: "overflow-auto"
},
isEntering: {
true: "animate-in fade-in-0"
},
isExiting: {
true: "animate-out fade-out-0"
}
},
defaultVariants: {
placement: "center",
scrollBehavior: "outside"
}
});
var modalVariants = (0, import_tailwind_variants.tv)({
base: "bg-background my-16 w-full max-w-[calc(100%-2rem)] rounded-lg border shadow-lg transition duration-200",
variants: {
scrollBehavior: {
inside: "max-h-[calc(100%-7.5rem)]",
outside: ""
},
isEntering: {
true: "animate-in fade-in-0 zoom-in-95"
},
isExiting: {
true: "animate-out fade-out-0 zoom-out-95"
},
size: {
xs: "sm:max-w-xs",
sm: "sm:max-w-sm",
md: "sm:max-w-md",
lg: "sm:max-w-lg",
xl: "sm:max-w-xl",
"2xl": "sm:max-w-2xl",
"3xl": "sm:max-w-3xl",
"4xl": "sm:max-w-4xl",
"5xl": "sm:max-w-5xl",
full: "my-0 h-dvh max-w-full rounded-none"
}
},
defaultVariants: {
size: "lg"
}
});
function ModalOverlay({
className,
placement,
scrollBehavior,
...props
}) {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
import_react_aria_components2.ModalOverlay,
{
"data-slot": "modal-overlay",
style: {
height: "var(--visual-viewport-height)"
},
className: (0, import_react_aria_components2.composeRenderProps)(
className,
(className2, renderProps) => modalOverlayVariants({ ...renderProps, placement, scrollBehavior, className: className2 })
),
...props
}
);
}
function Modal({
className,
size,
scrollBehavior,
...props
}) {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
import_react_aria_components2.Modal,
{
"data-slot": "modal",
className: (0, import_react_aria_components2.composeRenderProps)(
className,
(className2, renderProps) => modalVariants({ ...renderProps, size, scrollBehavior, className: className2 })
),
...props
}
);
}
function ModalContent({
className,
overlayClassName,
isDismissable = true,
size,
placement,
scrollBehavior,
...props
}) {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
ModalOverlay,
{
isDismissable,
className: overlayClassName,
placement,
scrollBehavior,
...props,
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Modal,
{
isDismissable,
className,
size,
scrollBehavior,
...props
}
)
}
);
}
// src/components/dialog.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
var DialogTrigger = import_react_aria_components3.DialogTrigger;
var Dialog = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ModalContent, { ...props });
var DialogContent = ({
role = "dialog",
className,
children,
showCloseButton = true,
...props
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components3.Dialog,
{
role,
"data-slot": "dialog-content",
className: cn("relative flex h-full w-full flex-col p-6 outline-hidden", className),
...props,
children: (0, import_react_aria_components3.composeRenderProps)(children, (children2) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
children2,
showCloseButton && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DialogCloseIcon, {})
] }))
}
);
};
var DialogHeader = ({ className, ...props }) => {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
"div",
{
"data-slot": "dialog-header",
className: cn("mb-4 flex flex-col gap-2 text-center sm:text-left", className),
...props
}
);
};
var DialogFooter = ({ className, ...props }) => {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
"div",
{
"data-slot": "dialog-footer",
className: cn("mt-4 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className),
...props
}
);
};
var DialogTitle = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components3.Heading,
{
slot: "title",
"data-slot": "dialog-title",
className: cn("text-lg leading-none font-semibold", className),
...props
}
);
var DialogDescription = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components3.Text,
{
slot: "description",
"data-slot": "dialog-description",
className: cn("text-muted-foreground text-sm", className),
...props
}
);
var DialogCloseIcon = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
import_react_aria_components3.Button,
{
"aria-label": "Close",
slot: "close",
"data-slot": "dialog-close",
className: composeTailwindRenderProps(
className,
"ring-offset-background focus:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
),
...props,
children: [
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CloseIcon, {}),
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "sr-only", children: "Close" })
]
}
);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Dialog,
DialogCloseIcon,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger
});