question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v5: Improve customization by allowing manually setting calculated variables in styles

See original GitHub issue

Hello!

We can have cases when we need to change specific style property, but we can’t do this because this property value set up in Bootstrap library as calculated formula. The idea is to create separate variables for these cases and precalculate it in default values of these variables.

The same was done in this issue and PR, but only for button component: https://github.com/twbs/bootstrap/issues/28899 https://github.com/twbs/bootstrap/pull/29444

The idea is to follow this practice in all components.

Example

Before:

@mixin list-group-item-variant($state, $background, $color) {
  .list-group-item-#{$state} {
    // ...
    background-color: darken($background, 5%);
    // ...
  }
}

After:

@mixin list-group-item-variant($state, $background, $color, $background-hover: darken($background, 5%)) {
  .list-group-item-#{$state} {
    // ...
    background-color: $background-hover;
    // ...
  }
}

The same can be done not only for colors, but for calculated unit values:

Before:

.card-subtitle {
  margin-top: -$card-spacer-y / 2;
}

After:

// In variables:
$card-subtitle-spacer: -$card-spacer-y / 2 !default;

// In styles:
.card-subtitle {
  margin-top: $card-subtitle-spacer;
}

Benefits

  • Allows to customize more properties and if you don’t need - just keep default calculation of the value
  • Allows to transform it to CSS variable usage by setting e.g. $background-hover: var(--bs-background-hover); (if we have background-color: darken($background, 5%); we can’t do this)

Drawbacks

  • More variables to support
  • Longer migration guide (probably)

What do you thik about this? Should I do a PR?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
septatrixcommented, Dec 10, 2020

I really like this idea though I think it will be most useful for colors (and therefore theming). The majority of people is unlikely to tinker with margins. Instead there is an abundance of people wanting to tweak and adjust colors.

Introducing this for parameters unrelated to colors is certainly nice however it needs to be carefully evaluated what properties are of relevance and as @mdo pointed out where some distinctions are over-engineered and superfluous.

Where I cannot wait for this feature however are colors. Bundled with css custom properties this allows many great new opportunities while still being backwards compatible. Many components calculate colors based on the SCSS color map and this map also gets exported as css variables. However as lightening and darkening of these colors is necessary the components do not use the css variables themself. Changing them therefore has no effect but they only grant the ability to match one’s own css to the bootstrap colors.

Most variables are however already defined inside variables.scss. Some of these are already exposed as css variables and actually used by components (tables, some gutters, breadcrumb divider). Expanding the usage of this pattern seems to be a goal of the bootstrap authors and I expect more components to adopt this behaviour for v5.1 (as I do not expect any substantial features for the next beta(s)) as it is backwards compatible. What I am really excited for however would the adoption of this pattern for colors. This would enable many possibilities of changing things during the runtime (e.g. dark and light theme).

2reactions
ydmitrycommented, Jan 13, 2021

Personally, I’m still interested in these changes, I think better not to do this for sizes, only for colors and do small PRs as you said

If I’m only one contributor for this issue I need to know target dates for beta to check if I can contribute

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use custom properties (CSS variables) in bootstrap #26596
Using CSS variables will allow to provide runtime configuration for styling, such as colors. CSS variables can work in conjunction of SASS.
Read more >
Using CSS custom properties (variables) - MDN Web Docs
Custom properties allow a value to be stored in one place, then referenced in multiple other places. An additional benefit is semantic ...
Read more >
Release notes — Pine Script™ v5 User Manual ... - TradingView
They allow users to create custom types that organize different values under one logical entity. A detailed rundown of the new functionality can...
Read more >
Create USS variables - Unity - Manual
When you update a variable, it updates all the USS properties that use it. For example, the following USS snippet defines one style...
Read more >
Where variables can be used - GitLab Docs
yml , variables from triggers, variables from pipeline schedules). Not supported are variables defined in the GitLab Runner config.toml and variables created in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found