1
- import _ from 'lodash'
2
1
import cx from 'classnames'
2
+ import _ from 'lodash'
3
3
import React , { Children , cloneElement , PropTypes } from 'react'
4
4
5
5
import {
@@ -18,23 +18,13 @@ import {
18
18
} from '../../lib'
19
19
import Icon from '../../elements/Icon'
20
20
import Label from '../../elements/Label'
21
-
22
21
import DropdownDivider from './DropdownDivider'
23
22
import DropdownItem from './DropdownItem'
24
23
import DropdownHeader from './DropdownHeader'
25
24
import DropdownMenu from './DropdownMenu'
26
25
27
26
const debug = makeDebugger ( 'dropdown' )
28
27
29
- const _meta = {
30
- name : 'Dropdown' ,
31
- type : META . TYPES . MODULE ,
32
- props : {
33
- pointing : [ 'left' , 'right' , 'top' , 'top left' , 'top right' , 'bottom' , 'bottom left' , 'bottom right' ] ,
34
- additionPosition : [ 'top' , 'bottom' ] ,
35
- } ,
36
- }
37
-
38
28
/**
39
29
* A dropdown allows a user to select a value from a series of options.
40
30
* @see Form
@@ -43,6 +33,18 @@ const _meta = {
43
33
*/
44
34
export default class Dropdown extends Component {
45
35
static propTypes = {
36
+ /** An element type to render as (string or function). */
37
+ as : customPropTypes . as ,
38
+
39
+ /** Label prefixed to an option added by a user. */
40
+ additionLabel : PropTypes . oneOfType ( [
41
+ PropTypes . element ,
42
+ PropTypes . string ,
43
+ ] ) ,
44
+
45
+ /** Position of the `Add: ...` option in the dropdown list ('top' or 'bottom'). */
46
+ additionPosition : PropTypes . oneOf ( [ 'top' , 'bottom' ] ) ,
47
+
46
48
/**
47
49
* Allow user additions to the list of options (boolean).
48
50
* Requires the use of `selection`, `options` and `search`.
@@ -52,19 +54,7 @@ export default class Dropdown extends Component {
52
54
PropTypes . bool ,
53
55
] ) ,
54
56
55
- /** Position of the `Add: ...` option in the dropdown list ('top' or 'bottom'). */
56
- additionPosition : PropTypes . oneOf ( _meta . props . additionPosition ) ,
57
-
58
- /** Label prefixed to an option added by a user. */
59
- additionLabel : PropTypes . oneOfType ( [
60
- PropTypes . element ,
61
- PropTypes . string ,
62
- ] ) ,
63
-
64
- /** An element type to render as (string or function). */
65
- as : customPropTypes . as ,
66
-
67
- /** A Dropdown can reduce its complexity */
57
+ /** A Dropdown can reduce its complexity. */
68
58
basic : PropTypes . bool ,
69
59
70
60
/** Format the Dropdown to appear as a button. */
@@ -102,15 +92,15 @@ export default class Dropdown extends Component {
102
92
defaultSelectedLabel : customPropTypes . every ( [
103
93
customPropTypes . demand ( [ 'multiple' ] ) ,
104
94
PropTypes . oneOfType ( [
105
- PropTypes . string ,
106
95
PropTypes . number ,
96
+ PropTypes . string ,
107
97
] ) ,
108
98
] ) ,
109
99
110
100
/** Initial value or value array if multiple. */
111
101
defaultValue : PropTypes . oneOfType ( [
112
- PropTypes . string ,
113
102
PropTypes . number ,
103
+ PropTypes . string ,
114
104
PropTypes . arrayOf ( PropTypes . oneOfType ( [
115
105
PropTypes . string ,
116
106
PropTypes . number ,
@@ -141,12 +131,12 @@ export default class Dropdown extends Component {
141
131
/** A dropdown can be formatted to appear inline in other content. */
142
132
inline : PropTypes . bool ,
143
133
144
- /** A dropdown can be labeled. */
145
- labeled : PropTypes . bool ,
146
-
147
134
/** A dropdown can be formatted as a Menu item. */
148
135
item : PropTypes . bool ,
149
136
137
+ /** A dropdown can be labeled. */
138
+ labeled : PropTypes . bool ,
139
+
150
140
/** A dropdown can show that it is currently loading data. */
151
141
loading : PropTypes . bool ,
152
142
@@ -184,60 +174,60 @@ export default class Dropdown extends Component {
184
174
onChange : PropTypes . func ,
185
175
186
176
/**
187
- * Called when a close event happens .
177
+ * Called on click .
188
178
*
189
179
* @param {SyntheticEvent } event - React's original SyntheticEvent.
190
180
* @param {object } data - All props.
191
181
*/
192
- onClose : PropTypes . func ,
182
+ onClick : PropTypes . func ,
193
183
194
184
/**
195
- * Called when a multi-select label is clicked .
185
+ * Called when a close event happens .
196
186
*
197
187
* @param {SyntheticEvent } event - React's original SyntheticEvent.
198
- * @param {object } data - All label props.
188
+ * @param {object } data - All props.
199
189
*/
200
- onLabelClick : PropTypes . func ,
190
+ onClose : PropTypes . func ,
201
191
202
192
/**
203
- * Called when an open event happens .
193
+ * Called on focus .
204
194
*
205
195
* @param {SyntheticEvent } event - React's original SyntheticEvent.
206
196
* @param {object } data - All props.
207
197
*/
208
- onOpen : PropTypes . func ,
198
+ onFocus : PropTypes . func ,
209
199
210
200
/**
211
- * Called on search input change .
201
+ * Called when a multi-select label is clicked .
212
202
*
213
203
* @param {SyntheticEvent } event - React's original SyntheticEvent.
214
- * @param {string } value - Current value of search input .
204
+ * @param {object } data - All label props .
215
205
*/
216
- onSearchChange : PropTypes . func ,
206
+ onLabelClick : PropTypes . func ,
217
207
218
208
/**
219
- * Called on click .
209
+ * Called on mousedown .
220
210
*
221
211
* @param {SyntheticEvent } event - React's original SyntheticEvent.
222
212
* @param {object } data - All props.
223
213
*/
224
- onClick : PropTypes . func ,
214
+ onMouseDown : PropTypes . func ,
225
215
226
216
/**
227
- * Called on focus .
217
+ * Called when an open event happens .
228
218
*
229
219
* @param {SyntheticEvent } event - React's original SyntheticEvent.
230
220
* @param {object } data - All props.
231
221
*/
232
- onFocus : PropTypes . func ,
222
+ onOpen : PropTypes . func ,
233
223
234
224
/**
235
- * Called on mousedown .
225
+ * Called on search input change .
236
226
*
237
227
* @param {SyntheticEvent } event - React's original SyntheticEvent.
238
- * @param {object } data - All props .
228
+ * @param {string } value - Current value of search input .
239
229
*/
240
- onMouseDown : PropTypes . func ,
230
+ onSearchChange : PropTypes . func ,
241
231
242
232
/** Controls whether or not the dropdown menu is displayed. */
243
233
open : PropTypes . bool ,
@@ -257,13 +247,10 @@ export default class Dropdown extends Component {
257
247
/** A dropdown can be formatted so that its menu is pointing. */
258
248
pointing : PropTypes . oneOfType ( [
259
249
PropTypes . bool ,
260
- PropTypes . oneOf ( _meta . props . pointing ) ,
250
+ PropTypes . oneOf ( [ 'left' , 'right' , 'top' , 'top left' , 'top right' , 'bottom' , 'bottom left' , 'bottom right' ] ) ,
261
251
] ) ,
262
252
263
- /**
264
- * A function that takes (data, index, defaultLabelProps) and returns
265
- * shorthand for Label .
266
- */
253
+ /** A function that takes (data, index, defaultLabelProps) and returns shorthand for Label. */
267
254
renderLabel : PropTypes . func ,
268
255
269
256
/** A dropdown can have its menu scroll. */
@@ -280,6 +267,9 @@ export default class Dropdown extends Component {
280
267
281
268
// TODO 'searchInMenu' or 'search='in menu' or ??? How to handle this markup and functionality?
282
269
270
+ /** Define whether the highlighted item should be selected on blur. */
271
+ selectOnBlur : PropTypes . bool ,
272
+
283
273
/** Currently selected label in multi-select. */
284
274
selectedLabel : customPropTypes . every ( [
285
275
customPropTypes . demand ( [ 'multiple' ] ) ,
@@ -296,9 +286,6 @@ export default class Dropdown extends Component {
296
286
PropTypes . bool ,
297
287
] ) ,
298
288
299
- /** Define whether the highlighted item should be selected on blur. */
300
- selectOnBlur : PropTypes . bool ,
301
-
302
289
/** A simple dropdown can open without Javascript. */
303
290
simple : PropTypes . bool ,
304
291
@@ -345,7 +332,11 @@ export default class Dropdown extends Component {
345
332
'selectedLabel' ,
346
333
]
347
334
348
- static _meta = _meta
335
+ static _meta = {
336
+ name : 'Dropdown' ,
337
+ type : META . TYPES . MODULE ,
338
+ }
339
+
349
340
static Divider = DropdownDivider
350
341
static Header = DropdownHeader
351
342
static Item = DropdownItem
0 commit comments