Skip to content

Commit

Permalink
fix(combobox): genericise some prop iterfaces for friendlier typings
Browse files Browse the repository at this point in the history
  • Loading branch information
SiTaggart committed Jan 25, 2021
1 parent 79294f0 commit 66f3174
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/paste-core/components/combobox/src/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {ComboboxListbox} from './ComboboxListbox';
import {ComboboxListboxGroup} from './ComboboxListboxGroup';
import {ComboboxListboxOption} from './ComboboxListboxOption';
import {getIndexedItems, getGroupedItems} from './helpers';
import type {GroupItemsProps, Item as ItemType, ItemProps, ItemsProps, ListBoxProps, ComboboxProps} from './types';
import type {GroupItemsProps, ItemProps, ItemsProps, ListBoxProps, ComboboxProps} from './types';

// Fixes chevron overlapping really long text
// Extra right padding is removed when autocomplete is true
Expand Down
28 changes: 16 additions & 12 deletions packages/paste-core/components/combobox/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@ import type {InputVariants, InputProps} from '@twilio-paste/input';

export type Item = string | {[key: string]: any};

export interface OptionTemplateFn<ProvidedItem> {
(item: ProvidedItem): React.ReactNode;
}

export interface ComboboxProps extends Omit<InputProps, 'id' | 'type' | 'value'> {
autocomplete?: boolean;
helpText?: string | React.ReactNode;
initialIsOpen?: UseComboboxPrimitiveProps<Item>['initialIsOpen'];
initialSelectedItem?: UseComboboxPrimitiveProps<Item>['initialSelectedItem'];
items: UseComboboxPrimitiveProps<Item>['items'];
itemToString?: UseComboboxPrimitiveProps<Item>['itemToString'];
initialIsOpen?: UseComboboxPrimitiveProps<any>['initialIsOpen'];
initialSelectedItem?: UseComboboxPrimitiveProps<any>['initialSelectedItem'];
items: UseComboboxPrimitiveProps<any>['items'];
itemToString?: UseComboboxPrimitiveProps<any>['itemToString'];
labelText: string | NonNullable<React.ReactNode>;
onHighlightedIndexChange?: UseComboboxPrimitiveProps<Item>['onHighlightedIndexChange'];
onInputValueChange?: UseComboboxPrimitiveProps<Item>['onInputValueChange'];
onIsOpenChange?: UseComboboxPrimitiveProps<Item>['onIsOpenChange'];
onSelectedItemChange?: UseComboboxPrimitiveProps<Item>['onSelectedItemChange'];
optionTemplate?: (item: string | Item) => React.ReactNode;
onHighlightedIndexChange?: UseComboboxPrimitiveProps<any>['onHighlightedIndexChange'];
onInputValueChange?: UseComboboxPrimitiveProps<any>['onInputValueChange'];
onIsOpenChange?: UseComboboxPrimitiveProps<any>['onIsOpenChange'];
onSelectedItemChange?: UseComboboxPrimitiveProps<any>['onSelectedItemChange'];
optionTemplate?: OptionTemplateFn<any>;
groupLabelTemplate?: (groupName: string) => React.ReactNode;
selectedItem?: UseComboboxPrimitiveProps<Item>['selectedItem'];
inputValue?: UseComboboxPrimitiveProps<Item>['inputValue'];
selectedItem?: UseComboboxPrimitiveProps<any>['selectedItem'];
inputValue?: UseComboboxPrimitiveProps<any>['inputValue'];
groupItemsBy?: string;
variant?: InputVariants;
state?: Partial<UseComboboxPrimitiveReturnValue<Item>>;
state?: Partial<UseComboboxPrimitiveReturnValue<any>>;
}

export interface ItemProps extends Pick<ComboboxProps, 'optionTemplate'> {
Expand Down

0 comments on commit 66f3174

Please sign in to comment.