Fix Card to be backwards compatible #5762
Merged
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.
What does this PR do?
In a recent PR, we introduced changes that were not backwards compatible. The issue was rooted in a side-effect of styled components
forwardedAs
prop and how it handles creating classes forstyled
HOCs.Essentially, by abstracting Card to go from being just a Box to a
styled(Box)
, we introduce another layer of styled components which resulted in the Box props applied to a Card getting lost. Styled components isn't set up to know how to merge/layer so many levels of chained styled components. Suddenly when we updated the DS site, everything looked like this (yikes):Therefore, this PR takes a new approach where the desired styling for Card is passed as
kind
on Box. Similar to what we do with Button.kind
takes a structure of{ hover: theme.card.hover.container, ...theme.card.container}
. Then, StyledBox handles thekind
styles.Where should the reviewer start?
src/js/components/Card/Card.js
What testing has been done on this PR?
Tested on Clickable story.
Also, I mirrored what the setup in the DS site was (which caused backwards compatibility issues) and confirmed this would work correctly:
Screen.Recording.2021-10-28.at.3.13.06.PM.mov
How should this be manually tested?
Created a styled component that is a
styled(Card)
and pass Box props on the card. All of those styles should appear.Any background context you want to provide?
What are the relevant issues?
Screenshots (if appropriate)
Do the grommet docs need to be updated?
Yes, need to move the extend outside of the hover block.
Should this PR be mentioned in the release notes?
Yes.
Is this change backwards compatible or is it a breaking change?
Backwards compatible.