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

Simplify make-container() #31735

Merged
merged 2 commits into from
Nov 14, 2020
Merged

Conversation

ffoodd
Copy link
Member

@ffoodd ffoodd commented Sep 24, 2020

By dividing in the custom property directly:

  1. code is shorter,
  2. a single stylelint-disable rule
  3. easier override for paddings since we only have to change the custom property—without having to think about multiplying what we want by 2.

Any thoughts?

@ffoodd ffoodd requested a review from a team as a code owner September 24, 2020 08:31
@MartijnCuppens
Copy link
Member

Maybe rename the variable to --bs-gutter-x-half or something alike?

@ffoodd
Copy link
Member Author

ffoodd commented Sep 24, 2020

I don't think so: the value is half the gutter indeed, but we use it directly as a gutter and it's only used in containers. Overriding --bs-gutter-x-half wouldn't make any sense if we set it to $gutter for example.

I'd be in favor of keeping naming as-is, but any other arguments or ideas are welcome :)

@mdo
Copy link
Member

mdo commented Sep 24, 2020

Conceptually, I think we'd leave it as-is. The "gutter" is the combination of one column's right padding and the next column's left padding. We just have to divide it by 2 to apply it to both sides of those different columns.

But, if not, would we need to update the .row, too? I'm kinda fine keeping it as-is—does this have much of an impact to performance or anything? Or file size?

@mixin make-row($gutter: $grid-gutter-width) {
--bs-gutter-x: #{$gutter};
--bs-gutter-y: 0;
display: flex;
flex-wrap: wrap;
margin-top: calc(var(--bs-gutter-y) * -1); // stylelint-disable-line function-blacklist
margin-right: calc(var(--bs-gutter-x) / -2); // stylelint-disable-line function-blacklist
margin-left: calc(var(--bs-gutter-x) / -2); // stylelint-disable-line function-blacklist
}

@ffoodd
Copy link
Member Author

ffoodd commented Sep 24, 2020

I don't think it impacts performance in any way; it should decrease file size a bit, but it's probably not valable for a few bytes only.

Your call, IMHO this PR allows simpler override but I don't have any other good argument.

@ffoodd
Copy link
Member Author

ffoodd commented Sep 25, 2020

@mdo FYI in Boosted gutter depends on breakpoint: https://github.com/Orange-OpenSource/Orange-Boosted-Bootstrap/blob/v5-dev/scss/mixins/_container.scss

If I kept the current implementation, I'd have to multiply $gutter by 2 to have the correct value above breakpoint, which would be like calc(#{$gutter * 2} / 2) which doesn't make any sense.

Anyone in need to customize the gutter should redeclare padding (which feels weird when using custom properties) or take the division into account to virtually get the expected result (which feels weird too).

Does my explanations make any sense?

@mdo
Copy link
Member

mdo commented Sep 25, 2020

I can dig it. Should we also do it on the .row though since we have the same calc() function happening there?

@XhmikosR
Copy link
Member

FYI this is bigger than the current solution, check the bundlewatch output. Pretty small difference, but still, it doesn't reduce the file size :)

@MartijnCuppens
Copy link
Member

Ow, I misunderstood what this PR was doing, the "gutter" term confused me a bit (padding-x was a bit clearer imo).


We should do the division by 2 in our _variables file. In the current situation, if I set $container-padding-x to 20px, it would actually be 10px.

$container-padding-x: $grid-gutter-width !default;


To save some bytes, we could also make use of the default value parameter:

  padding-right: var(--bs-gutter-x, #{$gutter});
  padding-left: var(--bs-gutter-x, #{$gutter});

@ffoodd
Copy link
Member Author

ffoodd commented Sep 28, 2020

What a topic :D

Moving the division in our variables seems a good idea.

Using the fallback value too, might be turned into a more generic approach about custom properties, we don't need to declare them actually and it'd still allows easy override while being lighter.

@ffoodd ffoodd force-pushed the main-fod-simpler-make-container branch from 2537d64 to 46a8cd0 Compare September 28, 2020 09:21
@XhmikosR
Copy link
Member

@twbs/css-review so what's the plan here? Should we drop this or is it still valid?

@MartijnCuppens
Copy link
Member

The current implementation is wrong, as I explained in #31735 (comment). We should fix this one way or another.

@ffoodd
Copy link
Member Author

ffoodd commented Nov 13, 2020

@MartijnCuppens I implemented your suggestions, is there anything else missing?

Copy link
Member

@MartijnCuppens MartijnCuppens left a comment

Choose a reason for hiding this comment

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

Perfect, @ffoodd 👌

@XhmikosR
Copy link
Member

This needs a rebase :)

ffoodd and others added 2 commits November 14, 2020 13:39
By dividing by 2 in the custom property directly:
1. code is shorter,
2. a single `stylelint-disable` rule
3. easier override for `padding`s since we only have to change the custom property—without having to think about multiplying what we want by 2.

Any thoughts?
@MartijnCuppens MartijnCuppens force-pushed the main-fod-simpler-make-container branch from 46a8cd0 to 95c2a7b Compare November 14, 2020 12:41
@MartijnCuppens MartijnCuppens changed the title Simplify make-container() a bit Simplify make-container() Nov 14, 2020
@MartijnCuppens MartijnCuppens merged commit 44fef16 into main Nov 14, 2020
@MartijnCuppens MartijnCuppens deleted the main-fod-simpler-make-container branch November 14, 2020 13:33
@XhmikosR XhmikosR changed the title Simplify make-container() Simplify make-container() Nov 14, 2020
@ffoodd ffoodd mentioned this pull request Nov 19, 2020
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants