generated from egoist/ts-lib-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Initial Release
- Loading branch information
Showing
6 changed files
with
957 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,59 @@ | ||
**💛 You can help the author become a full-time open-source maintainer by [sponsoring him on GitHub](https://github.com/sponsors/egoist).** | ||
# react-stay-at-bottom | ||
|
||
--- | ||
A React hook that keeps a scrollable element at the bottom. | ||
|
||
# my-ts-lib | ||
## Install | ||
|
||
[![npm version](https://badgen.net/npm/v/my-ts-lib)](https://npm.im/my-ts-lib) [![npm downloads](https://badgen.net/npm/dm/my-ts-lib)](https://npm.im/my-ts-lib) | ||
```bash | ||
npm i react-stay-at-bottom | ||
``` | ||
|
||
## Using this template | ||
## Usage | ||
|
||
- Search `my-ts-lib` and replace it with your custom package name. | ||
- Search `egoist` and replace it with your name. | ||
```tsx | ||
import { useStayAtBottom } from 'react-stay-at-bottom' | ||
|
||
Features: | ||
function MessageList({ | ||
children, | ||
messages, | ||
}: { | ||
children: React.ReactNode | ||
messages: string[] | ||
}) { | ||
const scrollRef = useRef<HTMLDivElement>(null) | ||
const { stayAtBottom, stopAtBottom, scrollToBottom, atBottom, scroll } = | ||
useStayAtBottom(scrollRef) | ||
|
||
- Package manager [pnpm](https://pnpm.js.org/), safe and fast | ||
- Release with [semantic-release](https://npm.im/semantic-release) | ||
- Bundle with [tsup](https://github.com/egoist/tsup) | ||
- Test with [vitest](https://vitest.dev) | ||
return <div ref={scrollRef}>{children}</div> | ||
} | ||
``` | ||
|
||
To skip CI (GitHub action), add `skip-ci` to commit message. To skip release, add `skip-release` to commit message. | ||
## Parameters | ||
|
||
## Install | ||
### `scrollRef`(**Required**): | ||
|
||
```bash | ||
npm i my-ts-lib | ||
``` | ||
type: `React.RefObject<HTMLElement>` | ||
|
||
description: a ref to the scrollable element. | ||
|
||
### `options`(**Optional**): | ||
|
||
type: `{ handleScroll?: (scrollElement: HTMLElement) => void, autoStay?: boolean, initialStay?: boolean }` | ||
|
||
description: an object controlling the behavior of the hook: | ||
|
||
- `handleScroll`: A function that replace the default scroll handler. | ||
- `autoStay`: Whether to automatically stay at the bottom when the scrollable element is scrolled. Defaults to `true`. | ||
- `initialStay`: Whether to stay at the bottom when the component is mounted. Defaults to `false`. | ||
|
||
## Sponsors | ||
## Return | ||
|
||
[![sponsors](https://sponsors-images.egoist.dev/sponsors.svg)](https://github.com/sponsors/egoist) | ||
- `stayAtBottom`: A function that keeps the scrollable element at the bottom. | ||
- `stopAtBottom`: A function that stops the scrollable element from being kept at the bottom. | ||
- `scrollToBottom`: A function that scrolls the scrollable element to the bottom. | ||
- `atBottom`: A boolean indicating whether the scrollable element is at the bottom. | ||
- `scroll`: A function that scrolls the scrollable element to the bottom. | ||
|
||
## License | ||
|
||
MIT © [EGOIST](https://github.com/sponsors/egoist) | ||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,26 @@ | |
"type": "module", | ||
"version": "0.0.3", | ||
"packageManager": "[email protected]", | ||
"description": "My awesome typescript library", | ||
"description": "A React hook that keeps a scrollable element at the bottom.", | ||
"author": "shlroland <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://github.com/shlroland/react-stay-at-bottom/README.md", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/shlroland/react-stay-at-bottom.git" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"hook", | ||
"react-hook", | ||
"scroll", | ||
"bottom", | ||
"react-scroll-to-bottom", | ||
"message-list", | ||
"stay-at-bottom", | ||
"keep-at-bottom", | ||
"auto-scroll-to-bottom" | ||
], | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
|
@@ -18,7 +36,8 @@ | |
"scripts": { | ||
"build": "tsup", | ||
"test": "vitest run", | ||
"prepublishOnly": "pnpm run build" | ||
"prepublishOnly": "pnpm run build", | ||
"commit": "cz" | ||
}, | ||
"dependencies": { | ||
"memoize-one": "^6.0.0", | ||
|
@@ -32,6 +51,8 @@ | |
"@ocavue/eslint-config": "^2.7.0", | ||
"@types/react": "^18.3.5", | ||
"@types/react-dom": "^18.3.0", | ||
"commitizen": "^4.3.0", | ||
"cz-conventional-changelog": "^3.3.0", | ||
"eslint": "^9.10.0", | ||
"prettier": "3.3.3", | ||
"tsup": "8.2.4", | ||
|
@@ -40,5 +61,10 @@ | |
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} |
Oops, something went wrong.