# rx-responsive

> RxResponsive is a small angular library for working with responsive web breakpoints in a fluid manner using RxJs.

Latest version **0.9.34** (published 2018-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install rx-responsive
pnpm add rx-responsive
yarn add rx-responsive
bun add rx-responsive
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.34 |
| Published | 2018-01-30 |
| First published | 2018-01-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 10 |
| Known vulnerabilities | 0 (+24 in 4 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kris Mackintosh |
| Maintainers | krismackintosh |

## Links

- npm: https://www.npmjs.com/package/rx-responsive
- Repository: https://github.com/Lightw3ight/RxResponsive
- Homepage: https://github.com/Lightw3ight/RxResponsive#readme
- Issues: https://github.com/Lightw3ight/RxResponsive/issues
- npm.io page: https://npm.io/package/rx-responsive

## Dependencies (10)

- [rxjs](https://npm.io/package/rxjs.md) ^5.5.6
- [rimraf](https://npm.io/package/rimraf.md) ^2.6.2
- [core-js](https://npm.io/package/core-js.md) ^2.4.1
- [zone.js](https://npm.io/package/zone.js.md) ^0.8.19
- [@angular/core](https://npm.io/package/@angular/core.md) ^5.2.0
- [@angular/common](https://npm.io/package/@angular/common.md) ^5.2.0
- [@angular/router](https://npm.io/package/@angular/router.md) ^5.2.0
- [@angular/compiler](https://npm.io/package/@angular/compiler.md) ^5.2.0
- [@angular/platform-browser](https://npm.io/package/@angular/platform-browser.md) ^5.2.0
- [@angular/platform-browser-dynamic](https://npm.io/package/@angular/platform-browser-dynamic.md) ^5.2.0

## Recent versions

- 0.9.34 (latest) — 2018-01-30
- 0.9.33 — 2018-01-30
- 0.9.32 — 2018-01-30
- 0.9.31 — 2018-01-30
- 0.9.30 — 2018-01-30
- 0.9.29 — 2018-01-30
- 0.9.28 — 2018-01-30
- 0.9.27 — 2018-01-30
- 0.9.26 — 2018-01-30
- 0.9.25 — 2018-01-30
- 0.9.24 — 2018-01-30
- 0.9.23 — 2018-01-30
- 0.9.22 — 2018-01-30
- 0.9.21 — 2018-01-30
- 0.9.20 — 2018-01-29
- … 22 more at https://npm.io/package/rx-responsive/versions

## README

# RxResponsive

RxResponsive is a small angular library for working with responsive web breakpoints in a fluid manner using RxJs.

The default breakpoints are based on bootstrap but you can configure your own strongly typed breakpoints too.

## Install
`yarn add rx-responsive`

## Usage:

### Module setup
Add the `RxResponsiveModule` with `forRoot()` to your root module's imports
```typescript
import { RxResponsiveModule } from 'rx-responsive';

@NgModule({
    imports: [
        RxResponsiveModule.forRoot()
    ],
    declarations: [
        ..
    ],
    providers: [
        ..
    ],
    bootstrap: [AppComponent]
})
export class AppModule {}
```

### Component setup
Inject the `RxResponsiveService` service publicly
```typescript
import { RxResponsiveService } from 'rx-responsive';

@Component({
    ..
})
export class MyComponent {
    constructor (
        public media: RxResponsiveService
    ) { }
}
```

### Using the service in your HTML
Given that you have publicly imported `RxResponsiveService` in your component with a name of `media`
#### Simple breakpoints
```html
    <div *ngIf="media.is.xs | async"></div>
    <div *ngIf="media.is.sm | async"></div>
    <div *ngIf="media.is.md | async"></div>
    <div *ngIf="media.is.lg | async"></div>
    <div *ngIf="media.is.xl | async"></div>
```

#### Combined breakpoints
```html
    <div *ngIf="media.is.xs.or.sm | async"></div>
    <div *ngIf="media.is.lg.or.xl | async"></div>
    <div *ngIf="media.is.sm.or.md.or.lg | async"></div>
```

#### greater$ and less$
```html
    <div *ngIf="media.is.md.or.greater | async"></div>
    <div *ngIf="media.is.lg.or.less | async"></div>
```

### Service API
#### .snapshot
A public getter to a snapshot in time of the current breakpoints

`media.snapshot.md === true`

#### .mediaSize$
A public getter to the breakpoint observable

```typescript
    media.mediaSize$.pipe(
        filter(ms => ms.lg),
        switchMap(...)
    )
```

### Configuring breakpoints
The default breakpoint sizes are based on bootstrap, but you can configure your own breakpoint conditions.

First off, define your own breakpoints as a const somewhere
```typescript
export const MyCustomBreakpoints = {
    mobile: { max: 500 },
    tablet: { min: 501, max: 1000 }
    desktop: { max: 1001 }
}
```

When importing the module `RxResponsiveModule` pass your breakpoints into the `forRoot()` method

```typescript
import { RxResponsiveModule } from 'rx-responsive';

@NgModule({
    imports: [
        RxResponsiveModule.withConfig(MyCustomBreakpoints)
    ],
    declarations: [
        ..
    ],
    providers: [
        ..
    ],
    bootstrap: [AppComponent]
})
export class AppModule {}
```

Finally, when importing the `RxResponsiveService` service in your component, add a generic type argument of your custom breakpoints

```typescript
import { RxResponsiveService } from 'rx-responsive';

@Component({
    ..
})
export class MyComponent {
    constructor (
        public media: RxResponsiveService<typeof MyCustomBreakpoints>
    ) { }
}
```

You will then get strong typing of your custom breakpoints

```html
    <div *ngIf="media.is.mobile | async"></div>
    <div *ngIf="media.is.tablet.or.greater | async"></div>
    <div *ngIf="media.is.mobile.or.desktop | async"></div>
```

```typescript
    media.mediaSize$.pipe(
        filter(ms => ms.mobile),
        switchMap(..)
    )

    media.is.mobile
        .subscribe(..)
```

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