Skip to content
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

Merged

Conversation

PopradiArpad
Copy link
Contributor

Huhh... This should replace PR #12176
([UI Framework] Reactify kuiCard and related CSS components)
which got stuck at rebase :(

@elasticmachine
Copy link
Contributor

Can one of the admins verify this patch?

KuiCardGroup.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
isUnited: PropTypes.bool
Copy link
Member

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.

Copy link
Contributor Author

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 = {
Copy link
Member

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.
 */

Copy link
Contributor Author

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.

@weltenwort
Copy link
Member

And before I forget it: It's awesome that you invest the effort into this, @PopradiArpad. Thank you for contributing! ❤️

@PopradiArpad
Copy link
Contributor Author

@weltenwort Thanks for your review!

@PopradiArpad
Copy link
Contributor Author

Better example layout. See the comment of @cjcenizal at #12176

Copy link
Contributor

@cjcenizal cjcenizal left a 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>
Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@cjcenizal
Copy link
Contributor

jenkins, test this

@cjcenizal cjcenizal added Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. release_note:enhancement v6.0.0 v6.0.0-beta1 labels Jun 9, 2017
@cjcenizal
Copy link
Contributor

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

@PopradiArpad PopradiArpad force-pushed the uiframework/feature/reactify-card3 branch from 977da71 to d8373b6 Compare June 9, 2017 08:36
@PopradiArpad
Copy link
Contributor Author

@cjcenizal Super doc! Thanks for the review!

Copy link
Member

@weltenwort weltenwort left a 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 {
Copy link
Member

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:

@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?

Copy link
Contributor Author

@PopradiArpad PopradiArpad Jun 9, 2017

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.

Copy link
Contributor

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:

  1. 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.
  2. 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?

Copy link
Contributor Author

@PopradiArpad PopradiArpad Jun 9, 2017

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.

Copy link
Member

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.

Copy link
Member

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
Copy link
Member

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...

Copy link
Contributor Author

@PopradiArpad PopradiArpad Jun 9, 2017

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

@cjcenizal
Copy link
Contributor

jenkins, test this

@cjcenizal
Copy link
Contributor

jenkins, test this dangit!

@cjcenizal cjcenizal merged commit 1e71d11 into elastic:master Jun 13, 2017
@cjcenizal
Copy link
Contributor

Woohoo!! 🎯

@PopradiArpad PopradiArpad deleted the uiframework/feature/reactify-card3 branch June 13, 2017 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:enhancement Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. v6.0.0-beta1 v6.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants