diff --git a/types/reach__alert-dialog/index.d.ts b/types/reach__alert-dialog/index.d.ts new file mode 100644 index 0000000000..7ae432cedd --- /dev/null +++ b/types/reach__alert-dialog/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for @reach/alert-dialog 0.2 +// Project: https://github.com/reach/reach-ui +// Definitions by: Harry Hedger +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as React from 'react'; +import { DialogProps, DialogContentProps } from 'reach__dialog'; + +export type AlertDialogProps = { + isOpen?: boolean; + onDismiss?: () => void; + leastDestructiveRef: React.RefObject; + children: React.ReactNode; +} & DialogProps; + +export type AlertDialogContentProps = { + children: React.ReactNode; +} & DialogContentProps; + +export const AlertDialog: React.FunctionComponent; +export const AlertDialogLabel: React.FC>; +export const AlertDialogDescription: React.FC>; +export const AlertDialogOverlay: React.FC; +export const AlertDialogContent: React.FC; diff --git a/types/reach__alert-dialog/reach__alert-dialog-tests.tsx b/types/reach__alert-dialog/reach__alert-dialog-tests.tsx new file mode 100644 index 0000000000..14460f6aee --- /dev/null +++ b/types/reach__alert-dialog/reach__alert-dialog-tests.tsx @@ -0,0 +1,52 @@ +import { + AlertDialog, + AlertDialogLabel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogOverlay, +} from '@reach/alert-dialog'; + +import * as React from 'react'; +import { render } from 'react-dom'; + +class GoodExamples extends React.Component { + cancelRef = React.createRef(); + + render() { + return ( + <> + + Please Confirm! + + + Are you sure you want to delete stuff, it will be permanent. + + + + + + + + Please Confirm! + + + Are you sure you want to delete stuff, it will be permanent. + + + + + + + ); + } +} + +render(, document.getElementById('app')); +render(, document.getElementById('app')); +render(, document.getElementById('app')); + +// No children and needs leastDestructiveRef +// $ExpectError +render(, document.getElementById('app')); +// $ExpectError +render(, document.getElementById('app')); diff --git a/types/reach__alert-dialog/tsconfig.json b/types/reach__alert-dialog/tsconfig.json new file mode 100644 index 0000000000..e4f52c48e0 --- /dev/null +++ b/types/reach__alert-dialog/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "paths": { + "@reach/alert-dialog": ["reach__alert-dialog"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "reach__alert-dialog-tests.tsx" + ] +} diff --git a/types/reach__alert-dialog/tslint.json b/types/reach__alert-dialog/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/reach__alert-dialog/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/reach__dialog/index.d.ts b/types/reach__dialog/index.d.ts new file mode 100644 index 0000000000..d32c2f8137 --- /dev/null +++ b/types/reach__dialog/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for @reach/dialog 0.1 +// Project: https://github.com/reach/reach-ui +// Definitions by: Harry Hedger +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as React from 'react'; + +export type DialogProps = { + isOpen?: boolean; + onDismiss?: () => void; + children?: React.ReactNode; +} & React.HTMLProps; + +export type DialogOverlayProps = { + initialFocusRef?: React.RefObject; +} & DialogProps; + +export type DialogContentProps = { + children?: React.ReactNode; +} & React.HTMLProps; + +export const Dialog: React.FC; +export const DialogOverlay: React.FC; +export const DialogContent: React.FC; diff --git a/types/reach__dialog/reach__dialog-tests.tsx b/types/reach__dialog/reach__dialog-tests.tsx new file mode 100644 index 0000000000..9ba3e66ffd --- /dev/null +++ b/types/reach__dialog/reach__dialog-tests.tsx @@ -0,0 +1,44 @@ +import { Dialog, DialogOverlay, DialogContent } from '@reach/dialog'; + +import * as React from 'react'; +import { render } from 'react-dom'; + +class Example extends React.Component { + state = { showDialog: true }; + buttonRef = React.createRef(); + + render() { + const { setState, state } = this; + + return ( + <> + setState({ showDialog: false })}> + +

Hello there. I am a dialog

+
+ + setState({ showDialog: false })} + initialFocusRef={this.buttonRef} + > + +

The overlay styles are a white fade instead of the default black fade.

+ +
+
+ + ); + } +} + +render(, document.getElementById('app')); + +render(, document.getElementById('app')); +render(, document.getElementById('app')); +render(, document.getElementById('app')); diff --git a/types/reach__dialog/tsconfig.json b/types/reach__dialog/tsconfig.json new file mode 100644 index 0000000000..2c1f86ee68 --- /dev/null +++ b/types/reach__dialog/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "paths": { + "@reach/dialog": ["reach__dialog"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "reach__dialog-tests.tsx" + ] +} diff --git a/types/reach__dialog/tslint.json b/types/reach__dialog/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/reach__dialog/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }