-
Notifications
You must be signed in to change notification settings - Fork 77
feat: refactor Tile removing ProductTile component #548
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
Changes from all commits
62182fc
bf5eff9
9e0bf80
503f72f
3221d62
204e24f
029390a
d6ffac6
346ed81
ba69c20
310253c
040ab92
4de6ab0
68fa459
4045b43
0a3e225
91af473
2818cd8
80c1dfd
c79604f
eead6c0
a5199f4
391b979
eae649b
1a33e6f
da92e76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,14 +13,17 @@ const Tile = props => { | |
| columnSpan, | ||
| colorAccent, | ||
| backgroundColor, | ||
| backgroundImage, | ||
| children, | ||
| className, | ||
| productTile, | ||
| ...rest | ||
| } = props; | ||
|
|
||
| const tileClasses = classnames( | ||
| 'fd-tile', | ||
| { | ||
| 'fd-tile': !productTile, | ||
| 'fd-product-tile': productTile, | ||
| 'is-disabled': disabled, | ||
| [`fd-has-grid-row-span-${rowSpan}`]: !!rowSpan, | ||
| [`fd-has-grid-column-span-${columnSpan}`]: !!columnSpan, | ||
|
|
@@ -34,7 +37,20 @@ const Tile = props => { | |
| <div | ||
| {...rest} | ||
| className={tileClasses}> | ||
| {children} | ||
| {productTile && | ||
| <div className='fd-product-tile__media' style={{ backgroundImage: 'url(' + backgroundImage + ')' }} /> | ||
| } | ||
| {React.Children.toArray(children).map(child => { | ||
| const isAction = child.type && child.type.displayName === 'Tile.Actions'; | ||
|
|
||
| if (isAction) { | ||
| return child; | ||
| } | ||
|
|
||
| return React.cloneElement(child, { | ||
| productTile: productTile | ||
| }); | ||
| })} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
@@ -43,17 +59,21 @@ Tile.displayName = 'Tile'; | |
|
|
||
| Tile.propTypes = { | ||
| backgroundColor: PropTypes.number, | ||
| backgroundImage: PropTypes.string, | ||
| className: PropTypes.string, | ||
| colorAccent: PropTypes.number, | ||
| columnSpan: CustomPropTypes.range(1, 6), | ||
| disabled: PropTypes.bool, | ||
| productTile: PropTypes.bool, | ||
|
Contributor
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. I think this component should clone children and pass the top-level |
||
| rowSpan: PropTypes.number | ||
| }; | ||
|
|
||
| Tile.propDescriptions = { | ||
| backgroundColor: 'Sets a background color class.', | ||
| backgroundImage: 'URL of the background image for product tile.', | ||
| colorAccent: 'Sets a background color accent class. Options include numbers from 1 to 9.', | ||
| columnSpan: 'Number of columns the tile covers.', | ||
| productTile: 'Set to **true** to mark component as a product tile.', | ||
| rowSpan: 'Number of rows the tile covers.' | ||
| }; | ||
|
|
||
|
|
||
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.
I created a conditional for product tile rather than if the background image exists bc product tiles should have background images with them always. This will eliminate the issue Jenna mentioned with background image rendering undefined for tiles that are not product.
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.
Well, technically it won't. There are really two props needed for a product tile:
productTileandbackgroundImageso it's possible the consumer passes one, but not the other. That said, this has become more of a pattern-based component so I think this is a good change. We could makeproductTilea shape prop with a requiredbackgroundImage, but that might be overkill here. As we've said in this PR, the consumer just wants to know which props to pass and the example page will help them with that.