From 31a2c8c5e5a706f2c1a1855adde19499c80b3225 Mon Sep 17 00:00:00 2001 From: nossbigg Date: Sat, 2 Feb 2019 12:39:59 +0800 Subject: [PATCH] Add typings for react-native-modal-filter-picker --- .../index.d.ts | 61 ++++++++++++++++++ ...react-native-modal-filter-picker-tests.tsx | 64 +++++++++++++++++++ .../tsconfig.json | 17 +++++ .../tslint.json | 1 + 4 files changed, 143 insertions(+) create mode 100644 types/react-native-modal-filter-picker/index.d.ts create mode 100644 types/react-native-modal-filter-picker/react-native-modal-filter-picker-tests.tsx create mode 100644 types/react-native-modal-filter-picker/tsconfig.json create mode 100644 types/react-native-modal-filter-picker/tslint.json diff --git a/types/react-native-modal-filter-picker/index.d.ts b/types/react-native-modal-filter-picker/index.d.ts new file mode 100644 index 0000000000..8188a32319 --- /dev/null +++ b/types/react-native-modal-filter-picker/index.d.ts @@ -0,0 +1,61 @@ +// Type definitions for react-native-modal-filter-picker 1.3 +// Project: https://github.com/hiddentao/react-native-modal-filter-picker#readme +// Definitions by: Chang Yanwei +// Cheng Gibson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import * as React from "react"; +import { + StyleProp, + ViewStyle, + TextStyle, + ListView, + KeyboardAvoidingView, + ModalProps, + ListViewProps +} from "react-native"; + +export interface ModalFilterPickerOption { + label: string; + key: string; +} + +export interface ModalFilterPickerProps { + options: T[]; + onSelect: (key: string) => void; + onCancel: () => void; + placeholderText?: string; + placeholderTextColor?: string; + androidUnderlineColor?: string; + cancelButtonText?: string; + title?: string; + noResultsText?: string; + visible?: boolean; + showFilter?: boolean; + modal?: ModalProps; + selectedOption?: string; + listViewProps?: Partial; + renderOption?: (option: T, isSelected: boolean) => JSX.Element; + renderList?: () => JSX.Element; + renderCancelButton?: () => JSX.Element; + keyboardShouldPersistTaps?: "never" | "always" | "handle"; + autoFocus?: boolean; + + // styling props + overlayStyle?: StyleProp; + listContainerStyle?: StyleProp; + filterTextInputContainerStyle?: StyleProp; + filterTextInputStyle?: StyleProp; + cancelContainerStyle?: StyleProp; + cancelButtonStyle?: StyleProp; + cancelButtonTextStyle?: StyleProp; + titleTextStyle?: StyleProp; + optionTextStyle?: StyleProp; +} + +declare class ModalFilterPicker< + T extends ModalFilterPickerOption +> extends React.Component> {} + +export default ModalFilterPicker; diff --git a/types/react-native-modal-filter-picker/react-native-modal-filter-picker-tests.tsx b/types/react-native-modal-filter-picker/react-native-modal-filter-picker-tests.tsx new file mode 100644 index 0000000000..05fc770e5a --- /dev/null +++ b/types/react-native-modal-filter-picker/react-native-modal-filter-picker-tests.tsx @@ -0,0 +1,64 @@ +import * as React from "react"; +import ModalFilterPicker, { + ModalFilterPickerOption +} from "react-native-modal-filter-picker"; +import { View, Button, Text } from "react-native"; + +interface MyModalFilterPickerOption extends ModalFilterPickerOption { + customField: string; +} + +const modalFilterPickerOptions: MyModalFilterPickerOption[] = [ + { + label: "some-label-1", + key: "some-key-1", + customField: "some-customfield-1" + }, + { + label: "some-label-2", + key: "some-key-2", + customField: "some-customfield-2" + } +]; + +const renderPicker = () => ( + { + console.log(key); + }} + onCancel={() => {}} + placeholderText="Filter..." + placeholderTextColor="#ccc" + androidUnderlineColor="rgba(0,0,0,0)" + cancelButtonText="Cancel" + title="some-title" + noResultsText="No matches" + visible + showFilter + modal={{ animated: true }} + selectedOption="some-option-key" + listViewProps={{ accessible: true }} + renderOption={(option, isSelected) => ( + + + `${option.label} ${option.customField} ${isSelected}` + + + )} + renderList={() => } + renderCancelButton={() =>