From e7e3d0f57db0dc0b21da9f0bbbb37438740ece7a Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Thu, 27 Jun 2019 17:12:07 -0700 Subject: [PATCH] Add types and tests for @reach/tabs (#36378) --- types/reach__tabs/index.d.ts | 40 +++++++++++++++++ types/reach__tabs/reach__tabs-tests.tsx | 57 +++++++++++++++++++++++++ types/reach__tabs/tsconfig.json | 28 ++++++++++++ types/reach__tabs/tslint.json | 1 + 4 files changed, 126 insertions(+) create mode 100644 types/reach__tabs/index.d.ts create mode 100644 types/reach__tabs/reach__tabs-tests.tsx create mode 100644 types/reach__tabs/tsconfig.json create mode 100644 types/reach__tabs/tslint.json diff --git a/types/reach__tabs/index.d.ts b/types/reach__tabs/index.d.ts new file mode 100644 index 0000000000..75aef88011 --- /dev/null +++ b/types/reach__tabs/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for @reach/tabs 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 Omit = Pick>; + +export interface TabsProps extends Omit, 'onChange'> { + children: React.ReactNode; + as?: string; + index?: number; + readOnly?: boolean; + defaultIndex?: number; + onChange?: (index: number) => void; +} + +export interface TabContainerProps extends React.HTMLProps { + children?: React.ReactNode; + selectedIndex?: number; + as?: string; +} + +export interface TabPanelProps extends React.HTMLProps { + children?: React.ReactNode; + isSelected?: boolean; + as?: string; +} + +export interface TabProps extends TabPanelProps { + disabled?: boolean; +} + +export const Tabs: React.FC; +export const TabList: React.FC; +export const TabPanels: React.FC; +export const Tab: React.FC; +export const TabPanel: React.FC; diff --git a/types/reach__tabs/reach__tabs-tests.tsx b/types/reach__tabs/reach__tabs-tests.tsx new file mode 100644 index 0000000000..7020be05fa --- /dev/null +++ b/types/reach__tabs/reach__tabs-tests.tsx @@ -0,0 +1,57 @@ +import { Tabs, TabList, Tab, TabPanels, TabPanel } from '@reach/tabs'; + +import * as React from 'react'; +import { render } from 'react-dom'; + +const BasicTabs = () => { + return ( + <> + + + One + Two + + + + +

one!

+
+ +

two!

+
+
+
+ + ); +}; + +const TabsWithProps = () => { + const [tabIndex, setTabIndex] = React.useState(0); + + return ( + + + Foo + Bar + Baz + Bat + + + {tabIndex} + Bar + Baz + Bat + + + ); +}; + +render(, document.getElementById('app')); +render(, document.getElementById('app')); +render(, document.getElementById('app')); +render(, document.getElementById('app')); +render(, document.getElementById('app')); +render(, document.getElementById('app')); + +// $ExpectError +render(, document.getElementById('app')); diff --git a/types/reach__tabs/tsconfig.json b/types/reach__tabs/tsconfig.json new file mode 100644 index 0000000000..1d4af269ac --- /dev/null +++ b/types/reach__tabs/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "paths": { + "@reach/tabs": ["reach__tabs"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "reach__tabs-tests.tsx" + ] +} diff --git a/types/reach__tabs/tslint.json b/types/reach__tabs/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/reach__tabs/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }