Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nallenscott/windshear

React hook for just-in-time component rendering, with first-class support for Tailwind CSS ⛵️
https://github.com/nallenscott/windshear

breakpoints hooks just-in-time media-queries pinpoint-accuracy react react-hooks tailwind-css viewport-dimensions

Last synced: 4 months ago
JSON representation

React hook for just-in-time component rendering, with first-class support for Tailwind CSS ⛵️

Awesome Lists containing this project

README

        




windshear

Windshear is a React hook for just-in-time component rendering, with first-class support for [Tailwind CSS](https://tailwindcss.com/docs). Easily bind visibility and other events to viewport dimensions and breakpoints with pinpoint accuracy.

## Installation

```
npm install windshear
```

## Usage

### Viewport dimensions

Windshear provides realtime viewport information that can be used to control the visibility of components or any feature that relies on the width/height of the viewport. Just call `useViewport`, and Windshear will continuously update the `currentWidth` and `currentHeight` properties using the global `window.innerWidth` and `window.innerHeight` for desktop browsers, and `window.screen.width` and `window.screen.height` for mobile browsers.

```js
import { useViewport } from 'windshear'

export default function Component () {
const viewport = useViewport()
return (
<>
{
viewport.currentWidth > 1280 ?
(

ComponentA

) :
(

ComponentB

)
}
>
)
}
```

### Tailwind breakpoints

Windshear accepts breakpoint definitions using the [Tailwind breakpoint schema](https://tailwindcss.com/docs/breakpoints). Simply drop your breakpoints into `useViewport`, and Windshear will continuously update the `activeBreakpoint` property with the key of the active breakpoint. Supports Tailwind's standard, max-width, and multi-range breakpoints.

```js
import { screens } from 'tailwindcss/defaultTheme'
import { useViewport } from 'windshear'

export default function Component () {
const viewport = useViewport(screens)
return (
<>
{
viewport.activeBreakpoint === 'lg' ?
(

ComponentA

) :
(

ComponentB

)
}
>
)
}
```

### Mobile user agents

Windshear provides basic detection for mobile user agents, and currently supports user agent strings containing the keywords Android, webOS, iPhone, iPad, iPod, or BlackBerry.

```js
import { useViewport } from 'windshear'

export default function Component () {
const viewport = useViewport()
return (
<>
{
viewport.isMobileAgent ?
(

ComponentA

) :
(

ComponentB

)
}
>
)
}
```