@kopexa/sight
Version:
Kopexa Sight Design System — React component library for GRC applications
179 lines (176 loc) • 4.52 kB
JavaScript
"use client";
// src/components/dialog/dialog.tsx
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
import { CloseIcon } from "@kopexa/icons";
import { createContext } from "@kopexa/react-utils";
import { cn } from "@kopexa/shared-utils";
import { dialog } from "@kopexa/theme";
import { useControllableState } from "@kopexa/use-controllable-state";
import { jsx, jsxs } from "react/jsx-runtime";
var [DialogProvider, useDialogContext] = createContext();
var DialogRoot = (props) => {
const {
open: openProp,
onOpenChange,
size,
radius,
placement,
scrollBehavior,
...restProps
} = props;
const [open, setOpen] = useControllableState({
value: openProp,
onChange: onOpenChange,
defaultValue: false
});
const styles = dialog({ size, radius, placement, scrollBehavior });
return /* @__PURE__ */ jsx(DialogProvider, { value: { styles, open, placement, size, radius }, children: /* @__PURE__ */ jsx(
DialogPrimitive.Root,
{
"data-slot": "dialog",
open,
onOpenChange: (open2) => setOpen(open2),
...restProps
}
) });
};
function DialogTrigger({ ...props }) {
return /* @__PURE__ */ jsx(DialogPrimitive.Trigger, { "data-slot": "dialog-trigger", ...props });
}
function DialogPortal({ ...props }) {
return /* @__PURE__ */ jsx(DialogPrimitive.Portal, { "data-slot": "dialog-portal", ...props });
}
function DialogClose({ ...props }) {
return /* @__PURE__ */ jsx(DialogPrimitive.Close, { "data-slot": "dialog-close", ...props });
}
function DialogOverlay({ className, ...props }) {
const { styles } = useDialogContext();
return /* @__PURE__ */ jsx(
DialogPrimitive.Backdrop,
{
"data-slot": "dialog-overlay",
className: cn(styles.overlay(), className),
...props
}
);
}
function DialogContent({
className,
children,
showCloseButton = true,
...props
}) {
const { styles } = useDialogContext();
return /* @__PURE__ */ jsxs(DialogPortal, { "data-slot": "dialog-portal", children: [
/* @__PURE__ */ jsx(DialogOverlay, {}),
/* @__PURE__ */ jsxs(
DialogPrimitive.Popup,
{
"data-slot": "dialog-content",
className: cn(styles.content(), className),
...props,
children: [
children,
showCloseButton && /* @__PURE__ */ jsxs(
DialogPrimitive.Close,
{
"data-slot": "dialog-close",
className: styles.close(),
children: [
/* @__PURE__ */ jsx(CloseIcon, {}),
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
]
}
)
]
}
)
] });
}
function DialogHeader({ className, ...props }) {
const { styles } = useDialogContext();
return /* @__PURE__ */ jsx(
"div",
{
"data-slot": "dialog-header",
className: styles.header({ className }),
...props
}
);
}
function DialogFooter({ className, ...props }) {
const { styles } = useDialogContext();
return /* @__PURE__ */ jsx(
"div",
{
"data-slot": "dialog-footer",
className: styles.footer({ className }),
...props
}
);
}
function DialogBody({ className, ...props }) {
const { styles } = useDialogContext();
return /* @__PURE__ */ jsx(
"div",
{
"data-slot": "dialog-body",
className: styles.body({ className }),
...props
}
);
}
function DialogTitle({ className, ...props }) {
const { styles } = useDialogContext();
return /* @__PURE__ */ jsx(
DialogPrimitive.Title,
{
"data-slot": "dialog-title",
className: cn(styles.title(), className),
...props
}
);
}
function DialogDescription({
className,
...props
}) {
const { styles } = useDialogContext();
return /* @__PURE__ */ jsx(
DialogPrimitive.Description,
{
"data-slot": "dialog-description",
className: cn(styles.description(), className),
...props
}
);
}
function DialogCloseTrigger({
className,
...props
}) {
const { styles } = useDialogContext();
return /* @__PURE__ */ jsx(
DialogPrimitive.Close,
{
"data-slot": "dialog-close-trigger",
className: cn(styles.closeTrigger(), className),
...props
}
);
}
export {
useDialogContext,
DialogRoot,
DialogTrigger,
DialogPortal,
DialogClose,
DialogOverlay,
DialogContent,
DialogHeader,
DialogFooter,
DialogBody,
DialogTitle,
DialogDescription,
DialogCloseTrigger
};