feat(Card): Add disabled card and clean up props#6659
feat(Card): Add disabled card and clean up props#6659tlabaj merged 9 commits intopatternfly:mainfrom
Conversation
| return ( | ||
| <React.Fragment> | ||
| <Card isHoverable> | ||
| <Card isSelectable selectableVariant="raised"> |
There was a problem hiding this comment.
Just a thought - could we combine these so you don't need separate props? Wondering if isSelectable="raised" could apply the new modifier.
There was a problem hiding this comment.
This is a good thought - I figured that adding the selectableVariant="raised" would mean that to opt into the new styling, they'd just need to add indicate they wanted to using the new prop. And eventually, when raised is the default, then it wont be necessary to specify that.
mcarrano
left a comment
There was a problem hiding this comment.
Looks great. Thanks @nicolethoen !
| let selectableModifiers = ''; | ||
| if (isSelectable || isHoverable) { | ||
| if (isRaised) { | ||
| if (isDisabled) { | ||
| selectableModifiers = css((isSelectable || isHoverable) && styles.modifiers.nonSelectableRaised); | ||
| } else { | ||
| selectableModifiers = css( | ||
| (isSelectable || isHoverable) && styles.modifiers.selectableRaised, | ||
| (isSelectable || isHoverable) && isSelected && styles.modifiers.selectedRaised | ||
| ); | ||
| } | ||
| } else { | ||
| selectableModifiers = css( | ||
| (isSelectable || isHoverable) && styles.modifiers.selectable, | ||
| (isSelectable || isHoverable) && isSelected && styles.modifiers.selected | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
I feel like this would be cleaner as a function rather than mutating a let.
| selectableModifiers = css((isSelectable || isHoverable) && styles.modifiers.nonSelectableRaised); | ||
| } else { | ||
| selectableModifiers = css( | ||
| (isSelectable || isHoverable) && styles.modifiers.selectableRaised, | ||
| (isSelectable || isHoverable) && isSelected && styles.modifiers.selectedRaised | ||
| ); | ||
| } | ||
| } else { | ||
| selectableModifiers = css( | ||
| (isSelectable || isHoverable) && styles.modifiers.selectable, | ||
| (isSelectable || isHoverable) && isSelected && styles.modifiers.selected |
There was a problem hiding this comment.
Also, I don't think the repeated isSelectable || isHoverable conditionals here are needed as they are already nested within an if checking that conditional, so they will always be true. I could be missing something though.
| /** @beta Modifies the card to include selected-raised styling */ | ||
| isSelectedRaised?: boolean; | ||
| /** @beta Specifies the selectable styling variant */ | ||
| selectableVariant?: 'legacy' | 'raised'; |
There was a problem hiding this comment.
legacy implies the non raised variant will eventually be deprecated. is that the case @mcarrano?
There was a problem hiding this comment.
I figured it means it's not preferred and the 'old but supported' way
There was a problem hiding this comment.
Ok I see my confusion. I thought the selectable variant set the card to selectable. That being said. I think the API is a little confusing. May we can rename the prop tp selectableStylingVariant.
I would also suggest not calling the option legacy. It is not really descriptive.
There was a problem hiding this comment.
So I was thinking about this more. Would it make sense to deprecate the isSelectable prop and let the selectableVariant prop not only set the styling, but set it selectable too? I think that would make the API more straight forward. Similar to what @mcoker was suggesting in his comment about combining props.
There was a problem hiding this comment.
How about selectStyle or selectableStyle over using variant, since the function of the select remains the same?
Edit: variant was removed nvm
|
|
||
| it('Verify that selectable card can be selected and unselected with keyboard input', () => { | ||
| cy.get('#selectableCard').focus(); | ||
| cy.focused().should('have.class', 'pf-m-selectable'); |
There was a problem hiding this comment.
So non raised card can no longer be selected or selectable?
There was a problem hiding this comment.
correct - I think it's the same as disabled from my understanding
There was a problem hiding this comment.
I don't think that is the case. We are still applying the style and we have an example for that use case. We should be testing both here.
tlabaj
left a comment
There was a problem hiding this comment.
I have a few questions about the logic.
| /** Modifies the card to include compact styling. Should not be used with isLarge. */ | ||
| isCompact?: boolean; | ||
| /** Modifies the card to include selectable styling */ | ||
| isSelectable?: boolean; |
There was a problem hiding this comment.
so, is this prop deprecated?
There was a problem hiding this comment.
Are we going to keep supporting the original plain variation of selectable cards? If not I'd say the next breaking release we update isSelectable to use the raised styling and remove isSelectableRaised (I'm just not sure if that really falls under the "deprecated" flag indication though). If we will keep the original styling I think we should bring back in the enum for the style variations and keep using isSelectable as is.
There was a problem hiding this comment.
Yes. I was confused at first. I thought the original variant prop also set the card to be selectable.
| isSelectedRaised?: boolean; | ||
| /** @beta Specifies the selectable styling variant */ | ||
| selectableVariant?: 'legacy' | 'raised'; | ||
| /** @beta Modifies a selectable card to have disabled styling */ |
There was a problem hiding this comment.
Can we be more explicit here that disabled only applies to non raised cards since we still support both variations.
There was a problem hiding this comment.
As I have it, a disabled selectable card without the raised variant is basically a normal card with no hover/select styles at all. Still valid?
There was a problem hiding this comment.
Yeah I think only the disabled raised selectable card has any special styling. The flag probably shouldn't apply anything to a non-selectable non-raised card (or alternatively, maybe remove any select related props from non-raised cards?)
|
Code looks good to me the only outstanding question I've got is whether we want to keep supporting the original plain selectable style, as that would impact how we mark |
|
@kmcfaul I think it would be a breaking change if we didn't support it. |
mcoker
left a comment
There was a problem hiding this comment.
LGTM! A thought about isDisabled - I wonder if we'll introduce a "disabled" card at some point that does something else, and if that might create a naming conflict. I don't know that we would, but figured I would mention it.
| id={id} | ||
| className={css( | ||
| styles.card, | ||
| isHoverable && styles.modifiers.hoverable, |
There was a problem hiding this comment.
@mcoker, could someone apply pf-m-hoverable. Without, isSelectable. I think removing support completely would technically be breaking. I think we can deprecate it, but we still need to apply the style.
There was a problem hiding this comment.
@tlabaj yep, they're separate. While you could use them together, it isn't necessary since isSelected has its own hoverable styles (they're the same as what isHoverable applies). https://github.com/patternfly/patternfly/blob/dc6cf07d69cbb80026dca7fe43dc28704aabea64/src/patternfly/components/Card/card.scss#L26-L27
@nicolethoen Yes, we still need to support the old selectable style. We didn't want to force a visual breaking change on products currently using selectable cards. |
|
@mcarrano is the intention that next time we have a breaking change release, the old styles will go away? |
Yes, most likely. |
|
|
||
| if (isHoverable) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn("Card: the 'isHoverable' prop is deprecated. Use isSelectable instead."); |
There was a problem hiding this comment.
I don't thinks this is necessary. We don't do this anywhere else that I can find.
|
Your changes have been released in:
Thanks for your contribution! 🎉 |
What: Closes #6567