Skip to content

Commit e30f79b

Browse files
committed
refactor(factories): merge item/collection factories
1 parent 2a4b80e commit e30f79b

33 files changed

+123
-133
lines changed

src/collections/Breadcrumb/BreadcrumbDivider.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getUnhandledProps,
88
getElementType,
@@ -47,6 +47,6 @@ BreadcrumbDivider.propTypes = {
4747
icon: customPropTypes.itemShorthand,
4848
}
4949

50-
BreadcrumbDivider.create = createShorthandItemFactory(BreadcrumbDivider, icon => ({ icon }))
50+
BreadcrumbDivider.create = createShorthandFactory(BreadcrumbDivider, icon => ({ icon }))
5151

5252
export default BreadcrumbDivider

src/collections/Breadcrumb/BreadcrumbSection.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { Component, PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getUnhandledProps,
88
getElementType,
@@ -87,4 +87,4 @@ export default class BreadcrumbSection extends Component {
8787
}
8888
}
8989

90-
BreadcrumbSection.create = createShorthandItemFactory(BreadcrumbSection, content => ({ content, link: true }))
90+
BreadcrumbSection.create = createShorthandFactory(BreadcrumbSection, content => ({ content, link: true }))

src/collections/Menu/Menu.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { PropTypes } from 'react'
44

