-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[UI Framework] Reactify kuiCard and related CSS components #12197
[UI Framework] Reactify kuiCard and related CSS components #12197
Conversation
Can one of the admins verify this patch? |
KuiCardGroup.propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
isUnited: PropTypes.bool |
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.
If isUnited
is not required, we should provide a value in defaultProps
for it.
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.
It sounds good.
} from '../../../../components'; | ||
|
||
export default () => { | ||
const cardStyle = { |
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.
How about adding a comment like the following here?
/**
* These styles are just for demonstration purposes. It is recommended use
* properly named classes to set the width in production code.
*/
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.
To make thinking the fast copy-pasters :)
Good.
And before I forget it: It's awesome that you invest the effort into this, @PopradiArpad. Thank you for contributing! ❤️ |
@weltenwort Thanks for your review! |
Better example layout. See the comment of @cjcenizal at #12176 |
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.
Woohoo! Looks fantastic! Huge improvement to the code. I had one small comment about formatting and then we can merge. @weltenwort could you take another look?
|
||
return ( | ||
<div> | ||
<KuiCardGroup> |
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 think we need to outdent this entire block by two spaces (up to line 89).
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.
Ok
jenkins, test this |
Looks like there is a minor conflict now because we merged one of your other PRs. Are you OK with rebasing master and resolving the merge conflict? I added instructions on how to do this to our CONTRIBUTING.md doc: https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#rebasing-and-fixing-merge-conflicts |
…ed -> isUnited, use other framework components in doc
977da71
to
d8373b6
Compare
@cjcenizal Super doc! Thanks for the review! |
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 just left a small correction and something related to the general BEM compliance of the kui framework. This should probably not block this PR since it is a broader issue. 😉
*/ | ||
.kuiCardGroup { | ||
display: flex; | ||
flex-wrap: wrap; /* 1 */ | ||
margin: -$cardSpacing; /* 2 */ | ||
|
||
/** | ||
* 1. Use the defined width of the card to determine when to wrap. | ||
* 2. Use an even margin all around the card so that the spacing is still even when wrapped. | ||
*/ | ||
.kuiCard { |
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.
Strictly speaking, this violates the open/closed principle by modifying the .kuiCard
block based on its location inside the .kuiCardGroup
block. I know several other frameworks break this rule by implementing such groups in exactly this way. A way to fix this would be to not nest the selectors and create a mix of .kuiCard
and .kuiCardGroup__card
on the individual card elements.
References:
- https://en.bem.info/methodology/css/#openclosed-principle
- https://cssguidelin.es/#the-openclosed-principle
@cjcenizal, it looks like this is consistent with how similar group blocks are implemented in the kui framework (e.g. .kuiButtonGroup
). So this is not specific to this PR. Do we accept this BEM violation for these cases?
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.
@weltenwort, in general you are right, changing the properties through nesting is a secure way into the CSS Hell, but in these cases we have an extra semantic information:
XGroup is a group of X so we are speaking about Xs.
The pro is simpler syntax for the user of the X React component: No extra property is needed on X depending on its location (is X part of a group of Xs or not?) and not to expose CSS, which is a main advantage of the framework.
The con is the loosening of the clear openclosed-principle.
But this loosening is context bound: only within a group of X. It could be considered as an extension of the principle instead of its violation.
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.
You're absolutely right... this is a dilemma I've encountered several times. For context, this component was originally implemented the way you suggest, and I only recently changed it to use the current pattern (https://github.com/elastic/kibana/pull/12183/files#diff-5b434436eea8c6ef3f9c1f64780bb791L3 for reference).
There are two problems I've encountered when strictly applying BEM in this kind of situation:
- Mixing classes is sometimes required on many elements of a single component, e.g. in the link I shared you not only need
.kuiCard
mixed with.kuiCardGroup__card
but you also need.kuiCard__description
mixed with.kuiCardGroup__cardDescription
. From the point of view of someone applying the classes, this "interface" can be complex and confusing. - Converting these components to React then requires passing in these classes manually, as you can see in the first commit of this PR. An alternative would be to create a wrapper component which applies this class for you. But again, I feel like both cases are added complexity in the interface.
To me, it comes down to a trade-off: sacrificing BEM in exchange for a more ergonomic interface. Personally, I think we should try to stick to BEM as much as possible, until we discover some pain in the interface. What are your thoughts on this?
Also, do you think we should document your links and these lines of reasoning in a style guide?
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.
BEM is good and known, that's why I can read your SCSS
and diverging from a standard needs explanation.
The css_style_guide.md looks to me the right place for that.
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.
@cjcenizal, thanks for the historic references. I tend to agree with you and @PopradiArpad that this looks like a good exemption from the rule. We should definitely document that somewhere. I will create a PR to amend the css style guide.
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.
for the record, the aforementioned PR is #12276
@@ -12,58 +11,82 @@ import { | |||
} from '../../../../components'; | |||
|
|||
export default () => { | |||
/** | |||
* These styles are just for demonstration purposes. It is recommended use |
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.
Oops, had a typo in the proposed text 😊 better: It is recommended to use...
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.
... and I haven't caught that.... ooops :)
Ok
jenkins, test this |
jenkins, test this dangit! |
Woohoo!! 🎯 |
Huhh... This should replace PR #12176
([UI Framework] Reactify kuiCard and related CSS components)
which got stuck at rebase :(