From 9786a8c8e490a0c9439e080c4d1ccdf328a9c7e9 Mon Sep 17 00:00:00 2001 From: arichter83 Date: Wed, 5 Dec 2018 13:51:45 +0100 Subject: [PATCH 1/4] Minor additions to Highlighter --- types/react-bootstrap-typeahead/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/react-bootstrap-typeahead/index.d.ts b/types/react-bootstrap-typeahead/index.d.ts index 2c0495ce03..52f99825d5 100644 --- a/types/react-bootstrap-typeahead/index.d.ts +++ b/types/react-bootstrap-typeahead/index.d.ts @@ -191,8 +191,9 @@ export interface AsyncTypeaheadProps extends TypeaheadProps { export const AsyncTypeahead: React.ClassicComponentClass>; export interface HighligherProps { - key: string; + key?: string; search: string; + optionId?: any; } export const Highlighter: React.ClassicComponentClass>; From 0b98134ca59e2cc6430b5bd8a9b212b715cc59fe Mon Sep 17 00:00:00 2001 From: arichter83 Date: Mon, 17 Dec 2018 12:47:11 +0100 Subject: [PATCH 2/4] Add new example wit deconstructed argument --- .../react-bootstrap-typeahead-tests.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx b/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx index 5fcbe15328..c77052a3c6 100644 --- a/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx +++ b/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx @@ -36,13 +36,21 @@ class BasicExample extends React.Component { filterBy={(option, props) => (props.text.indexOf(option) !== -1) } placeholder="Choose a state..." /> + (text.indexOf(option) !== -1) } + placeholder="Choose a state..." + /> - {option.name} + {option.name} {index} } /> From 868b2bb6fa0abf0b635853fee9e5a9885274a2e3 Mon Sep 17 00:00:00 2001 From: arichter83 Date: Mon, 17 Dec 2018 12:59:23 +0100 Subject: [PATCH 3/4] Add filterBy --- types/react-bootstrap-typeahead/index.d.ts | 24 +++++++++++++++---- .../react-bootstrap-typeahead-tests.tsx | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/types/react-bootstrap-typeahead/index.d.ts b/types/react-bootstrap-typeahead/index.d.ts index 6e5fc2cbf0..52f99825d5 100644 --- a/types/react-bootstrap-typeahead/index.d.ts +++ b/types/react-bootstrap-typeahead/index.d.ts @@ -1,13 +1,29 @@ -// Type definitions for react-bootstrap-typeahead 3.2 +// Type definitions for react-bootstrap-typeahead 3.4 // Project: https://github.com/ericgio/react-bootstrap-typeahead // Definitions by: Guymestef // Rajab Shakirov // Paito Anderson +// Andreas Richter // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -// TODO: , , , components +// TODO: components import * as React from 'react'; +import * as CSS from 'csstype'; + +export interface TypeaheadFilterbyProps { + filterBy: string[]; + labelKey: (string | (() => void)); + multiple: boolean; + selected: any[]; + caseSensitive: boolean; + ignoreDiacritics: boolean; + text: string; +} + +export interface TypeaheadMenuProps { + text: string; +} export interface TypeaheadProps { /* For localized accessibility: Should return a string indicating the number of results for screen readers. Receives the current results. */ @@ -58,7 +74,7 @@ export interface TypeaheadProps { emptyLabel?: string; /* Either an array of fields in option to search, or a custom filtering callback. */ - filterBy?: (string[] | ((option: T | string, text: string) => boolean)); + filterBy?: (string[] | ((option: T | string, props: TypeaheadFilterbyProps) => boolean)); /* Highlights the menu item if there is only one result and allows selecting that item by hitting enter. Does not work with allowNew. */ @@ -138,7 +154,7 @@ export interface TypeaheadProps { renderMenu?: (results: Array, menuProps: any) => any; /* Provides a hook for customized rendering of menu item contents. */ - renderMenuItemChildren?: (option: T, props: TypeaheadProps, index: number) => any; + renderMenuItemChildren?: (option: T, props: TypeaheadMenuProps, index: number) => any; /* Provides a hook for customized rendering of tokens when multiple selections are enabled. */ renderToken?: (selectedItem: T | string, onRemove: () => void) => any; diff --git a/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx b/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx index 6f302b4a55..c77052a3c6 100644 --- a/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx +++ b/types/react-bootstrap-typeahead/react-bootstrap-typeahead-tests.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { Typeahead } from 'react-bootstrap-typeahead'; +import { Typeahead, Highlighter, Menu, MenuItem } from 'react-bootstrap-typeahead'; const options = [ { name: 'Alabama', population: 4780127, capital: 'Montgomery', region: 'South' }, From 47e2865b69936e5d18bf9810c4141206142b8fc2 Mon Sep 17 00:00:00 2001 From: arichter83 Date: Mon, 17 Dec 2018 20:32:49 +0100 Subject: [PATCH 4/4] Missing CSSType --- types/react-bootstrap-typeahead/package.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 types/react-bootstrap-typeahead/package.json diff --git a/types/react-bootstrap-typeahead/package.json b/types/react-bootstrap-typeahead/package.json new file mode 100644 index 0000000000..e6696d08e7 --- /dev/null +++ b/types/react-bootstrap-typeahead/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "csstype": "^2.2.0" + } +}