npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@camlin/react-confirm-modal

v2.0.0

Published

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.

Downloads

137

Readme

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 antd 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 './components/ConfirmModal';

const App = () => {
  const [modalVisible, setModalVisible] = useState(false);

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

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

export default App;

Props

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

| Prop | Type | Required | Default | Description | | ------------- | ------------------------------------- | -------- | --------- | --------------------------------------------------------------------------- | | visible | boolean | Yes | false | Controls the visibility of the modal. | | title | string | No | "" | The title of the modal dialog. | | content | string | No | "" | The content of the modal body. | | footerButtons | ButtonProps[] | No | [] | Array of button configurations to display in the modal footer. | | onConfirm | () => void | Yes | null | Callback function triggered when the modal is confirmed or closed. |

ButtonProps

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

| Prop | Type | Required | Default | Description | | -------- | ---------------------------------------------------- | -------- | --------- | -------------------------------------------------------------------- | | text | string | Yes | "" | The label of the button. | | type | 'primary' \| 'default' \| 'dashed' \| 'link' \| 'text' \| undefined | No | 'default' | The Ant Design button type. | | onClick| () => void | Yes | null | Function 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;
}

License

This project is licensed under the MIT License.