Components
Modal

Modal

The Modal component is a versatile component for creating modal dialogs or pop-up windows. It can display custom content within a modal and provides options for showing and hiding the modal.

Props

The Modal component accepts the following props:

NameTypeDescription
childrenstring, React.ReactElement, or (props: { close: () => void }) => React.ReactElementThe content to display within the modal. This can be a string, a React element, or a function.
titlestring or React.ReactElementThe title to display in the modal header.
showbooleanIf true, the modal is displayed; if false, it is hidden.
onClose() => voidA callback function called when the modal is closed.
scrollType"paper" or "body"The scroll behavior of the modal. Use "paper" for scrollable content within the modal, and "body" for a full-height scrollable modal.

Try It

import { useState } from 'react';
import { Modal, Button } from '@kloktun/uikit';

export default function ModalExample() {
  const [showModal, setShowModal] = useState(false);

  return (
    <div>
      <Button onClick={() => setShowModal(true)}>Show Modal</Button>
      <Modal show={showModal} onClose={() => setShowModal(false)} title="Modal Title">
        {({ close }) => (
          <div className="flex flex-col gap-4">
            <p>This is a modal dialog with custom content.</p>
            <Button onClick={close}>Close</Button>
          </div>
        )}
      </Modal>
    </div>
  );
}