Add types/tests for @reach/combobox (#36379)

This commit is contained in:
Harry Hedger 2019-06-28 09:40:36 -07:00 committed by Ben Lichtman
parent e99c4f4e51
commit dcd243fdd8
4 changed files with 109 additions and 0 deletions

44
types/reach__combobox/index.d.ts vendored Normal file
View File

@ -0,0 +1,44 @@
// Type definitions for @reach/combobox 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 type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export interface ComboboxProps extends Omit<React.HTMLProps<HTMLElement>, 'onSelect'> {
children?: React.ReactNode;
onSelect?: (value: string) => void;
openOnFocus?: boolean;
as?: string;
}
export interface ComboboxInputProps extends React.HTMLProps<HTMLElement> {
selectOnClick?: boolean;
autocomplete?: boolean;
value?: string;
as?: string;
}
export interface ComboboxPopoverProps extends React.HTMLProps<HTMLElement> {
portal?: boolean;
}
export interface ComboboxListProps extends React.HTMLProps<HTMLElement> {
persistSelection?: boolean;
as?: string;
}
export interface ComboboxOptionProps extends React.HTMLProps<HTMLElement> {
children?: React.ReactNode;
value: string;
}
export const Combobox: React.FC<ComboboxProps>;
export const ComboboxInput: React.FC<ComboboxInputProps>;
export const ComboboxPopover: React.FC<ComboboxPopoverProps>;
export const ComboboxList: React.FC<ComboboxListProps>;
export const ComboboxOption: React.FC<ComboboxOptionProps>;
export const ComboboxOptionText: React.FC;

View File

@ -0,0 +1,36 @@
import {
Combobox,
ComboboxInput,
ComboboxPopover,
ComboboxList,
ComboboxOption,
ComboboxOptionText,
} from '@reach/combobox';
import * as React from 'react';
import { render } from 'react-dom';
const GoodExample = () => (
<Combobox>
<ComboboxInput aria-labelledby="demo" />
<ComboboxPopover>
<ComboboxList aria-labelledby="demo">
<ComboboxOption value="Apple" />
<ComboboxOption value="Banana" />
<ComboboxOption value="Orange" />
<ComboboxOption value="Pineapple" />
<ComboboxOption value="Kiwi" />
</ComboboxList>
</ComboboxPopover>
</Combobox>
);
render(<GoodExample />, document.getElementById('app'));
render(<Combobox />, document.getElementById('app'));
render(<ComboboxInput />, document.getElementById('app'));
render(<ComboboxPopover />, document.getElementById('app'));
render(<ComboboxList />, document.getElementById('app'));
render(<ComboboxOptionText />, document.getElementById('app'));
// $ExpectError
render(<ComboboxOption />, document.getElementById('app'));

View File

@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"paths": {
"@reach/combobox": ["reach__combobox"]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"reach__combobox-tests.tsx"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }