Skip to content

Commit b7d6be5

Browse files
committed
docs(project): Update README with TypeScript examples
1 parent 54cc91b commit b7d6be5

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
11
## Prerequisites
22

3-
[Node.js](http://nodejs.org/) >= 6 must be installed.
3+
[Node.js](http://nodejs.org/) >= 10 must be installed.
44

55
## Installation
66

7-
- Running `npm install` in the component's root directory will install everything you need for development.
7+
- Running `yarn` in the component's root directory will install everything you need for development.
88

9-
## Demo Development Server
9+
## Storybook Development
1010

11-
- `npm start` will run a development server with the component's demo app at [http://localhost:3000](http://localhost:3000) with hot module reloading.
12-
13-
## Running Tests
14-
15-
- `npm test` will run the tests once.
16-
17-
- `npm run test:coverage` will run the tests and produce a coverage report in `coverage/`.
18-
19-
- `npm run test:watch` will run the tests on every change.
20-
21-
## Building
22-
23-
- `npm run build` will build the component for publishing to npm and also bundle the demo app.
24-
25-
- `npm run clean` will delete built resources.
11+
- `yarn run storybook` will run Storybook.

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,21 @@ export default () => (
3535
);
3636
```
3737

38+
### TypeScript
39+
Typing for your row components is included as a named export.
40+
```typescript jsx
41+
import {ReactSmartScrollRow} from 'react-smart-scroll';
42+
43+
const TypedTestRow: ReactSmartScrollRow = ({data, rowRef}) => (
44+
<div ref={rowRef}>
45+
{data.text}
46+
</div>
47+
);
48+
```
49+
3850
### Working Demo with variable height rows:
39-
https://codesandbox.io/s/react-smart-scroll-demo-3x1ym
51+
* [JavaScript Demo](https://codesandbox.io/s/react-smart-scroll-demo-3x1ym)
52+
* [TypeScript Demo](https://codesandbox.io/s/react-smart-scroll-ts-demo-9p3kz)
4053

4154
**This component uses React Hooks, so it requires React 16.8.x or above.**
4255

@@ -65,7 +78,7 @@ Due to a CSS limitation with how overflow works with padding, `height: 100%` doe
6578
The `overflow` default value of `auto` is applied via `style`. If you want to use a css class to control it, you need to pass `null`, `undefined`, or an empty string to `overflow`. If you use a style object, you can set it there, since the default `auto` is applied before your style object and thus can be overwritten that way.
6679

6780
```javascript
68-
import ReactSmartScroll from 'react-smart-scroll';
81+
import ReactSmartScroll, {ReactSmartScrollRow} from 'react-smart-scroll';
6982

7083
<ReactSmartScroll
7184
className="demo-smart-scroll"
@@ -77,7 +90,7 @@ import ReactSmartScroll from 'react-smart-scroll';
7790
label="My text is: " // passed to row components
7891
/>
7992

80-
const TestRow = ({data, height, label, onClick, rowIndex, rowRef}) => (
93+
const TestRow: ReactSmartScrollRow = ({data, height, label, onClick, rowIndex, rowRef}) => (
8194
<div ref={rowRef} className="test-row" onClick={() => onClick(rowIndex)}>
8295
<strong>[{data.id}]</strong>: {height}px<br/>
8396
<label>{label}</label>:<p>{data.text}</p>

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
"main": "./dist/index.js",
1919
"module": "./dist/index.es.js",
2020
"types": "./dist/index.d.ts",
21-
"files": [
22-
"dist"
23-
],
21+
"files": ["dist"],
2422
"scripts": {
2523
"build": "rollup -c",
2624
"test": "react-scripts test",
@@ -57,8 +55,8 @@
5755
"typescript": "^4.4.3"
5856
},
5957
"peerDependencies": {
60-
"react": "^17.0.2",
61-
"react-dom": "^17.0.2"
58+
"react": "^16.8.0 | ^17.0.2",
59+
"react-dom": "^16.8.0 | ^17.0.2"
6260
},
6361
"eslintConfig": {
6462
"extends": [

0 commit comments

Comments
 (0)