|
| 1 | +import React, { PropsWithChildren } from 'react'; |
| 2 | +import { FlatListProps, StyleProp, ViewStyle, TextInputProps, TextStyle } from 'react-native'; |
| 3 | +import { ExpandableOverlayProps } from '../../incubator/expandableOverlay'; |
| 4 | +import { ModalTopBarProps } from '../modal/TopBar'; |
| 5 | +export declare enum PickerModes { |
| 6 | + SINGLE = "SINGLE", |
| 7 | + MULTI = "MULTI" |
| 8 | +} |
| 9 | +declare type PickerValueDeprecated = { |
| 10 | + value: string | number; |
| 11 | + label: string; |
| 12 | +}; |
| 13 | +export declare type PickerSingleValue = string | number | PickerValueDeprecated; |
| 14 | +export declare type PickerMultiValue = PickerSingleValue[]; |
| 15 | +export declare type PickerValue = PickerSingleValue | PickerMultiValue; |
| 16 | +export interface PickerSearchStyle { |
| 17 | + icon?: number; |
| 18 | + color?: string; |
| 19 | + placeholderTextColor?: string; |
| 20 | + selectionColor?: string; |
| 21 | +} |
| 22 | +export interface PickerBaseProps extends Omit<TextInputProps, 'value' | 'onChange'> { |
| 23 | + /** |
| 24 | + * Temporary prop required for migration to Picker's new API |
| 25 | + */ |
| 26 | + migrate?: boolean; |
| 27 | + /** |
| 28 | + * Temporary prop required for inner text field migration |
| 29 | + */ |
| 30 | + migrateTextField?: boolean; |
| 31 | + /** |
| 32 | + * Picker current value in the shape of {value: ..., label: ...}, for custom shape use 'getItemValue' prop |
| 33 | + */ |
| 34 | + value?: PickerValue; |
| 35 | + /** |
| 36 | + * Callback for when picker value change |
| 37 | + */ |
| 38 | + onChange?: (value: PickerValue) => void; |
| 39 | + /** |
| 40 | + * SINGLE mode or MULTI mode |
| 41 | + */ |
| 42 | + mode?: PickerModes; |
| 43 | + /** |
| 44 | + * Limit the number of selected items |
| 45 | + */ |
| 46 | + selectionLimit?: number; |
| 47 | + /** |
| 48 | + * Adds blur effect to picker modal (iOS only) |
| 49 | + */ |
| 50 | + enableModalBlur?: boolean; |
| 51 | + /** |
| 52 | + * Render custom picker - input will be value (see above) |
| 53 | + * Example: |
| 54 | + * renderPicker = (selectedItem) => {...} |
| 55 | + */ |
| 56 | + renderPicker?: (value?: PickerValue, label?: string) => React.ReactElement; |
| 57 | + /** |
| 58 | + * Render custom picker item |
| 59 | + */ |
| 60 | + renderItem?: (value: PickerValue, itemProps: PickerItemProps & { |
| 61 | + isSelected: boolean; |
| 62 | + }, label: string) => React.ReactElement; |
| 63 | + /** |
| 64 | + * Render custom picker modal (e.g ({visible, children, toggleModal}) => {...}) |
| 65 | + */ |
| 66 | + renderCustomModal?: (modalProps: ExpandableOverlayProps['modalProps']) => React.ReactElement; |
| 67 | + /** |
| 68 | + * Custom picker props (when using renderPicker, will apply on the button wrapper) |
| 69 | + */ |
| 70 | + customPickerProps?: ExpandableOverlayProps; |
| 71 | + /** |
| 72 | + * Add onPress callback for when pressing the picker |
| 73 | + */ |
| 74 | + onPress?: () => void; |
| 75 | + /** |
| 76 | + * @deprecated |
| 77 | + * A function that extract the unique value out of the value prop in case value has a custom structure (e.g. {myValue, myLabel}) |
| 78 | + */ |
| 79 | + getItemValue?: (value: PickerValue) => any; |
| 80 | + /** |
| 81 | + * @deprecated |
| 82 | + * A function that extract the label out of the value prop in case value has a custom structure (e.g. {myValue, myLabel}) |
| 83 | + */ |
| 84 | + getItemLabel?: (value: PickerValue) => string; |
| 85 | + /** |
| 86 | + * A function that returns the label to show for the selected Picker value |
| 87 | + */ |
| 88 | + getLabel?: (value: PickerValue) => string; |
| 89 | + /** |
| 90 | + * The picker modal top bar props |
| 91 | + */ |
| 92 | + topBarProps?: ModalTopBarProps; |
| 93 | + /** |
| 94 | + * Show search input to filter picker items by label |
| 95 | + */ |
| 96 | + showSearch?: boolean; |
| 97 | + /** |
| 98 | + * Style object for the search input (only when passing showSearch) |
| 99 | + */ |
| 100 | + searchStyle?: PickerSearchStyle; |
| 101 | + /** |
| 102 | + * Placeholder text for the search input (only when passing showSearch) |
| 103 | + */ |
| 104 | + searchPlaceholder?: string; |
| 105 | + /** |
| 106 | + * callback for picker modal search input text change (only when passing showSearch) |
| 107 | + */ |
| 108 | + onSearchChange?: (searchValue: string) => void; |
| 109 | + /** |
| 110 | + * Render custom search input (only when passing showSearch) |
| 111 | + */ |
| 112 | + renderCustomSearch?: (props: PickerItemsListProps) => React.ReactElement; |
| 113 | + /** |
| 114 | + * Allow to use the native picker solution (different style for iOS and Android) |
| 115 | + */ |
| 116 | + useNativePicker?: boolean; |
| 117 | + /** |
| 118 | + * Callback for rendering a custom native picker inside the dialog (relevant to native picker only) |
| 119 | + */ |
| 120 | + renderNativePicker?: () => React.ReactElement; |
| 121 | + /** |
| 122 | + * Pass props to the list component that wraps the picker options (allows to control FlatList behavior) |
| 123 | + */ |
| 124 | + listProps?: FlatListProps<any>; |
| 125 | + /** |
| 126 | + * Pass props to the picker modal |
| 127 | + */ |
| 128 | + pickerModalProps?: object; |
| 129 | + /** |
| 130 | + * Custom container style |
| 131 | + */ |
| 132 | + containerStyle?: StyleProp<ViewStyle>; |
| 133 | + /** |
| 134 | + * Callback for modal onShow event |
| 135 | + */ |
| 136 | + onShow?: () => void; |
| 137 | + /** |
| 138 | + * Component test id |
| 139 | + */ |
| 140 | + testID?: string; |
| 141 | +} |
| 142 | +export interface PickerPropsWithSingle extends PickerBaseProps { |
| 143 | + mode: PickerModes.SINGLE; |
| 144 | + value: PickerSingleValue; |
| 145 | +} |
| 146 | +export interface PickerPropsWithMulti extends PickerBaseProps { |
| 147 | + mode: PickerModes.MULTI; |
| 148 | + value: PickerMultiValue; |
| 149 | +} |
| 150 | +export declare type PickerProps = PickerPropsWithSingle | PickerPropsWithMulti; |
| 151 | +export interface PickerItemProps { |
| 152 | + /** |
| 153 | + * Item's value |
| 154 | + */ |
| 155 | + value: PickerSingleValue; |
| 156 | + /** |
| 157 | + * Item's label |
| 158 | + */ |
| 159 | + label: string; |
| 160 | + /** |
| 161 | + * Item's label style |
| 162 | + */ |
| 163 | + labelStyle?: StyleProp<TextStyle>; |
| 164 | + /** |
| 165 | + * Custom function for the item label (e.g (value) => customLabel) |
| 166 | + */ |
| 167 | + getItemLabel: PickerProps['getItemLabel']; |
| 168 | + /** |
| 169 | + * @deprecated Function to return the value out of the item value prop when value is custom shaped. |
| 170 | + */ |
| 171 | + getItemValue: PickerProps['getItemValue']; |
| 172 | + /** |
| 173 | + * Render custom item |
| 174 | + */ |
| 175 | + renderItem?: PickerProps['renderItem']; |
| 176 | + /** |
| 177 | + * Pass to change the selected icon |
| 178 | + */ |
| 179 | + selectedIcon?: number; |
| 180 | + /** |
| 181 | + * Pass to change the selected icon color |
| 182 | + */ |
| 183 | + selectedIconColor?: string; |
| 184 | + /** |
| 185 | + * Is the item disabled |
| 186 | + */ |
| 187 | + disabled?: boolean; |
| 188 | + /** |
| 189 | + * Callback for onPress action |
| 190 | + */ |
| 191 | + onPress: () => void; |
| 192 | + /** |
| 193 | + * Component test id |
| 194 | + */ |
| 195 | + testID?: string; |
| 196 | +} |
| 197 | +export interface PickerContextProps extends Pick<PickerProps, 'migrate' | 'value' | 'getItemValue' | 'getItemLabel' | 'renderItem' | 'selectionLimit'> { |
| 198 | + onPress: (value: PickerSingleValue) => void; |
| 199 | + isMultiMode: boolean; |
| 200 | + onSelectedLayout: (event: any) => any; |
| 201 | + selectionLimit: PickerProps['selectionLimit']; |
| 202 | +} |
| 203 | +export declare type PickerItemsListProps = Pick<PropsWithChildren<PickerProps>, 'topBarProps' | 'listProps' | 'children' | 'showSearch' | 'searchStyle' | 'searchPlaceholder' | 'onSearchChange' | 'renderCustomSearch' | 'testID'>; |
| 204 | +export {}; |
0 commit comments