Skip to content

Commit e05436a

Browse files
author
Patrick Tran
committed
initial commit
0 parents  commit e05436a

13 files changed

+11435
-0
lines changed

.eslintrc.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": [
3+
"prettier"
4+
],
5+
"parser": "@typescript-eslint/parser",
6+
"settings": {
7+
"import/resolver": {
8+
"node": {
9+
"extensions": [".js", ".jsx", ".ts", ".tsx"],
10+
"moduleDirectory": ["node_modules", "src/"]
11+
}
12+
}
13+
}
14+
}

.gitignore

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Directory for instrumented libs generated by jscoverage/JSCover
10+
lib-cov
11+
12+
# Coverage directory used by tools like istanbul
13+
coverage
14+
*.lcov
15+
16+
# nyc test coverage
17+
.nyc_output
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (https://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directories
26+
node_modules/
27+
jspm_packages/
28+
29+
# TypeScript v1 declaration files
30+
typings/
31+
32+
# TypeScript cache
33+
*.tsbuildinfo
34+
35+
# Optional npm cache directory
36+
.npm
37+
38+
# Optional eslint cache
39+
.eslintcache
40+
41+
# Output of 'npm pack'
42+
*.tgz
43+
44+
# Yarn Integrity file
45+
.yarn-integrity
46+
47+
# generate output
48+
dist
49+
50+
# vscode custom settings
51+
.vscode

.npmignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dist
2+
.babelrc
3+
.storybook
4+
.gitignore
5+
.prettierrc
6+
rollup.config.js
7+
tsconfig.json

.prettierrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"printWidth": 85,
6+
"tabWidth": 2,
7+
"endOfLine": "auto"
8+
}

README.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# React - Use Scroll to Element Hook
2+
3+
> React hook for scrolling to elements on the same page (Anchor Link)
4+
5+
<br/>
6+
7+
[![NPM](https://img.shields.io/npm/v/react-use-scroll-to-element-hook.svg)](https://www.npmjs.com/package/react-use-scroll-to-element-hook) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
8+
9+
<br/>
10+
11+
## Installation
12+
13+
This module is distributed via npm which is bundled with node and
14+
should be installed as one of your project's dependencies:
15+
16+
```shell
17+
npm install --save react-use-scroll-to-element-hook
18+
```
19+
20+
<br/>
21+
22+
## Demo
23+
24+
> ### [https://codesandbox.io/s/react-use-scoll-to-element-hook-example-1kids](https://codesandbox.io/s/react-use-scoll-to-element-hook-example-1kids)
25+
26+
<br/>
27+
<br/>
28+
29+
<img src="react-scroll-to-element-hook.gif" alt="react-scroll-to-element-hook" style="width:600px;"/>
30+
31+
<br/>
32+
<br/>
33+
34+
## Usage
35+
36+
```js
37+
import React from 'react';
38+
import ReactDOM from 'react-dom';
39+
import { useScrollToElement } from 'react-use-scroll-to-element-hook';
40+
41+
function MyComponent() {
42+
// some code...
43+
44+
const FAQS = [
45+
{
46+
name: 'Question 1',
47+
answer: 'Lorem ipsum',
48+
},
49+
{
50+
name: 'Question 2',
51+
Ananswerswer: 'Pretium fusce id ',
52+
},
53+
{
54+
name: 'Question 3',
55+
answer: 'Dolor sit amet',
56+
},
57+
];
58+
59+
const faqNames = FAQS.map(faq => faq.name);
60+
61+
//Refer to: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
62+
const scrollIntoViewOptions = {
63+
behavior: 'auto';
64+
}
65+
66+
const { getScrollToElementRef, scrollToElementClickHandler } = useScrollToElement(
67+
faqNames, //array of strings
68+
scrollIntoViewOptions //this is optional - behavior: smooth is used by default
69+
);
70+
71+
return <div>{/* render FAQ with Anchor links here - see CodeSandBox demo */}</div>;
72+
}
73+
```

0 commit comments

Comments
 (0)