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

Add numbers between 1 and 10 for flexGrow #144

Merged
merged 7 commits into from
Nov 15, 2017

Conversation

zinckiwi
Copy link
Contributor

Here's the proposal for arbitrary (well, up to a certain point) weighting for FlexItem.

@zinckiwi
Copy link
Contributor Author

Another immediate use case; I'd want about a 1/4 - 3/4 split here between version and type.

image

@zinckiwi
Copy link
Contributor Author

Oh, and entry in the docs:

image

@@ -7,6 +7,7 @@ export const EuiFlexItem = ({ children, className, grow, ...rest }) => {
'euiFlexItem',
{
'euiFlexItem--flexGrowZero': !grow,
[`euiFlexItem--flexGrow${grow}`]: Number(parseFloat(grow)) === grow && grow >= 1 && grow <= 10
Copy link
Contributor

Choose a reason for hiding this comment

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

How come thing is parseFloat, as opposed to parseInt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

absentmindedness, that's why

@@ -7,6 +7,7 @@ export const EuiFlexItem = ({ children, className, grow, ...rest }) => {
'euiFlexItem',
{
'euiFlexItem--flexGrowZero': !grow,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need guarding against a numeric value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think so. Any falsy value would work, proptypes says bool or number, so that's 0 or false.

@pugnascotia
Copy link
Contributor

Just to check - do these layouts still collapse as you'd expect on mobile?

@zinckiwi
Copy link
Contributor Author

Yep, collapsing works fine.

Copy link
Contributor

@pugnascotia pugnascotia left a comment

Choose a reason for hiding this comment

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

LGTM

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.

This is sweet! I just had a couple minor comments.

@@ -7,6 +7,7 @@ export const EuiFlexItem = ({ children, className, grow, ...rest }) => {
'euiFlexItem',
{
'euiFlexItem--flexGrowZero': !grow,
[`euiFlexItem--flexGrow${grow}`]: Number(parseInt(grow)) === grow && grow >= 1 && grow <= 10
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a prop type checker to contain these conditions, and throw errors if it fails?

Copy link
Contributor

@cjcenizal cjcenizal Nov 14, 2017

Choose a reason for hiding this comment

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

Can this just be

[`euiFlexItem--flexGrow${grow}`]: grow

now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends how much you trust people to fix prop type warnings I suppose! For the sake of that extra bit, I'd personally favour not adding superfluous classes, but can change if anyone contends otherwise (including yourself).

Copy link
Contributor

Choose a reason for hiding this comment

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

It can still be a boolean though, no?

Copy link
Contributor Author

@zinckiwi zinckiwi Nov 14, 2017

Choose a reason for hiding this comment

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

(though even then we'd need to catch true)

edit: nm, 1 == true

edit edit: I must be tired. Precisely because true >= 1 === true we'd need to catch it

Copy link
Contributor

@cjcenizal cjcenizal Nov 14, 2017

Choose a reason for hiding this comment

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

Hmm, my instinct is to simplify this as much as possible, which would mean relying on the prop-types error and the CSS to apply the correct styling. That way if someone passes in "11", debugging means checking 2 places instead of 3. And likewise adding support for 11 means making changes in 2 places instead of 3.

That being said, I don't feel very strongly about this. It's your call. 😄

EDIT: In terms of supporting the boolean value, then I think this will do the trick?

[`euiFlexItem--flexGrow${grow}`]: grow && grow > 0

export default () => (
<div>
<EuiFlexGroup>
<EuiFlexItem grow={1}>1</EuiFlexItem>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some additional content to this first item to demonstrate that it wraps without pushing the column wider?

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.

LGTM! Had one optional comment.

<EuiFlexItem grow={2}>2</EuiFlexItem>
<EuiFlexItem grow={3}>3</EuiFlexItem>
<EuiFlexItem grow={2}>2<br />wraps content if necessary</EuiFlexItem>
<EuiFlexItem grow={3}>3<br />expands_to_fit_if_content_cannot_wrap</EuiFlexItem>
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!


if (validValues.indexOf(value) === -1) {
return new Error(
'Prop `' + propName + '` supplied to' + ' `' + componentName + '` must be a boolean or an integer between 1 and 10.'
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want, you could use a template literal here:

`Prop \`${propName}\` supplied to \`'${componentName}\` must be a boolean or an integer between 1 and 10.`

@zinckiwi
Copy link
Contributor Author

Rather than dancing around JS hoops with true vs 1, whitelisted the numeric values. That work?

Copy link
Contributor

@snide snide left a comment

Choose a reason for hiding this comment

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

I think the implementation is fine. My only worry is that this flexibility might create some choose your own adventure grid systems.

Cons:

  • It requires stacking if you want two rows.
  • Because of that, it'll require you to use an EuiSpacer to manage the spacing between those rows. You'd need to know to match the spacing size against the gutter size if you used anything but the defaults.

Pros:

  • As long as you're aware of those cons, you can configure any layout you likely want. But you'll need to hand construct it.

Possible alternative

We also apply this to EuiFlexGrid and allow the grow prop to take on the number of columns passed to the parent wrapper. Meaning I could set columns={12} and pass grow={4}, grow={4}, grow={4}, grow={6}, grow={6} on flex items inside to create 3 columns on row 1 and 2 columns on row 2. This would allow for more conventional wraps and act similar to similar grid systems. The downside here is that "grow" would mean two different things depending upon the wrapper (grow in Group is proportional against a total, grow in Grid is proportional against a passed number of allowed columns).

I'm just spitballing here. If people are OK with Scott's implementation I think it's flexible enough to work how we'd want, but it would be off-pattern for how people normal consume grids (ands that OK, I'm just bringing it up).

FWIW we could add the grid style one in a later PR.

<EuiFlexItem grow={4}>4</EuiFlexItem>
</EuiFlexGroup>

<br/><br/>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an EuiSpacer. It will create a vertical margin to match the horizontal ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I copied from an adjacent block, FYI)

Copy link
Contributor

Choose a reason for hiding this comment

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

Then change it there too if you have time. Likely I built this stuff before I had spacer built. 😢

I always assume people will copy code out of the docs literally, so we should show them how to properly space stuff when we can.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the instances of <br /><br /> in the flex area.

@cjcenizal
Copy link
Contributor

Rather than dancing around JS hoops with true vs 1, whitelisted the numeric values. That work?

👍

@snide If the additions you have in mind won't require changing or removing the functionality added in this PR, then I think this is a good step forward. The cons you mention sound like good things to be aware of when building layouts with these tools.

@zinckiwi Maybe in a subsequent PR you can add a sandbox which demonstrates a layout using EuiFlexGroup, EuiFlexItem and EuiSpacer, so we can have a copy/pasteable example of best practices?

@snide
Copy link
Contributor

snide commented Nov 14, 2017

@cjcenizal Yeah, I agree. This is fine to merge. My stuff can go in later, and more likely, we'll need to create better "layout" documentation.

@cjcenizal
Copy link
Contributor

It's great that we're adding this because I actually need this now in Kibana!

Desired layout:

image

What I can do right now:

image

@zinckiwi zinckiwi merged commit 4105fd6 into elastic:master Nov 15, 2017
snide pushed a commit to snide/eui that referenced this pull request Nov 15, 2017
* Add numbers between 1 and 10 for flexGrow

* Parse grow prop better

* Add more granular prop type checking to FlexItem and expand doc

* Add changelog entry

* Switch string to interpolated

* Be explicit with grow prop className building

* Clean up double-brs in docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants