Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Merge requests
  • !24074

Improve theme-color-level() using abs()

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/schwastek/new-theme-color-level into v4-dev Sep 24, 2017
  • Overview 0
  • Commits 4
  • Pipelines 0
  • Changes 1

Created by: schwastek

Concerns function theme-color-level() in _functions.scss file.

Use internal Sass function abs() to get the absolute value of $level argument.

That way, if/else statement can be completely eliminated.

Screenshot

Both - old and new functions - return the same values.

new theme-color-level function values

Test

Check out this pull request locally or reproduce it from scratch:

  1. Run:
git clone https://github.com/twbs/bootstrap.git
cd bootstrap
# remove all files but `scss` and `.git` folders
find -not \( \( -path ./.git -o -path ./scss \) -prune \) -exec rm -rf {} +
touch ./scss/_debug.scss
printf "@import 'functions';\n@import 'variables';\n@import 'debug';" > ./scss/bootstrap.scss
npm init --yes
npm install nodemon node-sass --save-dev
  1. Overwrite scripts section in package.json with:
"scripts": {
    "css-compile": "node-sass ./scss/bootstrap.scss ./dist/css",
    "watch-css": "nodemon --ext scss --watch ./scss --exec \"npm run css-compile\""
  }
  1. Add at the end of _functions.scss:
// _functions.scss
(...)
@function new-theme-color-level($color-name: "primary", $level: 0) {
  $color: theme-color($color-name);
  $color-base: if($level > 0, #000, #fff);
  $level: abs($level);
  
  @return mix($color-base, $color, $level * $theme-color-interval);
}
  1. Paste into _debug.scss:
@debug theme-color-level("primary", -1);
@debug theme-color-level("primary", 0);
@debug theme-color-level("primary", 1);

@debug new-theme-color-level("primary", -1);
@debug new-theme-color-level("primary", 0);
@debug new-theme-color-level("primary", 1);
  1. Run:
npm run css-compile
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/schwastek/new-theme-color-level