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

r-modal

v0.4.0

Published

An unopinionated modal with integrations for react-router and react-redux.

Downloads

14

Readme

r-modal

An unopinionated modal with integrations for react-router and react-redux.

Demos

To run the demos clone the repo and npm i && npm start.

Installation

npm install r-modal --save

Concept

r-modal provides a relatively simple modal component which can be controlled by any of the integrations provided, or with your own state management solution. Conceptually this is similar to how a controlled input works.

There is a secondary stateless component, Page, which is used to lock the scroll position of the page content. In both cases, the components are left unstyled - full control of styling and UI is delegated to the developer.

Components

<Modal>

A stateless unstyled component that renders a modal inside an overlay.

import { Modal } from 'r-modal';

<Modal
  open={this.state.open}
  onRequestClose={this.closeModal}>
  Modal contents
  <button onClick={this.closeModal}>Close Modal</button>
</Modal>

API

prop|type|description :---|:---|:--- open | bool.isRequired | display the modal and overlay onRequestClose | func.isRequired | an escape hatch for the modal to access the outer state. Is called when the overlay is clicked or the ESC key is pressed. onBeforeOpen | func | called before the modal opens onBeforeClose | func | called before the modal closes className | string | classes to be applied to the modal element overlayClassName | string | classes to be applied to the overlay element style | shape({ overlay, modal }) | an object with inline styles to be applied to overlay and modal elements flatNodes | bool | renders modal and overlay nodes as siblings (by default the modal node is nested inside the overlay)


<Page>

A stateless unstyled component that locks the scroll position of the underlying page.

import { Page } from 'r-modal';

<Page
  locked={true}
  className="my-page">
  {this.prop.children}
</Page>

API

prop|type|description :---|:---|:--- locked | bool.isRequired | locks the position of the web page, preventing scrolling beneath the modal


<WithRoutesInModal>

A react-router integration that renders child routes inside a modal.

import { Page, Modal } from 'r-modal';
import { WithRoutesInModal } from 'r-modal/lib/react-router';

const App = props => (
  <div>
    <Page>
      {props.children}
    </Page>
    {props.showModal && (
      <Modal
        open
        onRequestClose={props.onModalClose}>
        {props.modalContents}
      </Modal>
    )}
  </div>
);

const AppWithRoutesInModal = props => (
  <WithRoutesInModal
    {...props}
    component={App}
  />
);

<Router>
  <Route path="/" component={AppWithRoutesInModal}>
    <IndexRoute component={Index} />
    <Route path="pictures/:id" component={ModalContent} />
  </Route>
</Router>
import { WithRoutesInModal } from 'r-modal/lib/react-router';

const BoardWithRoutesInModal = props => (
  <WithRoutesInModal
    {...props}
    component={App}
    backgroundLocation={`/boards/${props.params.id[0]}`}
  />
)

<Router>
  <Route path="/boards/:id" component={BoardWithRoutesInModal}>
    <Route path="card/:id" component={Card} />
  </Route>
</Router>

API

prop|type|description :---|:---|:--- component | func | the route component to decorate parentLocation* | oneOfType([object, string]) | the location of the modal's parent that is rendered behind the modal modal | func | an instance of the stateless Modal component page | func | an instance of the stateless Page component

*When provided, child routes are always rendered in a modal. Closing the modal will resolve to this location, therefore the provided location should be the exact route that is rendered beneath the modal. When not provided, routes will only be rendered in a modal if they have router state of { modal: true }.

redux integration

See examples