Skip to content

Commit 39dc519

Browse files
committed
typescript support
1 parent 258c35b commit 39dc519

22 files changed

+1940
-37218
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
!.eslintrc.js
2+
!.prettierrc.js
13
dist/
24
docs/

.eslintrc.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,42 @@ module.exports = {
66
node: true
77
},
88
extends: [
9-
'eslint:recommended',
10-
'plugin:jsx-a11y/recommended',
9+
'plugin:react/recommended',
10+
'plugin:@typescript-eslint/recommended',
11+
'prettier/@typescript-eslint',
1112
'plugin:prettier/recommended',
12-
'plugin:react/recommended'
13+
'plugin:jsx-a11y/recommended'
1314
],
1415
parserOptions: {
15-
ecmaVersion: 2019,
16+
ecmaVersion: 2020,
1617
sourceType: 'module'
1718
},
18-
plugins: [
19-
'jsx-a11y',
20-
'react'
21-
],
19+
parser: '@typescript-eslint/parser',
20+
plugins: ['jsx-a11y', 'react', 'react-hooks', '@typescript-eslint'],
2221
rules: {
23-
'indent': ['error', 2, { 'SwitchCase': 1 }],
22+
'@typescript-eslint/no-explicit-any': 0, // because library is generic
2423
'jsx-quotes': ['error', 'prefer-double'],
2524
'jsx-a11y/no-onchange': 0,
2625
'no-trailing-spaces': 'error',
2726
'object-curly-spacing': ['error', 'always'],
28-
'quotes': ['error', 'single', { 'allowTemplateLiterals': true }],
29-
'semi': ['error', 'never']
27+
quotes: ['error', 'single', { allowTemplateLiterals: true }],
28+
'react-hooks/exhaustive-deps': 'error',
29+
'react-hooks/rules-of-hooks': 'error',
30+
'react/prop-types': 0,
31+
semi: ['error', 'never']
3032
},
3133
settings: {
3234
react: {
33-
version: '16'
35+
version: 'detect'
36+
}
37+
},
38+
overrides: [
39+
{
40+
files: ['*.js', '*.jsx'],
41+
rules: {
42+
'@typescript-eslint/explicit-function-return-type': 'off',
43+
'@typescript-eslint/no-var-requires': 'off'
44+
}
3445
}
35-
}
46+
]
3647
}

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
language: node_js
22
node_js:
33
- "13"
4+
before_install:
5+
- curl -o- -L https://yarnpkg.com/install.sh | bash
6+
- export PATH="$HOME/.yarn/bin:$PATH"
47
cache: yarn
8+
script:
9+
- yarn ci
510
after_success:
6-
- npm run coverage
11+
- yarn run coverage

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.3.1] - 2020-03-13
8+
9+
### Fixed
10+
* typescript definitions by rewriting project in typescript
11+
12+
### Removed
13+
* browser build
14+
715
## [0.3.0] - 2019-12-29
816

917
### Added

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# react-with-forwarded-ref
22
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
33

