Skip to content

Commit 494b68b

Browse files
authored
Add readme and package improvements
1 parent efc13c0 commit 494b68b

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# use-scroll-direction
2+
[![Latest Stable Version](https://img.shields.io/npm/v/use-scroll-direction.svg)](https://www.npmjs.com/package/use-scroll-direction)
3+
[![CI Status](https://github.com/AndrzejSala/use-scroll-direction/workflows/CI/badge.svg)](https://github.com/AndrzejSala/use-scroll-direction/actions)
4+
[![Gzipped size](https://img.shields.io/bundlephobia/min/use-scroll-direction?label=size)](https://www.npmjs.com/package/use-scroll-direction)
5+
[![License](https://img.shields.io/npm/l/use-scroll-direction.svg)](./LICENSE)
6+
[![NPM total downloads](https://img.shields.io/npm/dt/use-scroll-direction.svg)](https://npmcharts.com/compare/use-scroll-direction?minimal=true)
7+
28
A simple, performant and versatile hook for handling scroll in your react app.
39

410
## Installation
@@ -7,9 +13,9 @@ npm i use-scroll-direction
713
```
814

915
## Usage
10-
The hook returns the actual scroll direction which could be one of three states: **'NONE', 'DOWN', 'UP'**;
16+
The hook returns the actual scroll direction which could be one of three states: **'NONE'**, **'DOWN'**, **'UP'**;
1117

12-
### On window
18+
### Use on window object
1319
```tsx
1420
import {useScrollDirection} from "use-scroll-direction";
1521

@@ -25,7 +31,7 @@ export const WindowExample = () => {
2531
};
2632

2733
```
28-
### On the element ref
34+
### Use on the specific element
2935
```tsx
3036
import {useScrollDirection} from "use-scroll-direction";
3137

@@ -34,11 +40,20 @@ export const ComponentRefExample = () => {
3440
const scrollDirection = useScrollDirection({ref: elementRef});
3541

3642
return (
43+
//The content needs to overflow a container
3744
<div ref={elementRef} style={{height: '100vh', overflowY: 'scroll'}} >
3845
<div>{...}</div>
3946
</div>
4047
)
4148
};
4249
```
4350

44-
For more specific examples, check the demo app in `./example`
51+
For more specific examples, check the demo app in `./example`
52+
53+
## Available options
54+
55+
| Name | Type | Description |
56+
| - | - | - |
57+
| `wait` | `?number` | Time in ms for throttling of scroll handler (default: 50)
58+
| `timeToReset` | `?number` | Time in ms after last scroll event to reset the state (default: 250)
59+
| `ref` | `?string` | When passed, the listener will be attached to element instead of window object

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
{
2-
"version": "0.1.0",
2+
"version": "0.1.1",
3+
"description": "A simple, performant, and cross-browser hook for handling scroll in your next react app.",
4+
"keywords": [
5+
"react",
6+
"hook",
7+
"custom-hook",
8+
"typescript",
9+
"detect",
10+
"scroll",
11+
"scrolling",
12+
"direction",
13+
"position",
14+
"window",
15+
"ref",
16+
"frontend"
17+
],
18+
"bugs": {
19+
"url": "https://github.com/AndrzejSala/use-scroll-direction/issues"
20+
},
321
"license": "MIT",
422
"main": "dist/index.js",
523
"typings": "dist/index.d.ts",
@@ -10,6 +28,10 @@
1028
"engines": {
1129
"node": ">=10"
1230
},
31+
"repository": {
32+
"type": "git",
33+
"url": "https://github.com/AndrzejSala/use-scroll-direction"
34+
},
1335
"scripts": {
1436
"start": "tsdx watch",
1537
"build": "tsdx build",
@@ -35,7 +57,7 @@
3557
"trailingComma": "es5"
3658
},
3759
"name": "use-scroll-direction",
38-
"author": "Andrzej Sala",
60+
"author": "Andrzej Sala <[email protected]>",
3961
"module": "dist/use-scroll-direction.esm.js",
4062
"size-limit": [
4163
{

0 commit comments

Comments
 (0)