2.3.3 • Published 8 months ago

@camlin/react-confirm-modal v2.3.3

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

react-modal-confirmation component

The react-modal-confirmation is a reusable confirmation modal component built with React and Ant Design. It allows you to display a customizable confirmation dialog with multiple buttons and callback actions.

Installation

To use the react-modal-confirmation, first install the required dependencies:

npm install react

Install this package:

npm install @camlin/react-modal-confirmation

Usage

Here’s how you can use the react-modal-confirmation in your React project:

import React, { useState } from 'react';
import { ConfirmModal } from '@camlin/react-confirm-modal';

const App = () => {
  const [modalOpen, setModalOpen] = useState(false);

  const handleConfirm = () => {
    setModalOpen(false);
    console.log("Confirmed!");
  };

  return (
    <div>
      <button onClick={() => setModalOpen(true)}>Show Modal</button>
      
      <ConfirmModal
        open={modalOpen}
        title="Confirmation Required"
        content="Are you sure you want to proceed?"
        footerButtons={[
          { text: 'OK', type: 'primary', onClick: () => {} },
          { text: 'Cancel', type: 'default', onClick: () => setModalOpen(false) },
        ]}
        onConfirm={handleConfirm}
      />
    </div>
  );
};

export default App;

Props

The react-modal-confirmation component accepts the following props:

PropTypeRequiredDefaultDescription
visiblebooleanYesfalseControls the visibility of the modal.
titleReactNodeNo""The title of the modal dialog.
contentReactNodeNo""The content of the modal body.
footerButtonsButtonProps[]No[]Array of button configurations to display in the modal footer.
onConfirm() => voidNonullCallback function triggered when the modal is confirmed or closed.

ButtonProps

The footerButtons prop accepts an array of objects with the following properties:

PropTypeRequiredDefaultDescription
textstringYes""The label of the button.
type'primary' \| 'default' \| 'dashed' \| 'link' \| 'text'No'default'The Ant Design button type.
onClick() => voidNonullFunction to be executed when the button is clicked.

Example

Here’s an example of passing different button configurations to the footerButtons prop:

<ConfirmModal
  visible={modalVisible}
  title="Delete Confirmation"
  content="Are you sure you want to delete this item?"
  footerButtons={[
    { text: 'Yes', type: 'primary', onClick: handleConfirm },
    { text: 'No', type: 'default', onClick: () => setModalVisible(false) },
    { text: 'More Info', type: 'link', onClick: () => alert('More information') },
  ]}
  onConfirm={handleConfirm}
/>

In this example:

  • The modal displays three buttons: "Yes", "No", and "More Info".
  • Each button has its own action, such as closing the modal or triggering a confirmation.

Styling

You can customize the styles of the modal and buttons by overriding the default Ant Design styles. Make sure to include your own SCSS or CSS file if you wish to customize the look and feel.

// Example of overriding Ant Design styles in your SCSS file
.ant-modal {
  background-color: #f5f5f5;
}

.ant-btn-primary {
  background-color: #ff4d4f;
}

Environnement

License

This project is licensed under the MIT License.

2.2.9

9 months ago

2.2.8

9 months ago

2.3.0

8 months ago

2.2.1

12 months ago

2.1.2

12 months ago

2.2.0

12 months ago

2.1.1

12 months ago

2.3.2

8 months ago

2.2.3

9 months ago

2.1.4

12 months ago

2.3.1

8 months ago

2.2.2

9 months ago

2.1.3

12 months ago

2.2.5

9 months ago

2.3.3

8 months ago

2.2.4

9 months ago

2.2.7

9 months ago

2.2.6

9 months ago

2.2.10

8 months ago

2.1.0

12 months ago

2.0.0

1 year ago

1.0.0

1 year ago