Skip to content

Commit a68c279

Browse files
committed
wip shorthand collection keys
1 parent bc3b314 commit a68c279

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+265
-181
lines changed

docs/app/Examples/collections/Table/States/TableWarningShorthand.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import React from 'react'
22
import { Table } from 'semantic-ui-react'
33

4+
const tableData = [
5+
{ name: undefined, status: undefined, notes: undefined },
6+
{ name: 'Jimmy', status: 'Requires Action', notes: undefined },
7+
{ name: 'Jamie', status: undefined, notes: 'Hostile' },
8+
{ name: 'Jill', status: undefined, notes: undefined },
9+
]
10+
411
const headerRow = [
512
'Name',
613
'Status',
@@ -20,16 +27,14 @@ const renderBodyRow = ({ name, status, notes }) => ({
2027
],
2128
})
2229

23-
const tableData = [
24-
{ name: undefined, status: undefined, notes: undefined },
25-
{ name: 'Jimmy', status: 'Requires Action', notes: undefined },
26-
{ name: 'Jamie', status: undefined, notes: 'Hostile' },
27-
{ name: 'Jill', status: undefined, notes: undefined },
28-
]
29-
3030
const TableWarningShorthand = () => {
3131
return (
32-
<Table celled headerRow={headerRow} renderBodyRow={renderBodyRow} tableData={tableData} />
32+
<Table
33+
celled
34+
headerRow={headerRow}
35+
renderBodyRow={renderBodyRow}
36+
tableData={tableData}
37+
/>
3338
)
3439
}
3540

src/collections/Menu/Menu.js

