# @astrocoders/react-modal-image

> Lightweight Lightbox React Component

Latest version **2.1.7** (published 2018-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @astrocoders/react-modal-image
pnpm add @astrocoders/react-modal-image
yarn add @astrocoders/react-modal-image
bun add @astrocoders/react-modal-image
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.7 |
| Published | 2018-07-20 |
| First published | 2018-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 38.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ari Autio |
| Maintainers | gabrielrubens, georgelima, guilhermedecampo, jabur, sandroqz |
| Keywords | react-component, lightbox, modal, image, react |

## Links

- npm: https://www.npmjs.com/package/@astrocoders/react-modal-image
- Repository: https://github.com/astrocoders/react-modal-image
- npm.io page: https://npm.io/package/@astrocoders/react-modal-image

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.1.7 (latest) — 2018-07-20
- 2.1.6 — 2018-07-20
- 2.1.5 — 2018-07-19

## README

# react-modal-image

[![CircleCI][build-badge]][build]
[![npm package][npm-badge]][npm]

A _lightweight_ React component providing modal image Lightbox.

[DEMO](https://aautio.github.io/react-modal-image/)

## Features

- Only _3 kB_ when gzipped.
- Zero dependencies.
- Includes builds for CommonJS and ES modules.
- For React 15.x and 16.x.
- Esc, Enter & click outside the image close the lightbox
- User can zoom & move the image or download the highest quality one
- Image alt shown as title of lightbox

You need to bring your own `Set` polyfill if you use old Internet Explorers.

## Simple API

```js
import ModalImage from 'react-modal-image'

<ModalImage
  small={urlToTinyImageFile}
  large={urlToHugeImageFile}
  alt="Hello World!"
/>
```

| Prop                | Type      | Description                                                                         |
| ------------------- | --------- | ----------------------------------------------------------------------------------- |
| `className`         | `String`  | Optional. `class` for the small preview image.                                      |
| `alt`               | `String`  | Optional. `alt` for the small image and the heading text in Lightbox.               |
| `small`             | `URL`     | `src` for the small preview image.                                                  |
| `smallSrcSet`       | `String`  | Optional. `srcSet` for the small preview image.                                     |
| `medium`            | `URL`     | Optional if `large` is defined. Image shown when zoomed out in Lightbox.            |
| `large`             | `URL`     | Optional if `medium` is defined. Image shown when zoomed in Lightbox. Downloadable. |
| `hasDownloadButton` | `Boolean` | Optional. Show download button in LightBox if set `true`                            |

## Lightbox-only API

You can also choose to import only the Lightbox.

To use the Lightbox only, you'll need to handle the open state by yourself:

```js
import { Lightbox } from 'react-modal-image'

// ...

const closeLightbox = () => {
  this.state.open = true
}

// ...

{
  this.state.open && (
    <Lightbox medium={urlToLargeImageFile} large={urlToHugeImageFile} alt="Hello World!" onClose={this.closeLightbox} />
  )
}
```

| Prop      | Type       | Description                                             |
| --------- | ---------- | ------------------------------------------------------- |
| `onClose` | `function` | Will be invoked when the Lightbox requests to be closed |

[build-badge]: https://img.shields.io/circleci/project/github/aautio/react-modal-image.svg
[build]: https://circleci.com/gh/aautio/react-modal-image
[npm-badge]: https://img.shields.io/npm/v/react-modal-image.svg
[npm]: https://www.npmjs.org/package/react-modal-image

---
_Source: https://npm.io/package/@astrocoders/react-modal-image · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
