index.d.ts 5.06 KB
Newer Older
Kyle Roach's avatar
Kyle Roach committed
1 2 3 4 5 6 7
// Type definitions for react-native-picker
// Project: https://github.com/beefe/react-native-picker
// Definitions by: Kyle Roach <https://github.com/iRoachie>
// TypeScript Version: 2.3.2

/**
 * Options to create a picker object
8
 *
Kyle Roach's avatar
Kyle Roach committed
9 10 11 12 13
 * @interface PickerOptions
 */
interface PickerOptions {
    /**
     * Items to be passed into the picker
14
     *
Kyle Roach's avatar
Kyle Roach committed
15
     * Default is an empty array
16
     *
Kyle Roach's avatar
Kyle Roach committed
17 18 19 20 21 22 23
     * @type {any[]}
     * @memberof PickerOptions
     */
    pickerData?: any[]

    /**
     * The selected item in the picker
24
     *
Kyle Roach's avatar
Kyle Roach committed
25 26
     * Accepts the item in an array
     * Example: ['selected']
27
     *
Kyle Roach's avatar
Kyle Roach committed
28
     * Default is an empty array
29
     *
Kyle Roach's avatar
Kyle Roach committed
30 31 32 33 34 35 36
     * @type {any[]}
     * @memberof PickerOptions
     */
    selectedValue?: any[]

    /**
     * Title text shown at the top of the picker
37
     *
Kyle Roach's avatar
Kyle Roach committed
38
     * Default value is 'pls select'
39
     *
Kyle Roach's avatar
Kyle Roach committed
40 41 42 43 44 45 46
     * @type {string}
     * @memberof PickerOptions
     */
    pickerTitleText?: string

    /**
     * Text for the confirm button
47
     *
Kyle Roach's avatar
Kyle Roach committed
48
     * Default value is 'confirm'
49
     *
Kyle Roach's avatar
Kyle Roach committed
50 51 52 53 54 55 56
     * @type {string}
     * @memberof PickerOptions
     */
    pickerConfirmBtnText?: string

    /**
     * Text for the cancel button
57
     *
Kyle Roach's avatar
Kyle Roach committed
58
     * Default value is 'cancel'
59
     *
Kyle Roach's avatar
Kyle Roach committed
60 61 62 63 64 65 66
     * @type {string}
     * @memberof PickerOptions
     */
    pickerCancelBtnText: string

    /**
     * The color of the text for the confirm button
67
     *
Kyle Roach's avatar
Kyle Roach committed
68 69
     * Accepts rgba values as an array
     * [R, G, B, A]
70
     *
Kyle Roach's avatar
Kyle Roach committed
71
     * Default is [1, 186, 245, 1]
72
     *
Kyle Roach's avatar
Kyle Roach committed
73 74 75 76 77 78 79
     * @type {number[]}
     * @memberof PickerOptions
     */
    pickerConfirmBtnColor?: number[]

    /**
     * The color of the text for the cancel button
80
     *
Kyle Roach's avatar
Kyle Roach committed
81 82
     * Accepts rgba values as an array
     * [R, G, B, A]
83
     *
Kyle Roach's avatar
Kyle Roach committed
84
     * Default is [1, 186, 245, 1]
85
     *
Kyle Roach's avatar
Kyle Roach committed
86 87 88 89 90 91 92
     * @type {number[]}
     * @memberof PickerOptions
     */
    pickerCancelBtnColor?: number[]

    /**
     * The color of the Title text
93
     *
Kyle Roach's avatar
Kyle Roach committed
94 95
     * Accepts rgba values as an array
     * [R, G, B, A]
96
     *
Kyle Roach's avatar
Kyle Roach committed
97
     * Default is [20, 20, 20, 1]
98
     *
Kyle Roach's avatar
Kyle Roach committed
99 100 101 102 103 104 105
     * @type {number[]}
     * @memberof PickerOptions
     */
    pickerTitleColor?: number[]

    /**
     * The background color of the toobar
106
     *
Kyle Roach's avatar
Kyle Roach committed
107 108
     * Accepts rgba values as an array
     * [R, G, B, A]
109
     *
Kyle Roach's avatar
Kyle Roach committed
110
     * Default is [232, 232, 232, 1]
111
     *
Kyle Roach's avatar
Kyle Roach committed
112 113 114 115 116 117 118
     * @type {number[]}
     * @memberof PickerOptions
     */
    pickerToolBarBg?: number[]

    /**
     * Background color of the picker
119
     *
Kyle Roach's avatar
Kyle Roach committed
120 121
     * Accepts rgba values as an array
     * [R, G, B, A]
122
     *
Kyle Roach's avatar
Kyle Roach committed
123
     * Default is [196, 199, 206, 1]
124
     *
Kyle Roach's avatar
Kyle Roach committed
125 126 127 128 129 130 131 132
     * @type {number[]}
     * @memberof PickerOptions
     */
    pickerBg?: number[]


