# owp.responsive-react

> Responsive layout for React

Latest version **1.0.0** (published 2020-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install owp.responsive-react
pnpm add owp.responsive-react
yarn add owp.responsive-react
bun add owp.responsive-react
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-07-27 |
| First published | 2020-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Andreas Arvidsson |
| Maintainers | andreas_arvidsson |
| Keywords | responsive, react, Open Web Project, owp |

## Links

- npm: https://www.npmjs.com/package/owp.responsive-react
- Repository: https://github.com/AndreasArvidsson/OpenWebProject-ResponsiveReact
- Issues: https://github.com/AndreasArvidsson/OpenWebProject-ResponsiveReact/issues
- npm.io page: https://npm.io/package/owp.responsive-react

## Dependencies (1)

- [react](https://npm.io/package/react.md) ^16.9.0

## 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

- 1.0.0 (latest) — 2020-07-27

## README

# OpenWebProject ResponsiveReact

**Responsive layout for React**

Based upon the size of the screen (or more specifically the browser window) do conditionally rendering. Makes it possible to have different layouts for different screen/window sizes.

## Installation
`npm install owp.responsive-react --save`

## Screen sizes
I'm using the screen sizes as defined by [Bootstrap](https://getbootstrap.com/docs/4.0/layout/overview/#responsive-breakpoints)

* xs - Extra small devices (portrait phones, less than 576px)
* sm - Small devices (landscape phones, 576px and up)
* md - Medium devices (tablets, 768px and up)
* lg - Large devices (desktops, 992px and up)
* xl - Extra large devices (large desktops, 1200px and up)

## Usage
Add the provider at the top of your application.
```jsx
import { ResponsiveProvider } from "owp.responsive-react";

ReactDOM.render(
    <ResponsiveProvider>
        <App />
    </ResponsiveProvider>,
    document.getElementById("root")
);
```

Conditional render based upon screen/window size.
```jsx
import Responsive, { XS, SM, MD, LG, XL } from "owp.responsive-react";

//Render div if screen/window size is md(Medium) or larger.
<Responsive min="md">
    <div>min md</div>
</Responsive>

//Render div if screen/window size is md(Medium) or smaller.
<Responsive max="md">
    <div>max md</div>
</Responsive>

//Render div if screen/window width is 500px or more.
<Responsive minWidth={500}>
    <div>minWidth 500</div>
</Responsive>

//Render div if screen/window width is 500px or less.
<Responsive maxWidth={500}>
    <div>maxWidth 500</div>
</Responsive>

//Render div if screen/window height is 300px or more.
<Responsive minHeight={300}>
    <div>minHeight 300</div>
</Responsive>

//Render div if screen/window height is 300px or less.
<Responsive maxHeight={300}>
    <div>maxHeight 300</div>
</Responsive>

//Render div if screen/window is in portrait mode(height >= width).
<Responsive isPortrait={true}>
    <div>isPortrait</div>
</Responsive>

//Render div if screen/window is in landscape mode(height < width).
<Responsive isLandscape={true}>
    <div>isLandscape</div>
</Responsive>

//Render best matching layout based upon screen/window size.
<Responsive>
    <XS><div>Extra small</div></XS>
    <SM><div>Small</div></SM>
    <MD><div>Medium</div></MD>
    <LG><div>Large</div></LG>
    <XL><div>Extra large</div></XL>
</Responsive>

//Can be combined with a condition. Will render the best match, but only in portrait mode.
<Responsive isPortrait={true}>
    <XS><div>Extra small</div></XS>
    <SM><div>Small</div></SM>
    <MD><div>Medium</div></MD>
    <LG><div>Large</div></LG>
    <XL><div>Extra large</div></XL>
</Responsive>
```

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