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

@frankhu00/react-modal

v1.2.0

Published

React modal

Downloads

1

Readme

React Modal

A simple react + styled-components modal

Package Interface

Named exports: Modal, useModalContext, ModalContainer, and ModalContent
Default export: Modal

Usages

1) Pass in a function as children to access modal methods

<Modal content={() => <div>Modal Content</div>}>
    {({ showModal }) => <button onClick={showModal}>Button to trigger modal</button>}
</Modal>

2) Modal methods are passed to the direct descendant

const SampleButton = ({ showModal }) => {
    return <button onClick={showModal}>Sample Button</button>;
};

<Modal content={() => <div>Modal Content</div>}>
    <SampleButton />
</Modal>;

3) Using ContextAPI to access modal methods

const GrandchildButton = () => {
    const { showModal } = useModalContext();

    return <button onClick={showModal}>Grandchild Button</button>;
};

<Modal content={() => <div>Modal Content</div>}>
    <div className="component-container">
        <GrandchildButton />
    </div>
</Modal>;

Modal Props

| Prop | Type | Default | Description | | --------------------- | ---------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | content | Component | () => Component | undefined | A component or function that returns a component to serve as the modal content | | onModalShow | func | undefined | Function to trigger when the modal is shown | | onModalClose | func | undefined | Function to trigger when the modal is closed | | animationDuration | number | 500 | The fade in / out duration in ms | | showOnRender | boolean | false | If true, modal will display when mounted | | showXBtn | boolean | true | If true, a "x" button will rendered at the top right of the modal | | persist | boolean | false | If true, the modal will be mounted in dom and hidden / shown via CSS | | closeOnBackdrop | boolean | true | If true, clicking on the backdrop will close the modal | | addControls | boolean | false | If true, modal will automatically append two action buttons: "Close" and "Confirm". The "Close" button will close the modal, and the action of the "Confirm" is dependent on "proceedAction" prop | | proceedAction | func | () => console.warn(...) | The onClick handler for the "Confirm" button created from "addControls" prop | | proceedBtnText | string | "Confirm" | The text displayed for "Confirm" button | | closeBtnText | string | "Close" | The text displayed for "Close" button | | CustomModalContainer | Component | ModalContainer | Defines the component that warps around the entire modal | | CustomModalContent | Component | ModalContent | Defines the component used to wrap around the modal content | | CustomPrimaryButton | Component | button element | The component that is used to generate the "Confirmed" button | | CustomSecondaryButton | Component | button element | The component that is used to generate the "Closed" button |

Modal Methods

Below are the methods available to control the modal

| Method | Inputs | Description | | ---------------------- | ------------------------------------------------ | --------------------------------- | | showModal | none | Displays the modal | | closeModal | none | Closes the modal | | toggleModal | none | Toggles the state of the modal | | setDynamicContent | Component | Func Component | Updates the contents of the modal | | updateOptions | { showXBtn, addControls, ...etc } | Updates the specified option | | updateCustomComponents | { Container, Content, PrimaryBtn, SecondaryBtn } | Updates the custom components |

Additional Notes

ModalContainer styled component

Extend ModalContainer with styled-components to make furthur css changes since this component is looking for show, zIndex, closeOnBackdrop, stage, animationDuration prop for animations and default styling

  • show is used to toggle the css display rule
  • zIndex sets z-index rule
  • closeOnBackdrop will set the cursor rule
  • stage is used to determine the component's rendering stage (entering vs exiting) to use either fade in or fade out animation
  • animationDuration specifies the duration of the animation