    /**
     * Font size of the items in the toolbar
133
     *
Kyle Roach's avatar
Kyle Roach committed
134
     * Default is 16
135
     *
Kyle Roach's avatar
Kyle Roach committed
136 137 138 139 140 141 142
     * @type {number}
     * @memberof PickerOptions
     */
    pickerToolBarFontSize?: number

    /**
     * Font size of the items in the picker
143
     *
Kyle Roach's avatar
Kyle Roach committed
144
     * Default is 16
145
     *
Kyle Roach's avatar
Kyle Roach committed
146 147 148 149 150
     * @type {number}
     * @memberof PickerOptions
     */
    pickerFontSize?: number

151 152
    /**
     * Row height of the items in the picker
153
     *
154
     * Default is 24
155
     *
156 157 158 159 160
     * @type {number}
     * @memberof PickerOptions
     */
    pickerRowHeight?: number

Kyle Roach's avatar
Kyle Roach committed
161 162
    /**
     * Color of the text for the items in the picker
163
     *
Kyle Roach's avatar
Kyle Roach committed
164 165
     * Accepts rgba values as an array
     * [R, G, B, A]
166
     *
Kyle Roach's avatar
Kyle Roach committed
167
     * Default is [31, 31, 31, 1]
168
     *
Kyle Roach's avatar
Kyle Roach committed
169 170 171 172 173 174 175
     * @type {number[]}
     * @memberof PickerOptions
     */
    pickerFontColor?: number[]

    /**
     * Event fired when user confirms the picker
176
     *
Kyle Roach's avatar
Kyle Roach committed
177
     * Returns the selected item
178 179 180
     *
     * @param {any[]} item
     *
Kyle Roach's avatar
Kyle Roach committed
181 182 183 184 185 186
     * @memberof PickerOptions
     */
    onPickerConfirm?(item: any[]): void

    /**
     * Event fired when user cancels the picker
187
     *
Kyle Roach's avatar
Kyle Roach committed
188
     * Returns the selected item
189 190 191
     *
     * @param {any[]} item
     *
Kyle Roach's avatar
Kyle Roach committed
192 193 194 195 196 197 198
     * @memberof PickerOptions
     */
    onPickerCancel?(item: any[]): void


    /**
     * Event fired when user scrolls over or selects a value in the picker
199
     *
Kyle Roach's avatar
Kyle Roach committed
200
     * Returns the selected item
201 202 203
     *
     * @param {any[]} item
     *
Kyle Roach's avatar
Kyle Roach committed
204 205 206 207 208 209 210 211 212
     * @memberof PickerOptions
     */
    onPickerSelect?(item: any[]): void
}


export default class Picker {
    /**
     * Creates a new Picker objects
213
     *
Kyle Roach's avatar
Kyle Roach committed
214
     * @static
215 216
     * @param {PickerOptions} options
     *
Kyle Roach's avatar
Kyle Roach committed
217 218 219 220 221 222
     * @memberof Picker
     */
    static init(options: PickerOptions): void

    /**
     * Shows the picker
223
     *
Kyle Roach's avatar
Kyle Roach committed
224
     * @static
225
     *
Kyle Roach's avatar
Kyle Roach committed
226 227 228 229 230 231
     * @memberof Picker
     */
    static show(): void

    /**
     * Hides the picker
232
     *
Kyle Roach's avatar
Kyle Roach committed
233
     * @static
234
     *
Kyle Roach's avatar
Kyle Roach committed
235 236 237 238 239 240
     * @memberof Picker
     */
    static hide(): void

    /**
     * Toggles the visibility of the picker
241
     *
Kyle Roach's avatar
Kyle Roach committed
242
     * @static
243
     *
Kyle Roach's avatar
Kyle Roach committed
244 245 246 247 248 249
     * @memberof Picker
     */
    static toggle(): void

    /**
     * Sets an item in the picker as the selected value
250
     *
Kyle Roach's avatar
Kyle Roach committed
251 252
     * Accepts the item in an array
     * Example: ['selected']
253
     *
Kyle Roach's avatar
Kyle Roach committed
254
     * @static
255 256
     * @param {any[]} item
     *
Kyle Roach's avatar
Kyle Roach committed
257 258 259
     * @memberof Picker
     */
    static select(item: any[]): void
260

Kyle Roach's avatar
Kyle Roach committed
261 262
    /**
     * Checks if the picker is showing currently
263
     *
Kyle Roach's avatar
Kyle Roach committed
264
     * @static
265 266
     * @returns {boolean}
     *
Kyle Roach's avatar
Kyle Roach committed
267 268
     * @memberof Picker
     */
269 270
    static isPickerShow(fn?: (err: any, message: any) => void): boolean
}