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

modal-kf-react

v1.0.10

Published

A customizable modal for React

Downloads

3

Readme

Modal Component

The Modal component is a reusable React component written in TypeScript that renders a modal dialog box. It provides a flexible and customizable way to display information, warnings, or errors.

To use this modal, you will need to import the provider in the parent component and wrap the children in it. You will then need to import to context hook from react, and the context from the module in the children, and use the function "displayModal" to display and modify it.

Here is the installation step by step.

Installation

To use the Modal component in your React project, follow these steps:

Install the required dependencies by running the following command:

npm install modal-kf-react

First, import the Provider in your root file, such as index.jsx

import ModalProvider from "modal-kf-react/ModalProvider";

Then, you will need the useContext from react and the context from the module in the desired children file.

import { useContext } from "react";

import { ModalContext } from "modal-kf-react/ModalProvider";

You're ready to use the Modal component in your application!

Usage

You need to wrap your app in the Provider

index.jsx

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <React.StrictMode>
    <ModalProvider>
      <App />
    </ModalProvider>
  </React.StrictMode>
);

app.jsx (or any children with the imports)

const { DisplayModal } = useContext(ModalContext);
 const showModal = () => {
    DisplayModal({
      mode: "info",
      title: "Test modal",
      children: "This modal should be diplayed in blue (because of the mode: info)",
    });
  };

  ...

   return (
    <>
      <button onClick={showModal}>test modal</button>
    </>
  );

With this example, clicking on the button should display a blue modal with a title and a children. Clicking on the close button, or anywhere outside the modal should close it.

Typescript usage

You can use the same setup above if your application is in Typescript, you'll need to also import the props in the children element

import { DisplayModalProps } from "modal-kf-react/ModalProvider";

and then add the props in the children element

App.tsx

 const showModal = () => {
    DisplayModal({
      mode: "info",
      title: "Test modal",
      children: "This modal should be diplayed in blue (because of the mode: info)",
    } as DisplayModalProps);
  };

Props

The Modal component accepts several props to customize its behavior and appearance:

| Name | Type | Required | Description | Default | | -------------------- | ---------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | | mode | string | required | The mode of the modal. Possible values are "default," "info", "warning", "error" or "custom". Default use the pattern shown in the base project, info warning and error are premade modals. "Custom" is a blank modale with no default, this is mainly used to display full components. You can overwrite any props using those modes. | ------- | | title | string | optional | The title of the modal. | ------- | | children | ReactNode | optional | The children components to be rendered inside the modal. | ------- | | className | string | optional | Additional class name for styling the modal. | ------- | | onClosed | function | optional | Callback function invoked when the modal is closed. | return | | onClose | function | optional | Callback function invoked to determine whether the modal should be closed. Should return a boolean value. | return true | | enableFadeIn | boolean | optional | Enables fade-in animation for the modal. | true | | enableFadeOut | boolean | optional | Enables fade-out animation for the modal. | true | | delay | number | optional | Set a timer for the display of the modal. | -1 | | height | string or number | optional | Set the height of the modal | auto | | width | string or number | optional | Set the width of the modal | auto | | modalPosition | string | optional | Set the modal position. Possible values are "center", "top-left", "top-right", "bottom-left", "bottom-right" | "center" | | backgroundColor | string | optional | Set the background color of the modal | Depends on the mode | | backgroundColorTitle | string | optional | Set the background color of the title, if it exists | Depends on the mode | | textColor | string | optional | Set the color of the text inside the modal | mode "default" : black ; other modes "white" | | closePosition | string | optional | Set the position of the close button on the modal. Possible values are "right", "left", "outside-right", "outside-left" | "outside-right" | | border | string | optional | Set the border of the modal | "solid black 2px" | | borderRadius | string | optional | Set the border radius of the modal | "20px" | | borderInside | string | optional | Set the color of the border on top or on the left of the children | "solid black 1px" | | boxShadow | string | optional | Set the box shadow of the modal | "none" | | orientation | string | optional | Set the orientation of the display inside the modal. The display is in flex. Accepts only "row". | "column" |