# react-adaptive

> HOC component for adaptive design with React

Latest version **2.0.2** (published 2019-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-adaptive
pnpm add react-adaptive
yarn add react-adaptive
bun add react-adaptive
```

## 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.0.2 |
| Published | 2019-03-15 |
| First published | 2018-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 35.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Lokymil |
| Maintainers | lokymil |
| Keywords | css, react-component, viewport, react, mobile, media queries, respond, media query, matchMedia, responsive, component, adaptive |

## Links

- npm: https://www.npmjs.com/package/react-adaptive
- Repository: https://github.com/Lokymil/react-adaptive
- Homepage: https://github.com/Lokymil/react-adaptive#readme
- Issues: https://github.com/Lokymil/react-adaptive/issues
- npm.io page: https://npm.io/package/react-adaptive

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2019-03-15
- 2.0.1 — 2019-03-15
- 2.0.0 — 2019-03-15
- 1.2.0 — 2019-03-15
- 1.1.1 — 2018-11-19
- 1.1.0 — 2018-11-19
- 1.0.0 — 2018-10-29
- 0.2.1 — 2018-10-29
- 0.2.0 — 2018-10-29
- 0.1.2 — 2018-10-29
- 0.1.1 — 2018-10-29
- 0.1.0 — 2018-10-29

## README

# react-adaptive [![NPM](https://img.shields.io/npm/v/react-adaptive.svg)](https://www.npmjs.com/package/react-adaptive) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

A Higher Order Component (HOC) allowing you to adapt your component display according to its own size and integrate you website with adaptive design.

## Information

<table>
  <tr>
    <td>Package</td>
    <td>react-adaptive</td>
  </tr>
  <tr>
    <td>Description</td>
    <td>Element size in react for adaptive design</td>
  </tr>
  <tr>
    <td>Example (basic for now)</td>
    <td>https://lokymil.github.io/react-adaptive/</td>
  </tr>
</table>

## Install
```bash
npm install --save react-adaptive
```


## Usage

### Using withAdaptive HOC

In that case, you have to define a function receiving the size of the component and returning expected component according to your own process.

```js
import React, { Component } from 'react';
import { withAdaptive } from 'react-adaptive';

class LargeComponent extends Component {
  render() {
    return (
      <div>
        My large component {this.props.name}
      </div>
    );
  }
}

class MediumComponent extends Component {
  render() {
    return (
      <div>
        My medium component {this.props.name}
      </div>
    );
  }
}

class SmallComponent extends Component {
  render() {
    return (
      <div>
        My small component {this.props.name}
      </div>
    );
  }
}

const mapSizeToComponent = size => props => {
  if (size.width < 400) {
    return <SmallComponent {...props} />;
  }

  if (size.width < 700) {
    return <MediumComponent {...props} />;
  }

  return <LargeComponent {...props} />;
};

export default withAdaptive({ mapSizeToComponent });
```

### Using withBreakpoint HOC

In that case, you have to define a set of breakpoints, up to 7, and a set of associated components. You can define an optionnal default Component.  
Breakpoints name :
<table>
  <tr>
  </tr>
</table>

```js
import React, { Component } from 'react';
import { withBreakpoints, breakpoints } from 'react-adaptive';

class LargeComponent extends Component {
  render() {
    return (
      <div>My large component components.name}</div>
    );
  }
}

class MediumComponent extends Component {
  render() {
    return (
      <div>My medium component components.name}</div>
    );
  }
}

class SmallComponent extends Component {
  render() {
    return (
      <div>My small component components.name}</div>
    );
  }
}

const components = {
  [breakpoints.large]: LargeComponent,
  [breakpoints.medium]: MediumComponent,
  [breakpoints.small]: SmallComponent
};

const breakPoints = {
  [breakpoints.large]: 1000,
  [breakpoints.medium]: 700,
  [breakpoints.small]: 400
};

export default withBreakpoints(breakPoints)({
  components,
  defaultComponent: LargeComponent
});
```

### Using withSize HOC

In that case, your component will have an additionnal props as: 
```js
size = { width: `current component width` }
```

```js
import React from 'react';
import { withSize } from 'react-adaptive';

const MyComponent = ({ size }) => (<div>My own size is {size.width}</div>);

export default withSize(MyComponent);
```

## License

MIT © [Lokymil](https://github.com/Lokymil)

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