mantine-modal-manager
TypeScript icon, indicating that this package has built-in type declarations

7.6.2 • Public • Published

Improved Mantine modals manager

npm

This is an extension of @mantine/modals package with improved modals manager that allows to:

  • Open managed modals with full typesafety
  • Keeping the state of parent modals when opening nested modals
  • Has an improved API for managed modals

Installation

# With yarn
yarn add @mantine/hooks @mantine/core mantine-modal-manager

# With npm
npm install @mantine/hooks @mantine/core mantine-modal-manager

Usage

import { createManagedModal, createModalManager } from 'mantine-modal-manager';

// Define modal props:
type InnerProps = {
  title: string;
};

// Create managed modal:
const ExampleModal = createManagedModal<InnerProps>(({ actions, innerProps }) => {
  return (
    <div>
      <p>{innerProps.title}</p>
      <button onClick={actions.closeModal}>Close</button>
    </div>
  );
});

// Somewhere in your app create modal manager:
const [ModalManager, modalEvents] = createModalManager({
  example: ExampleModal,
});

// In your layout use the modal:

export const Layout = () => {
  return (
    <ModalManager>
      <YourApp />
    </ModalManager>
  );
};

// In your app use the modal:
const YourApp = () => {
  const openExampleModal = () =>
    modalEvents.openManagedModal({
      modal: 'example',
      innerProps: {
        title: 'Hello world',
      },
    });

  return (
    <div>
      <button onClick={openExampleModal}>Open modal</button>
    </div>
  );
};

License

MIT

Package Sidebar

Install

npm i mantine-modal-manager

Weekly Downloads

5

Version

7.6.2

License

MIT

Unpacked Size

137 kB

Total Files

54

Last publish

Collaborators

  • meierschlumpf