1.0.12 ā€¢ Published 3 years ago

use-backdrop v1.0.12

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

React Hooks API for quickly displaying customizable full-screen backdrops/overlays.

Think of use-backdrop as alert(), but native to React, and endlessly customizable!

NPM JavaScript Style Guide

use-backdrop is ready for production apps šŸ˜˜

gif of use-backdrop

Install

npm install --save use-backdrop

Usage

šŸŽ‰ A no-fuss example that uses use-backdrop to display a modal is available on GitHub. šŸŽ‰

Step 1: Wrap BackdropProvider around your root (App) component

import { BackdropProvider } from 'use-backdrop';
 
return (
  <BackdropProvider>
    <div className="App">
      { /* The rest of your app. */ }
    </div>
  </BackdropProvider>
)

Step 2: Import and call the useBackdrop hook

import { useBackdrop } from 'use-backdrop';
 
export default function MyComponent() {
  const { displayBackdrop, closeBackdrop } = useBackdrop();
}

Step 3: Call displayBackdrop, passing in a render function

export default function MyComponent() {
  const { displayBackdrop } = useBackdrop();
 
  const handleClick = () => displayBackdrop((closeBackdrop) => (
    <div>
      <button onClick={closeBackdrop}>
        Click me to close the backdrop.
      </button>
    </div>
  ));
 
  return (
    <div>
      <button onClick={handleClick}>
        Click me to display a backdrop.
      </button>
    </div>
  )
}

BackdropProvider props & options

BackdropProvider.propTypes = {
  children: PropTypes.element,

  // zIndex of the backdrop surface. Unused if backdropSurface is
  // overridden.
  zIndex: PropTypes.number,

  // If true, backdrop background is transparent.
  disableDarken: PropTypes.bool,

  // A render function: (children) => (/* React Component */)
  // that returns a Component that overrides (takes the place of)
  // the default darkened div background.
  //
  // See /example/src/ExampleApp.jsx for proper use.
  backdropSurface: PropTypes.func
}

BackdropProvider.defaultProps = {
  children: null,
  disableBackdrop: false,
  zIndex: 10,
  backdropSurface: null
}

License

MIT Ā© lyulka

1.0.11

3 years ago

1.0.10

3 years ago

1.0.12

3 years ago

1.0.2

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.0

4 years ago