+2-3
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-
createShorthand,
7+
createShorthandItem,
88
customPropTypes,
99
getElementType,
1010
getUnhandledProps,
@@ -153,9 +153,8 @@ class Menu extends Component {
153153
const { activeIndex } = this.state
154154

155155
return _.map(items, (item, index) => {
156-
return createShorthand(MenuItem, val => ({ content: val }), item, {
156+
return createShorthandItem(MenuItem, val => ({ content: val }), item, {
157157
active: activeIndex === index,
158-
childKey: ({ content, name }) => [content, name].join('-'),
159158
index,
160159
onClick: this.handleItemClick,
161160
})

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

src/collections/Table/Table.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function Table(props) {
8484
<ElementType {...rest} className={classes}>
8585
{headerRow && <TableHeader>{TableRow.create(headerRow, { cellAs: 'th' })}</TableHeader>}
8686
<TableBody>
87-
{renderBodyRow && _.map(tableData, (data, index) => TableRow.create(renderBodyRow(data, index)))}
87+
{renderBodyRow && TableRow.create(_.map(tableData, (data, index) => renderBodyRow(data, index)))}
8888
</TableBody>
8989
{footerRow && <TableFooter>{TableRow.create(footerRow)}</TableFooter>}
9090
</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-
createShorthandFactory,
5+
createShorthandItemFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -128,6 +128,6 @@ TableCell.propTypes = {
128128
width: PropTypes.oneOf(TableCell._meta.props.width),
129129
}
130130

131-
TableCell.create = createShorthandFactory(TableCell, content => ({ content }))
131+
TableCell.create = createShorthandItemFactory(TableCell, content => ({ content }))
132132

133133
export default TableCell

src/collections/Table/TableRow.js

+4-2
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-
createShorthandFactory,
6+
createShorthandCollectionFactory,
77
customPropTypes,
88
getElementType,
99
getUnhandledProps,
@@ -112,6 +112,8 @@ TableRow.propTypes = {
112112
warning: PropTypes.bool,
113113
}
114114

115-
TableRow.create = createShorthandFactory(TableRow, cells => ({ cells }))
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 }))
116118

117119
export default TableRow

src/elements/Button/Button.js

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

44
import {
55
customPropTypes,
6-
createShorthandFactory,
6+
createShorthandItemFactory,
77
getElementType,
88
getUnhandledProps,
99
makeDebugger,
@@ -246,6 +246,6 @@ Button.defaultProps = {
246246
as: 'button',
247247
}
248248

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

251251
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-
createShorthandFactory,
5+
createShorthandItemFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -85,7 +85,7 @@ Flag.defaultProps = {
8585
as: 'i',
8686
}
8787

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

9090
export default Flag
9191

src/elements/Header/Header.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash'
22
import cx from 'classnames'
33
import React, { PropTypes } from 'react'
44
import {
5-
createShorthand,
5+
createShorthandItem,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -62,7 +62,7 @@ function Header(props) {
6262
{(content || subheader) && (
6363
<HeaderContent>
6464
{content}
65-
{createShorthand(HeaderSubheader, val => ({ content: val }), subheader)}
65+
{createShorthandItem(HeaderSubheader, val => ({ content: val }), subheader)}
6666
</HeaderContent>
6767
)}
6868
</ElementType>
@@ -72,7 +72,7 @@ function Header(props) {
7272
return (
7373
<ElementType {...rest} className={classes}>
7474
{content}
75-
{createShorthand(HeaderSubheader, val => ({ content: val }), subheader)}
75+
{createShorthandItem(HeaderSubheader, val => ({ content: val }), subheader)}
7676
</ElementType>
7777
)
7878
}

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-
createShorthandFactory,
5+
createShorthandItemFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -113,6 +113,6 @@ Icon.defaultProps = {
113113
as: 'i',
114114
}
115115

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

118118
export default Icon

src/elements/Image/Image.js

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

44
import {
55
getElementType,
6-
createShorthandFactory,
6+
createShorthandItemFactory,
77
customPropTypes,
88
getUnhandledProps,
99
META,
@@ -185,6 +185,6 @@ Image.defaultProps = {
185185
ui: true,
186186
}
187187

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

190190
export default Image

src/elements/Label/Label.js

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

44
import {
5-
createShorthand,
6-
createShorthandFactory,
5+
createShorthandItem,
6+
createShorthandItemFactory,
77
customPropTypes,
88
getElementType,
99
getUnhandledProps,
@@ -194,7 +194,7 @@ export default class Label extends Component {
194194
{Icon.create(icon)}
195195
{typeof image !== 'boolean' && Image.create(image)}
196196
{content}
197-
{createShorthand(LabelDetail, val => ({ content: val }), detail)}
197+
{createShorthandItem(LabelDetail, val => ({ content: val }), detail)}
198198
{(removable || onRemove) && (
199199
<Icon name='delete' onClick={this.handleRemove} />
200200
)}
@@ -205,4 +205,4 @@ export default class Label extends Component {
205205

206206
// Label is not yet defined inside the class
207207
// Do not use a static property initializer
208-
Label.create = createShorthandFactory(Label, value => ({ content: value }))
208+
Label.create = createShorthandItemFactory(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-
createShorthandFactory,
5+
createShorthandItemFactory,
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 = createShorthandFactory(ListContent, content => ({ content }))
87+
ListContent.create = createShorthandItemFactory(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-
createShorthandFactory,
5+
createShorthandItemFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -38,6 +38,6 @@ ListDescription.propTypes = {
3838
content: customPropTypes.contentShorthand,
3939
}
4040

41-
ListDescription.create = createShorthandFactory(ListDescription, content => ({ content }))
41+
ListDescription.create = createShorthandItemFactory(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-
createShorthandFactory,
5+
createShorthandItemFactory,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -38,6 +38,6 @@ ListHeader.propTypes = {
3838
content: customPropTypes.contentShorthand,
3939
}
4040

41-
ListHeader.create = createShorthandFactory(ListHeader, content => ({ content }))
41+
ListHeader.create = createShorthandItemFactory(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-
createShorthandFactory,
5+
createShorthandItemFactory,
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 = createShorthandFactory(ListIcon, name => ({ name }))
41+
ListIcon.create = createShorthandItemFactory(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-
createShorthandFactory,
6+
createShorthandItemFactory,
77
customPropTypes,
88
getElementType,
99
getUnhandledProps,
@@ -146,6 +146,6 @@ ListItem.propTypes = {
146146
value: PropTypes.string,
147147
}
148148

149-
ListItem.create = createShorthandFactory(ListItem, content => ({ content }))
149+
ListItem.create = createShorthandItemFactory(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-
createShorthand,
5+
createShorthandItem,
66
customPropTypes,
77
getElementType,
88
getUnhandledProps,
@@ -23,8 +23,8 @@ function StepContent(props) {
2323

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

0 commit comments

Comments
 (0)