Add types/tests for @reach/auto-id, @reach/rect, @reach/skip-nav, @reach/utils, @reach/visually-hidden, @reach/window-size (#36373)

This commit is contained in:
Harry Hedger
2019-06-28 09:42:26 -07:00
committed by Ben Lichtman
parent dcd243fdd8
commit 93cb7d2d62
24 changed files with 342 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
// Type definitions for @reach/auto-id 0.2
// Project: https://github.com/reach/reach-ui
// Definitions by: Harry Hedger <https://github.com/hedgerh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
export function useId(): number;
@@ -0,0 +1,4 @@
import { useId } from '@reach/auto-id';
// $ExpectType number
useId();
+28
View File
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@reach/auto-id": ["reach__auto-id"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"reach__auto-id-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+18
View File
@@ -0,0 +1,18 @@
// Type definitions for @react/rect 0.2
// Project: https://github.com/reach/reach-ui
// Definitions by: Harry Hedger <https://github.com/hedgerh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
export interface RectProps {
observe?: boolean;
onChange?: (rect: DOMRect) => void;
children?(args: { rect: DOMRect, ref: React.Ref<any> }): React.ReactNode;
}
declare const Rect: React.FC<RectProps>;
export default Rect;
export function useRect(ref: React.Ref<any>, isSelected?: boolean): DOMRect;
+31
View File
@@ -0,0 +1,31 @@
import Rect, { useRect } from '@reach/rect';
import * as React from 'react';
import { render } from 'react-dom';
function Example() {
const ref = React.useRef<HTMLDivElement | null>(null);
const rect = useRect(ref);
return (
<div>
<pre>{JSON.stringify(rect, null, 2)}</pre>
<div ref={ref} />
<Rect observe={false}>
{({ rect, ref }) => (
<div ref={ref}>
<div>Will not measure the element when false</div>
<div>
Edit this code and change it to <code>true</code>
</div>
<pre>{JSON.stringify(rect, null, 2)}</pre>
</div>
)}
</Rect>
</div>
);
}
render(<Example />, document.getElementById('app'));
render(<Rect />, document.getElementById('app'));
+28
View File
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@reach/rect": ["reach__rect"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"reach__rect-tests.tsx"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for @reach/skip-nav 0.1
// Project: https://github.com/reach/reach-ui
// Definitions by: Harry Hedger <https://github.com/hedgerh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
export interface SkipNavProps {
children?: string | React.ReactNode;
}
export class SkipNavLink extends React.Component<SkipNavProps & React.HTMLProps<HTMLAnchorElement>> {}
export class SkipNavContent extends React.Component<SkipNavProps & React.HTMLProps<HTMLDivElement>> {}
@@ -0,0 +1,20 @@
import { SkipNavLink, SkipNavContent } from '@reach/skip-nav';
import * as React from 'react';
import { render } from 'react-dom';
render(<SkipNavLink />, document.getElementById('app'));
render(
<SkipNavLink style={{ color: 'red' }} onClick={() => {}}>
Skip it
</SkipNavLink>,
document.getElementById('app')
);
render(<SkipNavContent />, document.getElementById('app'));
render(
<SkipNavContent style={{ color: 'red' }} onClick={() => {}}>
Skip Nav Content
</SkipNavContent>,
document.getElementById('app')
);
+28
View File
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@reach/skip-nav": ["reach__skip-nav"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"reach__skip-nav-tests.tsx"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for @reach/utils 0.2
// Project: https://github.com/reach/reach-ui
// Definitions by: Harry Hedger <https://github.com/hedgerh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
export function checkStyles(pkg: string): () => void;
export function wrapEvent(
handler: React.ReactEventHandler | undefined,
cb: React.ReactEventHandler
): React.ReactEventHandler;
export function assignRef(ref?: React.Ref<any>, value?: React.ReactNode): void;
@@ -0,0 +1,4 @@
import { checkStyles, wrapEvent, assignRef } from '@reach/utils';
import * as React from 'react';
import { render } from 'react-dom';
+28
View File
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@reach/utils": ["reach__utils"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"reach__utils-tests.tsx"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+10
View File
@@ -0,0 +1,10 @@
// Type definitions for @reach/visually-hidden 0.2
// Project: https://github.com/reach/reach-ui
// Definitions by: Harry Hedger <https://github.com/hedgerh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
declare let VisuallyHidden: React.FC<any>;
export default VisuallyHidden;
@@ -0,0 +1,13 @@
import VisuallyHidden from '@reach/visually-hidden';
import * as React from 'react';
import { render } from 'react-dom';
render(<VisuallyHidden />, document.getElementById('app'));
render(
<VisuallyHidden>
<div>I should be hidden!</div>
</VisuallyHidden>,
document.getElementById('app')
);
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@reach/visually-hidden": ["reach__visually-hidden"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"reach__visually-hidden-tests.tsx"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for @reach/window-size 0.1
// Project: https://github.com/reach/reach-ui
// Definitions by: Harry Hedger <https://github.com/hedgerh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import * as React from 'react';
export interface WindowSizeProps {
children: (size: { width: number; height: number }) => React.ReactNode;
}
declare const WindowSize: React.FC<WindowSizeProps>;
export default WindowSize;
@@ -0,0 +1,18 @@
import WindowSize from '@reach/window-size';
import * as React from 'react';
import { render } from 'react-dom';
render(
<WindowSize>
{(size) => (
<div>
<div>Resize your window.</div>
<pre>{JSON.stringify(size, null, 2)}</pre>
</div>
)}
</WindowSize>,
document.getElementById('app')
);
render(<WindowSize />, document.getElementById('app')); // $ExpectError
+29
View File
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@reach/window-size": ["reach__window-size"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"reach__window-size-tests.tsx"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }