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

react-bootstrap-modal-provider

v2.0.3

Published

React-Bootstrap-Modal-Provider is a React Component that renders React-Bootstrap modals more performantly with less markup.

Downloads

407

Readme

React-Bootstrap-Modal-Provider

Work in progress

React-Bootstrap-Modal-Provider is a Component that renders React-Bootstrap modals more performantly with less markup.

API

ModalProvider

ModalProvider is a component that renders a Modal for you alongside its children. ModalProvider will take care of maintaining the state of its modal.

ModalProvider can receive the following props:

Prop | Type | Default | Description :---|:---|:---|:--- componentClass | String or Component | 'div' | The root container of ModalProvider modalProps | Object | {} | Props to be provided to the <Modal>

withModalProvider

withModalProvider is a Higher Order Component that decorates the component that you provide it with a modalProvider prop.

The modalProvider prop provided by withModalProvider has the following shape:

Provided Prop | Type | Description :---|:---|:--- showModal(options: Object) | Function | A function that will render a modal with the options you provide it. hideModal() | Function | A function that will hide the modal of the current <ModalProvider> scope. When called within a nested <ModalProvider>, it will close the nested modal only.

showModal can take the following options:

Option | Type | Description :---|:---|:--- body (required) | String or ReactElement | The content rendered inside <Modal.Body>. closeButton | Boolean | Displays a closeButton on <Modal.Header> when set to true. footer | String or ReactElement | The content rendered inside <Modal.Footer>. No <Modal.Footer> is rendered when this is null. modalProps|Object| Props that are passed to. title|StringorReactElement| The content rendered inside<Modal.Title>. No <Modal.Title>is rendered when this isnull`

In the component that you pass withModalProvider, you can pass an object with your desired modal configuration to modalProvider.showModal:

this.props.modalProvider.showModal({
  title: 'This is a title',
  body: 'This is a body'
});

You can also pass a function to showModal to have access to modalProvider functions, like so:

this.props.modalProvider.showModal((modalProvider) => {
  return {
    title: 'This is a title',
    body: 'This is a body',
    footer: <button onClick={ modalProvider.hideModal }>This button closes the modal</button>
  }
});

Recycling code for common modals is as simple as defining an export of a function or object to be passed to this.props.modalProvider.showModal:

//basicModal.js
...
const basicModal = ({ hideModal }) => ({
  title: 'Congrats! You opened the modal.',
  body: <BasicModalBody />,
  footer: <Button onClick={hideModal}>Hide Modal</Button>,
  closeButton: true,
});
export default basicModal;
//BasicExamplePage.jsx
import React from 'react';
import { modalProviderShape, withModalProvider } from 'react-bootstrap-modal-provider';
import basicModal from './basicModal';

class BasicExamplePage extends React.Component {
  render() {
    return (
      ...
        <Button onClick={() => this.props.modalProvider.showModal(basicModal)}>
          Click me for a modal predefined by an imported function
        </Button>
      ...
    )
  }
}
BasicExamplePage.propTypes = { modalProvider: modalProviderShape.isRequired };

export default withModalProvider(BasicExamplePage);
...

TODO:

  • [x] Create ModalProvider component
  • [x] Create withModalProvider HOC
  • [x] Setup build script with webpack
  • [x] Setup eslint
  • [x] Add examples
  • [ ] Add tests
  • [ ] Write README.md