55
import {
66
AutoControlledComponent as Component,
7-
createShorthandItem,
7+
createShorthand,
88
customPropTypes,
99
getElementType,
1010
getUnhandledProps,
@@ -153,7 +153,7 @@ class Menu extends Component {
153153
const { activeIndex } = this.state
154154

155155
return _.map(items, (item, index) => {
156-
return createShorthandItem(MenuItem, val => ({ content: val }), item, {
156+
return createShorthand(MenuItem, val => ({ content: val }), item, {
157157
active: activeIndex === index,
158158
index,
159159
onClick: this.handleItemClick,

src/collections/Message/Message.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { PropTypes } from 'react'
33
import cx from 'classnames'
44

55
import {
6-
createShorthandItem,
6+
createShorthand,
77
customPropTypes,
88
getElementType,
99
getUnhandledProps,
@@ -86,9 +86,9 @@ function Message(props) {
8686
{Icon.create(icon)}
8787
{(header || content || list) && (
8888
<MessageContent>
89-
{createShorthandItem(MessageHeader, val => ({ children: val }), header)}
90-
{createShorthandItem(MessageList, val => ({ items: val }), list)}
91-
{createShorthandItem('p', val => ({ children: val }), content)}
89+
{createShorthand(MessageHeader, val => ({ children: val }), header)}
90+
{createShorthand(MessageList, val => ({ items: val }), list)}
91+
{createShorthand('p', val => ({ children: val }), content)}
9292
</MessageContent>
9393
)}
9494
</ElementType>

src/collections/Table/TableCell.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -133,6 +133,6 @@ TableCell.propTypes = {
133133
width: PropTypes.oneOf(TableCell._meta.props.width),
134134
}
135135

136-
TableCell.create = createShorthandItemFactory(TableCell, content => ({ content }))
136+
TableCell.create = createShorthandFactory(TableCell, content => ({ content }), true)
137137

138138
export default TableCell

src/collections/Table/TableRow.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import cx from 'classnames'
33
import React, { PropTypes } from 'react'
44

55
import {
6-
createShorthandCollectionFactory,
6+
createShorthandFactory,
77
customPropTypes,
88
getElementType,
99
getUnhandledProps,
@@ -112,8 +112,6 @@ TableRow.propTypes = {
112112
warning: PropTypes.bool,
113113
}
114114

115-
// TODO the value for this factory is an array
116-
// Collection factories should also take in the component that they map their values to
117-
TableRow.create = createShorthandCollectionFactory(TableRow, cells => ({ cells }))
115+
TableRow.create = createShorthandFactory(TableRow, cells => ({ cells }), true)
118116

119117
export default TableRow

src/elements/Button/Button.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { Component, PropTypes } from 'react'
33

44
import {
55
customPropTypes,
6-
createShorthandItemFactory,
6+
createShorthandFactory,
77
getElementType,
88
getUnhandledProps,
99
makeDebugger,
@@ -289,6 +289,6 @@ class Button extends Component {
289289
}
290290
}
291291

292-
Button.create = createShorthandItemFactory(Button, value => ({ content: value }))
292+
Button.create = createShorthandFactory(Button, value => ({ content: value }))
293293

294294
export default Button

src/elements/Flag/Flag.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -85,7 +85,7 @@ Flag.defaultProps = {
8585
as: 'i',
8686
}
8787

88-
Flag.create = createShorthandItemFactory(Flag, value => ({ name: value }))
88+
Flag.create = createShorthandFactory(Flag, value => ({ name: value }))
8989

9090
export default Flag
9191

src/elements/Header/HeaderSubheader.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -38,6 +38,6 @@ HeaderSubheader.propTypes = {
3838
content: customPropTypes.contentShorthand,
3939
}
4040

41-
HeaderSubheader.create = createShorthandItemFactory(HeaderSubheader, content => ({ content }))
41+
HeaderSubheader.create = createShorthandFactory(HeaderSubheader, content => ({ content }))
4242

4343
export default HeaderSubheader

src/elements/Icon/Icon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -113,6 +113,6 @@ Icon.defaultProps = {
113113
as: 'i',
114114
}
115115

116-
Icon.create = createShorthandItemFactory(Icon, value => ({ name: value }))
116+
Icon.create = createShorthandFactory(Icon, value => ({ name: value }))
117117

118118
export default Icon

src/elements/Image/Image.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -198,6 +198,6 @@ Image.defaultProps = {
198198
ui: true,
199199
}
200200

201-
Image.create = createShorthandItemFactory(Image, value => ({ src: value }))
201+
Image.create = createShorthandFactory(Image, value => ({ src: value }))
202202

203203
export default Image

src/elements/Label/Label.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import cx from 'classnames'
33
import React, { Component, PropTypes } from 'react'
44

55
import {
6-
createShorthandItem,
7-
createShorthandItemFactory,
6+
createShorthand,
7+
createShorthandFactory,
88
customPropTypes,
99
getElementType,
1010
getUnhandledProps,
@@ -202,7 +202,7 @@ export default class Label extends Component {
202202
{Icon.create(icon)}
203203
{typeof image !== 'boolean' && Image.create(image)}
204204
{content}
205-
{createShorthandItem(LabelDetail, val => ({ content: val }), detail)}
205+
{createShorthand(LabelDetail, val => ({ content: val }), detail)}
206206
{onRemove && Icon.create(removeIconShorthand, { onClick: this.handleRemove })}
207207
</ElementType>
208208
)
@@ -211,4 +211,4 @@ export default class Label extends Component {
211211

212212
// Label is not yet defined inside the class
213213
// Do not use a static property initializer
214-
Label.create = createShorthandItemFactory(Label, value => ({ content: value }))
214+
Label.create = createShorthandFactory(Label, value => ({ content: value }))

src/elements/List/ListContent.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -84,6 +84,6 @@ ListContent.propTypes = {
8484
verticalAlign: PropTypes.oneOf(ListContent._meta.props.verticalAlign),
8585
}
8686

87-
ListContent.create = createShorthandItemFactory(ListContent, content => ({ content }))
87+
ListContent.create = createShorthandFactory(ListContent, content => ({ content }))
8888

8989
export default ListContent

src/elements/List/ListDescription.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -38,6 +38,6 @@ ListDescription.propTypes = {
3838
content: customPropTypes.contentShorthand,
3939
}
4040

41-
ListDescription.create = createShorthandItemFactory(ListDescription, content => ({ content }))
41+
ListDescription.create = createShorthandFactory(ListDescription, content => ({ content }))
4242

4343
export default ListDescription

src/elements/List/ListHeader.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -38,6 +38,6 @@ ListHeader.propTypes = {
3838
content: customPropTypes.contentShorthand,
3939
}
4040

41-
ListHeader.create = createShorthandItemFactory(ListHeader, content => ({ content }))
41+
ListHeader.create = createShorthandFactory(ListHeader, content => ({ content }))
4242

4343
export default ListHeader

src/elements/List/ListIcon.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
createShorthandItemFactory,
5+
createShorthandFactory,
66
getUnhandledProps,
77
META,
88
SUI,
@@ -38,6 +38,6 @@ ListIcon.propTypes = {
3838
verticalAlign: PropTypes.oneOf(ListIcon._meta.props.verticalAlign),
3939
}
4040

41-
ListIcon.create = createShorthandItemFactory(ListIcon, name => ({ name }))
41+
ListIcon.create = createShorthandFactory(ListIcon, name => ({ name }))
4242

4343
export default ListIcon

src/elements/List/ListItem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import cx from 'classnames'
33
import React, { isValidElement, PropTypes } from 'react'
44

55
import {
6-
createShorthandItemFactory,
6+
createShorthandFactory,
77
customPropTypes,
88
getElementType,
99
getUnhandledProps,
@@ -146,6 +146,6 @@ ListItem.propTypes = {
146146
value: PropTypes.string,
147147
}
148148

149-
ListItem.create = createShorthandItemFactory(ListItem, content => ({ content }))
149+
ListItem.create = createShorthandFactory(ListItem, content => ({ content }))
150150

151151
export default ListItem

src/elements/Step/StepContent.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { PropTypes } from 'react'
22
import cx from 'classnames'
33

44
import {
5-
createShorthandItem,
5+
createShorthand,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -23,8 +23,8 @@ function StepContent(props) {
2323

2424
return (
2525
<ElementType {...rest} className={classes}>
26-
{createShorthandItem(StepTitle, val => ({ title: val }), title)}
27-
{createShorthandItem(StepDescription, val => ({ description: val }), description)}
26+
{createShorthand(StepTitle, val => ({ title: val }), title)}
27+
{createShorthand(StepDescription, val => ({ description: val }), description)}
2828
</ElementType>
2929
)
3030
}

0 commit comments

Comments
 (0)