-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(shorthand): standardize childKey and shorthand props #452
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ Card.propTypes = { | |
/** A Card can center itself inside its container. */ | ||
centered: PropTypes.bool, | ||
|
||
/** Primary content of the Card. */ | ||
/** Primary content of the Card. Mutually exclusive with all shorthand props. */ | ||
children: customPropTypes.every([ | ||
customPropTypes.disallow(['description', 'header', 'image', 'meta']), | ||
PropTypes.node, | ||
|
@@ -99,41 +99,26 @@ Card.propTypes = { | |
/** A Card can be formatted to display different colors. */ | ||
color: PropTypes.oneOf(Card._meta.props.color), | ||
|
||
/** Shorthand prop for CardDescription. Mutually exclusive with children. */ | ||
description: customPropTypes.every([ | ||
customPropTypes.disallow(['children']), | ||
PropTypes.node, | ||
]), | ||
/** Shorthand prop for the CardDescription component. Mutually exclusive with children. */ | ||
description: CardContent.propTypes.description, | ||
|
||
/** Shorthand prop for CardContent containing extra prop. Mutually exclusive with children. */ | ||
extra: customPropTypes.every([ | ||
customPropTypes.disallow(['children']), | ||
PropTypes.node, | ||
]), | ||
/** Shorthand prop for the CardContent component containing extra prop. Mutually exclusive with children. */ | ||
extra: PropTypes.shorthand, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated prop validation from children components. |
||
|
||
/** A Card can be formatted to take up the width of its container. */ | ||
fluid: PropTypes.bool, | ||
|
||
/** Shorthand prop for CardHeader. Mutually exclusive with children. */ | ||
header: customPropTypes.every([ | ||
customPropTypes.disallow(['children']), | ||
PropTypes.node, | ||
]), | ||
/** Shorthand prop for the CardHeader component. Mutually exclusive with children. */ | ||
header: CardContent.propTypes.header, | ||
|
||
/** Render as an `a` tag instead of a `div` and adds the href attribute. */ | ||
href: PropTypes.string, | ||
|
||
/** A card can contain an Image component. */ | ||
image: customPropTypes.every([ | ||
customPropTypes.disallow(['children']), | ||
PropTypes.node, | ||
]), | ||
/** A card can contain an Image component. Mutually exclusive with children. */ | ||
image: customPropTypes.image, | ||
|
||
/** Shorthand prop for CardMeta. Mutually exclusive with children. */ | ||
meta: customPropTypes.every([ | ||
customPropTypes.disallow(['children']), | ||
PropTypes.node, | ||
]), | ||
/** Shorthand prop for the CardMeta component. Mutually exclusive with children. */ | ||
meta: CardContent.propTypes.meta, | ||
|
||
/** Render as an `a` tag instead of a `div` and called with event on Card click. */ | ||
onClick: PropTypes.func, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import cx from 'classnames' | ||
import _ from 'lodash' | ||
import React, { PropTypes } from 'react' | ||
|
||
import { | ||
|
@@ -27,12 +28,18 @@ function CardGroup(props) { | |
const rest = getUnhandledProps(CardGroup, props) | ||
const ElementType = getElementType(CardGroup, props) | ||
|
||
const content = !items ? children : items.map(item => { | ||
const key = item.key || [item.header, item.description].join('-') | ||
return <Card key={key} {...item} /> | ||
if (children) { | ||
return <ElementType {...rest} className={classes}>{children}</ElementType> | ||
} | ||
|
||
const itemsJSX = _.map(items, item => { | ||
const { childKey, itemProps } = item | ||
const finalKey = childKey || [itemProps.header, itemProps.description].join('-') | ||
|
||
return <Card {...itemProps} key={finalKey} /> | ||
}) | ||
|
||
return <ElementType {...rest} className={classes}>{content}</ElementType> | ||
return <ElementType {...rest} className={classes}>{itemsJSX}</ElementType> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated definition of |
||
} | ||
|
||
CardGroup._meta = { | ||
|
@@ -64,10 +71,10 @@ CardGroup.propTypes = { | |
items: customPropTypes.every([ | ||
customPropTypes.disallow(['children']), | ||
PropTypes.arrayOf(PropTypes.shape({ | ||
description: PropTypes.node, | ||
meta: PropTypes.node, | ||
key: PropTypes.string, | ||
header: PropTypes.node, | ||
childKey: PropTypes.childKey, | ||
// do not spread Card propTypes here | ||
// it will be undefined due to circular imports | ||
// allow the Card to validate the props it is sent | ||
})), | ||
]), | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated all comments on
views
to unified format.