4-
[![npm version](https://img.shields.io/npm/v/react-with-forwarded-ref.svg)](https://www.npmjs.com/package/react-with-forwarded-ref) [![npm downloads](https://img.shields.io/npm/dm/react-with-forwarded-ref.svg)](https://www.npmjs.com/package/react-with-forwarded-ref) [![Build Status](https://travis-ci.org/rpearce/react-with-forwarded-ref.svg?branch=master)](https://travis-ci.org/rpearce/react-with-forwarded-ref) [![Coverage Status](https://coveralls.io/repos/github/rpearce/react-with-forwarded-ref/badge.svg?branch=master)](https://coveralls.io/github/rpearce/react-with-forwarded-ref?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/61ace8daca24175f9d16/maintainability)](https://codeclimate.com/github/rpearce/react-with-forwarded-ref/maintainability)
4+
[![npm version](https://img.shields.io/npm/v/react-with-forwarded-ref.svg)](https://www.npmjs.com/package/react-with-forwarded-ref) [![npm downloads](https://img.shields.io/npm/dm/react-with-forwarded-ref.svg)](https://www.npmjs.com/package/react-with-forwarded-ref) [![bundlephobia size](https://badgen.net/bundlephobia/minzip/react-with-forwarded-ref)](bundlephobia.com/result?p=react-with-forwarded-ref) [![Build Status](https://travis-ci.org/rpearce/react-with-forwarded-ref.svg?branch=master)](https://travis-ci.org/rpearce/react-with-forwarded-ref) [![Coverage Status](https://coveralls.io/repos/github/rpearce/react-with-forwarded-ref/badge.svg?branch=master)](https://coveralls.io/github/rpearce/react-with-forwarded-ref?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/61ace8daca24175f9d16/maintainability)](https://codeclimate.com/github/rpearce/react-with-forwarded-ref/maintainability)
55

66
This React.js [higher-order component
77
(HOC)](https://reactjs.org/docs/higher-order-components.html) exists to provide
@@ -10,8 +10,6 @@ an appropriate wrapper for components that utilize
1010
`ref` via `props` and renames `ref` to `forwardedRef` along
1111
with whatever other `props` are passed in.
1212

13-
Please see the [`API Documentation`](./API.md) for usage.
14-
1513
## Links
1614
* [Installation](#installation)
1715
* [Usage](#usage)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`withForwardedRef renders 1`] = `
4+
<DocumentFragment>
5+
<div
6+
class="foo"
7+
>
8+
Testing 123
9+
</div>
10+
</DocumentFragment>
11+
`;
12+
13+
exports[`withForwardedRef renders, custom displayName 1`] = `
14+
<DocumentFragment>
15+
<div
16+
class="foo"
17+
>
18+
Testing 123
19+
</div>
20+
</DocumentFragment>
21+
`;
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
1-
/* eslint react/prop-types: 0 */
2-
3-
import React, { createRef } from 'react'
4-
import { renderIntoDocument } from 'react-dom/test-utils'
5-
import { shallow } from 'enzyme'
6-
import toJson from 'enzyme-to-json'
7-
1+
import React, { FC, ReactNode, RefObject, createRef } from 'react'
2+
import { render } from '@testing-library/react'
83
import withForwardedRef from '../source'
94

5+
interface Props<A = any> {
6+
children: ReactNode
7+
className: string
8+
forwardedRef?: RefObject<A>
9+
}
10+
1011
describe('withForwardedRef', () => {
1112
it('renders', () => {
12-
const Comp = ({ children, className, forwardedRef }) => (
13+
const Comp: FC<Props> = ({ children, className, forwardedRef }) => (
1314
<div className={className} ref={forwardedRef}>
1415
{children}
1516
</div>
1617
)
1718
const WrappedComp = withForwardedRef(Comp)
1819
const ref = createRef()
19-
const wrapper = shallow(
20+
const { asFragment } = render(
2021
<WrappedComp className="foo" ref={ref}>
2122
Testing 123
2223
</WrappedComp>
2324
)
24-
const tree = toJson(wrapper)
25-
expect(tree).toMatchSnapshot()
25+
26+
expect(asFragment()).toMatchSnapshot()
2627
})
2728

2829
it('renders, custom displayName', () => {
29-
const Comp = ({ children, className, forwardedRef }) => (
30+
const Comp: FC<Props> = ({ children, className, forwardedRef }) => (
3031
<div className={className} ref={forwardedRef}>
3132
{children}
3233
</div>
3334
)
3435
Comp.displayName = 'FooBar'
3536
const WrappedComp = withForwardedRef(Comp)
3637
const ref = createRef()
37-
const wrapper = shallow(
38+
const { asFragment } = render(
3839
<WrappedComp className="foo" ref={ref}>
3940
Testing 123
4041
</WrappedComp>
4142
)
42-
const tree = toJson(wrapper)
43-
expect(tree).toMatchSnapshot()
43+
44+
expect(asFragment()).toMatchSnapshot()
4445
})
4546

4647
it('ref points to HTMLDivElement', () => {
47-
const Comp = ({ children, className, forwardedRef }) => (
48+
const Comp: FC<Props> = ({ children, className, forwardedRef }) => (
4849
<div className={className} ref={forwardedRef}>
4950
{children}
5051
</div>
5152
)
5253
const WrappedComp = withForwardedRef(Comp)
5354
const ref = createRef()
54-
renderIntoDocument(
55+
56+
render(
5557
<WrappedComp className="foo" ref={ref}>
5658
Testing 123
5759
</WrappedComp>
5860
)
61+
5962
expect(ref.current).toBeInstanceOf(HTMLDivElement)
6063
})
6164
})

babel.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)