Skip to content

Commit a8a317c

Browse files
committed
fix(Item): actually make content a shorthand prop for ItemContent
As already documented.
1 parent c828368 commit a8a317c

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

src/views/Item/Item.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22

3-
import { SemanticShorthandContent, SemanticShorthandItem } from '../../generic'
4-
import ItemContent from './ItemContent'
3+
import { SemanticShorthandItem } from '../../generic'
4+
import ItemContent, { ItemContentProps } from './ItemContent'
55
import ItemDescription, { ItemDescriptionProps } from './ItemDescription'
66
import ItemExtra, { ItemExtraProps } from './ItemExtra'
77
import ItemGroup from './ItemGroup'
@@ -24,7 +24,7 @@ export interface StrictItemProps {
2424
className?: string
2525

2626
/** Shorthand for ItemContent component. */
27-
content?: SemanticShorthandContent
27+
content?: SemanticShorthandItem<ItemContentProps>
2828

2929
/** Shorthand for ItemDescription component. */
3030
description?: SemanticShorthandItem<ItemDescriptionProps>

src/views/Item/Item.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import cx from 'clsx'
2+
import _ from 'lodash'
23
import PropTypes from 'prop-types'
34
import React from 'react'
45

@@ -29,17 +30,22 @@ function Item(props) {
2930
)
3031
}
3132

33+
let contentShorthandValue = content
34+
if (
35+
contentShorthandValue === undefined &&
36+
[description, extra, header, meta].some((prop) => !_.isNil(prop))
37+
) {
38+
contentShorthandValue = {}
39+
}
40+
3241
return (
3342
<ElementType {...rest} className={classes}>
3443
{ItemImage.create(image, { autoGenerateKey: false })}
3544

36-
<ItemContent
37-
content={content}
38-
description={description}
39-
extra={extra}
40-
header={header}
41-
meta={meta}
42-
/>
45+
{ItemContent.create(contentShorthandValue, {
46+
autoGenerateKey: false,
47+
overrideProps: { description, extra, header, meta },
48+
})}
4349
</ElementType>
4450
)
4551
}
@@ -63,7 +69,7 @@ Item.propTypes = {
6369
className: PropTypes.string,
6470

6571
/** Shorthand for ItemContent component. */
66-
content: customPropTypes.contentShorthand,
72+
content: customPropTypes.itemShorthand,
6773

6874
/** Shorthand for ItemDescription component. */
6975
description: customPropTypes.itemShorthand,

src/views/Item/ItemContent.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React from 'react'
44

55
import {
66
childrenUtils,
7+
createShorthandFactory,
78
customPropTypes,
89
getElementType,
910
getUnhandledProps,
@@ -73,4 +74,6 @@ ItemContent.propTypes = {
7374
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
7475
}
7576

77+
ItemContent.create = createShorthandFactory(ItemContent, (content) => ({ content }))
78+
7679
export default ItemContent

test/specs/views/Item/Item-test.js

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ describe('Item', () => {
3333
mapValueToProps: (val) => ({ src: val }),
3434
})
3535

36+
common.implementsShorthandProp(Item, {
37+
autoGenerateKey: false,
38+
propKey: 'content',
39+
ShorthandComponent: ItemContent,
40+
mapValueToProps: (val) => ({ content: val }),
41+
})
42+
3643
describe('content prop', () => {
3744
it('renders ItemContent component', () => {
3845
shallow(<Item content={faker.hacker.phrase()} />).should.have.descendants('ItemContent')

0 commit comments

Comments
 (0)