Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

1.3 KB
Raw Blame
import type { ButtonProps } from "@rallly/ui/button";
import { Button } from "@rallly/ui/button";
import {
  Dialog,
  DialogClose,
  DialogContent,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from "@rallly/ui/dialog";
import type * as React from "react";

export interface ModalProps {
  title?: React.ReactNode;
  okText?: string;
  cancelText?: string;
  okButtonProps?: ButtonProps;
  onOk?: () => void;
  onCancel?: () => void;
  content?: React.ReactNode;
  overlayClosable?: boolean;
  visible?: boolean;
}

const Modal: React.FunctionComponent<ModalProps> = ({
  title,
  okText,
  content,
  onCancel,
  cancelText,
  onOk,
  okButtonProps,
  visible,
}) => {
  return (
    <Dialog
      open={visible}
      onOpenChange={(open) => {
        if (!open) {
          onCancel?.();
        }
      }}
    >
      <DialogContent>
        <DialogHeader>
          <DialogTitle>{title}</DialogTitle>
        </DialogHeader>
        <p className="text-sm">{content}</p>
        <DialogFooter>
          <DialogClose render={<Button />}>{cancelText}</DialogClose>
          <Button
            variant="primary"
            onClick={() => {
              onOk?.();
            }}
            {...okButtonProps}
          >
            {okText}
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
};

export default Modal;