Skip to content

Commit 5ee7b8a

Browse files
layershifterlevithomason
authored andcommitted
style(Dropdown): update typings and propTypes usage (#1334)
1 parent 358af2f commit 5ee7b8a

File tree

6 files changed

+194
-106
lines changed

6 files changed

+194
-106
lines changed

src/modules/Dropdown/Dropdown.js

+46-55
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import _ from 'lodash'
21
import cx from 'classnames'
2+
import _ from 'lodash'
33
import React, { Children, cloneElement, PropTypes } from 'react'
44

55
import {
@@ -18,23 +18,13 @@ import {
1818
} from '../../lib'
1919
import Icon from '../../elements/Icon'
2020
import Label from '../../elements/Label'
21-
2221
import DropdownDivider from './DropdownDivider'
2322
import DropdownItem from './DropdownItem'
2423
import DropdownHeader from './DropdownHeader'
2524
import DropdownMenu from './DropdownMenu'
2625

2726
const debug = makeDebugger('dropdown')
2827

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-
3828
/**
3929
* A dropdown allows a user to select a value from a series of options.
4030
* @see Form
@@ -43,6 +33,18 @@ const _meta = {
4333
*/
4434
export default class Dropdown extends Component {
4535
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+
4648
/**
4749
* Allow user additions to the list of options (boolean).
4850
* Requires the use of `selection`, `options` and `search`.
@@ -52,19 +54,7 @@ export default class Dropdown extends Component {
5254
PropTypes.bool,
5355
]),
5456

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. */
6858
basic: PropTypes.bool,
6959

7060
/** Format the Dropdown to appear as a button. */
@@ -102,15 +92,15 @@ export default class Dropdown extends Component {
10292
defaultSelectedLabel: customPropTypes.every([
10393
customPropTypes.demand(['multiple']),
10494
PropTypes.oneOfType([
105-
PropTypes.string,
10695
PropTypes.number,
96+
PropTypes.string,
10797
]),
10898
]),
10999

110100
/** Initial value or value array if multiple. */
111101
defaultValue: PropTypes.oneOfType([
112-
PropTypes.string,
113102
PropTypes.number,
103+
PropTypes.string,
114104
PropTypes.arrayOf(PropTypes.oneOfType([
115105
PropTypes.string,
116106
PropTypes.number,
@@ -141,12 +131,12 @@ export default class Dropdown extends Component {
141131
/** A dropdown can be formatted to appear inline in other content. */
142132
inline: PropTypes.bool,
143133

144-
/** A dropdown can be labeled. */
145-
labeled: PropTypes.bool,
146-
147134
/** A dropdown can be formatted as a Menu item. */
148135
item: PropTypes.bool,
149136

137+
/** A dropdown can be labeled. */
138+
labeled: PropTypes.bool,
139+
150140
/** A dropdown can show that it is currently loading data. */
151141
loading: PropTypes.bool,
152142

@@ -184,60 +174,60 @@ export default class Dropdown extends Component {
184174
onChange: PropTypes.func,
185175

186176
/**
187-
* Called when a close event happens.
177+
* Called on click.
188178
*
189179
* @param {SyntheticEvent} event - React's original SyntheticEvent.
190180
* @param {object} data - All props.
191181
*/
192-
onClose: PropTypes.func,
182+
onClick: PropTypes.func,
193183

194184
/**
195-
* Called when a multi-select label is clicked.
185+
* Called when a close event happens.
196186
*
197187
* @param {SyntheticEvent} event - React's original SyntheticEvent.
198-
* @param {object} data - All label props.
188+
* @param {object} data - All props.
199189
*/
200-
onLabelClick: PropTypes.func,
190+
onClose: PropTypes.func,
201191

202192
/**
203-
* Called when an open event happens.
193+
* Called on focus.
204194
*
205195
* @param {SyntheticEvent} event - React's original SyntheticEvent.
206196
* @param {object} data - All props.
207197
*/
208-
onOpen: PropTypes.func,
198+
onFocus: PropTypes.func,
209199

210200
/**
211-
* Called on search input change.
201+
* Called when a multi-select label is clicked.
212202
*
213203
* @param {SyntheticEvent} event - React's original SyntheticEvent.
214-
* @param {string} value - Current value of search input.
204+
* @param {object} data - All label props.
215205
*/
216-
onSearchChange: PropTypes.func,
206+
onLabelClick: PropTypes.func,
217207

218208
/**
219-
* Called on click.
209+
* Called on mousedown.
220210
*
221211
* @param {SyntheticEvent} event - React's original SyntheticEvent.
222212
* @param {object} data - All props.
223213
*/
224-
onClick: PropTypes.func,
214+
onMouseDown: PropTypes.func,
225215

226216
/**
227-
* Called on focus.
217+
* Called when an open event happens.
228218
*
229219
* @param {SyntheticEvent} event - React's original SyntheticEvent.
230220
* @param {object} data - All props.
231221
*/
232-
onFocus: PropTypes.func,
222+
onOpen: PropTypes.func,
233223

234224
/**
235-
* Called on mousedown.
225+
* Called on search input change.
236226
*
237227
* @param {SyntheticEvent} event - React's original SyntheticEvent.
238-
* @param {object} data - All props.
228+
* @param {string} value - Current value of search input.
239229
*/
240-
onMouseDown: PropTypes.func,
230+
onSearchChange: PropTypes.func,
241231

242232
/** Controls whether or not the dropdown menu is displayed. */
243233
open: PropTypes.bool,
@@ -257,13 +247,10 @@ export default class Dropdown extends Component {
257247
/** A dropdown can be formatted so that its menu is pointing. */
258248
pointing: PropTypes.oneOfType([
259249
PropTypes.bool,
260-
PropTypes.oneOf(_meta.props.pointing),
250+
PropTypes.oneOf(['left', 'right', 'top', 'top left', 'top right', 'bottom', 'bottom left', 'bottom right']),
261251
]),
262252

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. */
267254
renderLabel: PropTypes.func,
268255

269256
/** A dropdown can have its menu scroll. */
@@ -280,6 +267,9 @@ export default class Dropdown extends Component {
280267

281268
// TODO 'searchInMenu' or 'search='in menu' or ??? How to handle this markup and functionality?
282269

270+
/** Define whether the highlighted item should be selected on blur. */
271+
selectOnBlur: PropTypes.bool,
272+
283273
/** Currently selected label in multi-select. */
284274
selectedLabel: customPropTypes.every([
285275
customPropTypes.demand(['multiple']),
@@ -296,9 +286,6 @@ export default class Dropdown extends Component {
296286
PropTypes.bool,
297287
]),
298288

299-
/** Define whether the highlighted item should be selected on blur. */
300-
selectOnBlur: PropTypes.bool,
301-
302289
/** A simple dropdown can open without Javascript. */
303290
simple: PropTypes.bool,
304291

@@ -345,7 +332,11 @@ export default class Dropdown extends Component {
345332
'selectedLabel',
346333
]
347334

348-
static _meta = _meta
335+
static _meta = {
336+
name: 'Dropdown',
337+
type: META.TYPES.MODULE,
338+
}
339+
349340
static Divider = DropdownDivider
350341
static Header = DropdownHeader
351342
static Item = DropdownItem

src/modules/Dropdown/DropdownDivider.js

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
META,
99
} from '../../lib'
1010

11+
/**
12+
* A dropdown menu can contain dividers to separate related content.
13+
*/
1114
function DropdownDivider(props) {
1215
const { className } = props
1316
const classes = cx('divider', className)

src/modules/Dropdown/DropdownHeader.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import _ from 'lodash'
21
import cx from 'classnames'
2+
import _ from 'lodash'
33
import React, { PropTypes } from 'react'
44

55
import {
@@ -10,8 +10,17 @@ import {
1010
} from '../../lib'
1111
import Icon from '../../elements/Icon'
1212

13+
/**
14+
* A dropdown menu can contain a header.
15+
*/
1316
function DropdownHeader(props) {
14-
const { children, className, content, icon } = props
17+
const {
18+
children,
19+
className,
20+
content,
21+
icon,
22+
} = props
23+
1524
const classes = cx('header', className)
1625
const rest = getUnhandledProps(DropdownHeader, props)
1726
const ElementType = getElementType(DropdownHeader, props)

src/modules/Dropdown/DropdownItem.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import _ from 'lodash'
21
import cx from 'classnames'
2+
import _ from 'lodash'
33
import React, { Component, PropTypes } from 'react'
44

55
import {
@@ -17,7 +17,7 @@ import Image from '../../elements/Image'
1717
import Label from '../../elements/Label'
1818

1919
/**
20-
* An item sub-component for Dropdown component
20+
* An item sub-component for Dropdown component.
2121
*/
2222
export default class DropdownItem extends Component {
2323
static propTypes = {
@@ -54,6 +54,14 @@ export default class DropdownItem extends Component {
5454
/** Shorthand for Label. */
5555
label: customPropTypes.itemShorthand,
5656

57+
/**
58+
* Called on click.
59+
*
60+
* @param {SyntheticEvent} event - React's original SyntheticEvent.
61+
* @param {object} data - All props.
62+
*/
63+
onClick: PropTypes.func,
64+
5765
/**
5866
* The item currently selected by keyboard shortcut.
5967
* This is not the active item.
@@ -63,19 +71,11 @@ export default class DropdownItem extends Component {
6371
/** Display text. */
6472
text: customPropTypes.contentShorthand,
6573

66-
/** Stored value */
74+
/** Stored value. */
6775
value: PropTypes.oneOfType([
6876
PropTypes.number,
6977
PropTypes.string,
7078
]),
71-
72-
/**
73-
* Called on click.
74-
*
75-
* @param {SyntheticEvent} event - React's original SyntheticEvent.
76-
* @param {object} data - All props.
77-
*/
78-
onClick: PropTypes.func,
7979
}
8080

8181
static _meta = {

src/modules/Dropdown/DropdownMenu.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { PropTypes } from 'react'
21
import cx from 'classnames'
2+
import React, { PropTypes } from 'react'
33

44
import {
55
customPropTypes,
@@ -9,6 +9,9 @@ import {
99
useKeyOnly,
1010
} from '../../lib'
1111

12+
/**
13+
* A dropdown menu can contain a menu.
14+
*/
1215
function DropdownMenu(props) {
1316
const { children, className, scrolling } = props
1417
const classes = cx(

0 commit comments

Comments
 (0)