Skip to content

feat(41): TypeScript support #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
148 changes: 148 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
declare module 'react-native-searchable-dropdown' {
import { Component, ReactNode } from "react";
import {TextInputProps, ViewStyle, FlatListProps, ViewProps, FlatList} from "react-native";

export type ItemType = {
id: any,
name?: string
}

/**
* SearchableDropdownProps
* @alias SearchableDropdownProps
*/
export type SearchableDropdownProps<T extends ItemType = ItemType> = ViewProps & {
/**
* dropdown items
*/
items: T[],

/**
* default selected index of items.
*/
defaultIndex?: number,

/**
* called when the input receives focus.
*/
onFocus?: () => void,

/**
* called when the focus moves to another component.
*/
onBlur?: () => void,

/**
* on text change you can pass onTextChange and catch the input text.
*/
onTextChange?: (text: string) => void,

/**
* on item selection you can pass onItemSelect and catch the input item.
*/
onItemSelect?: (item: T) => void,

/**
* component container style
*/
containerStyle?: ViewStyle,

/**
* TextInput style
*/
textInputStyle?: ViewStyle,

/**
* items on dropdown
*/
itemStyle?: ViewStyle,

/**
* item text
*/
itemTextStyle?: ViewStyle,

/**
* reset textInput Value with true and false state
*/
resetValue?: boolean,

/**
* textInput placeholder
*/
placeholder?: string,

/**
* textInput placeholderTextColor
*/
placeholderTextColor?: string,

/**
* items container style you can pass maxHeight to restrict the items dropdown height
*/
itemsContainerStyle?: ViewStyle,

/**
* TextInput underline height
*/
underlineColorAndroid?: string,

/**
* all supported (FlatList) props
* @example listProps={ nestedScrollEnabled: true }
*/
listProps?: Partial<FlatListProps<T>>,

/**
* all supported (TextInput) props
* @example textInputProps={ underlineColorAndroid: 'transparent' }
*/
textInputProps?: TextInputProps,

/**
* filter data on text changing
* @example setSort={(item, searchedText)=> item.name.toLowerCase().startsWith(searchedText.toLowerCase())}
*/
setSort?: (item: T, searchedText: string) => boolean,

/**
* toggle multi selection
*/
multi?: boolean,

/**
* selectedItems of multi selection
* <br><b>note:</b> work when if multi prop is true
*/
selectedItems?: T[],

/**
* toggle chip display mode
* <br><b>note:</b> work when if multi prop is true
*/
chip?: boolean,

/**
* { (item, index) => { } }
* <br><b>note:</b> work when if multi prop is true
*/
onRemoveItem?: (item: T, index: number) => void
}

export type SearchableDropdownState<T extends ItemType = ItemType> = {
item: Partial<T>,
listItems: T[],
focus: boolean
}

export default class SearchableDropdown<T extends ItemType = ItemType>
extends Component<SearchableDropdownProps<T>, SearchableDropdownState<T>> {

renderFlatList(): FlatList;

renderItems(item: T, index: number): ReactNode;

renderSelectedItems(): ReactNode;
}

}
Loading