Skip to content

Refactor: Updated type definitions in 'react-native-select-dropdown' … #147

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 2 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 12 additions & 12 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import type * as React from 'react';
import {StyleProp, ViewStyle, TextStyle} from 'react-native';

declare module 'react-native-select-dropdown' {
export type SelectDropdownProps = {
export type SelectDropdownProps<T> = {
/**
* array of data that will be represented in dropdown, can be array of objects
*/
data: Array<any>;
data: Array<T>;
/**
* function recieves selected item and its index in data array
*/
onSelect: (selectedItem: any, index: number) => void;
onSelect: (selectedItem: T, index: number) => void;
/**
* default button text when no item is selected
*/
defaultButtonText?: string;
/**
* default selected item in dropdown
*/
defaultValue?: any;
defaultValue?: T;
/**
* default selected item index
*/
Expand Down Expand Up @@ -58,7 +58,7 @@ declare module 'react-native-select-dropdown' {
/**
* function that should return a React component for dropdown icon
*/
renderDropdownIcon?: (selectedItem: any, index: number) => React.ReactNode;
renderDropdownIcon?: (selectedItem: T, index: number) => React.ReactNode;
/**
* dropdown icon position "left" || "right"
*/
Expand Down Expand Up @@ -126,41 +126,41 @@ declare module 'react-native-select-dropdown' {
/**
* function returns React component for search input icon
*/
renderSearchInputLeftIcon?: (selectedItem: any, index: number) => React.ReactNode;
renderSearchInputLeftIcon?: (selectedItem: T, index: number) => React.ReactNode;
/**
* function returns React component for search input icon
*/
renderSearchInputRightIcon?: (selectedItem: any, index: number) => React.ReactNode;
renderSearchInputRightIcon?: (selectedItem: T, index: number) => React.ReactNode;
} & (
| {
/**
* function recieves selected item and its index, this function should return a string that will be represented in button after item is selected
*/
buttonTextAfterSelection: (selectedItem: any, index: number) => string;
buttonTextAfterSelection: (selectedItem: T, index: number) => string;
}
| {
/**
* function recieves selected item and its index, this function should return a React component as a child for dropdown button buttonStyle should be used for parent button view style.
*/
renderCustomizedButtonChild?: (selectedItem: any, index: number) => React.ReactNode;
renderCustomizedButtonChild?: (selectedItem: T, index: number) => React.ReactNode;
}
) &
(
| {
/**
* function recieves item and index for each row in dropdown, this function shoud return a string that will be represented in each row in dropdown
*/
rowTextForSelection: (item: any, index: number) => string;
rowTextForSelection: (item: T, index: number) => string;
}
| {
/**
* function recieves item and its index, this function should return React component as a child for customized row rowStyle should be used for parent row view style.
*/
renderCustomizedRowChild?: (selectedItem: any, index: number, isSelected?: boolean) => React.ReactNode;
renderCustomizedRowChild?: (selectedItem: T, index: number, isSelected?: boolean) => React.ReactNode;
}
);

export default class SelectDropdown extends React.Component<SelectDropdownProps> {
export default class SelectDropdown<T> extends React.Component<SelectDropdownProps<T>> {
/**
* Remove selection & reset it to display defaultButtonText check
*/
Expand Down