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

Updated utility API (css-vars utils and new bg/color utils), plus new root CSS variables #34100

Merged
merged 4 commits into from
Aug 4, 2021

Conversation

mdo
Copy link
Member

@mdo mdo commented May 24, 2021

Consider this a bit of an integration branch for now while work on v5.0.2 continues. I'm using this to consolidate efforts across a handful of PRs.


Changes

  • cda10d6: Updates .text-{color} and .bg-{color} utilities to use CSS variables.

    Both .text-{color} and .bg-{color} utilities are now powered by CSS variables. For example, we use the new --bs-primary-rgb: 13, 110, 253 and --bs-text-opacity (with no default value, but a fallback of 1) in .text-primary where the new computed style is color: rgba(13, 110, 253, 1).

    We generate these new RGB variables with some new functions that convert hex values to RGB and that generate new Sass maps based on our $theme-colors map. These new maps are now used to generate our utilities for text color and background-color and include new options for .{text|bg}-black, .{text|bg}-white, and .{text|bg}-body.

    The utility API has been updated to include a new css-var boolean option. When set to true, it generates only local CSS variables using the API's class and individual values. This is how we've added our new .text-opacity-* and .bg-opacity-* utilities. Add these new classes alonside .text-{color} and .bg-{color} utilities to set their alpha transparency on the fly.

    This also deprecates .text-black-50 and .text-white-50 since we can create those on the fly now.

    Fixes V5 Utilities : Add Border Opacity #33320. Fixes Utilities like .text-light should use the root variables defined (in this case, --bs-light)  #33985.

  • c754e3e: Adds additional :root CSS variables for all our shades of gray and some $body- Sass variables.

    Previously our :root CSS variables only included our $colors and $theme-colors. Now they also include $grays. We've also added new CSS variables for common <body> styles with default values set by their Sass variable counterparts (e.g., --#{$variable-prefix}body-color: #{$body-color};).

@septatrix
Copy link
Contributor

What are your thoughts (or plans) about using HSL as suggested in this comment #32424 (comment)? While they cannot replace SCSS mix() they might still be advantageous in certain situations (e.g. change the primary shade while keeping saturation and lightness). Such cases may be rare and only a slight advantage but on the other hand there are no real disadvantages compared to traditional RGB.

@mdo mdo changed the title v5.1.0-dev Updated utility API (css-vars utils and new bg/color utils), plus new root CSS variables Jun 23, 2021
@mdo mdo marked this pull request as ready for review June 23, 2021 04:59
@mdo mdo requested a review from a team as a code owner June 23, 2021 04:59
ffoodd
ffoodd previously requested changes Jul 6, 2021
Copy link
Member

@ffoodd ffoodd left a comment

Choose a reason for hiding this comment

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

I like the way you did this!

A bit worried about file size and mostly how people will use this, but that's definitely a good step forward :)

@mdo
Copy link
Member Author

mdo commented Jul 7, 2021

Pushed a couple commits @ffoodd—let me know what you think! Basically trying to find a simple way to ignore the output of a CSS variable if the Sass value is null. I think this works? Did something similar in #34443.

@mdo mdo force-pushed the v510-dev branch 3 times, most recently from 1126322 to aa1c14e Compare July 19, 2021 03:41
@mdo mdo dismissed ffoodd’s stale review July 25, 2021 17:01

Changes addressed

@mdo mdo requested a review from ffoodd July 25, 2021 17:02
Copy link
Member

@ffoodd ffoodd left a comment

Choose a reason for hiding this comment

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

A few typos but the overall looks fine 🎉

mdo and others added 4 commits August 3, 2021 16:59
- Adds new functions to generate additional Sass maps
- Adds new root variables for rgb() versions of our theme colors, plus a few extras
- Adds ability to change the alpha transparency of text color and background color utilities with new utilities, inline styles, or local CSS var
- Updates documentation for color and background-color utilities pages
- Deprecates .text-black-50 and .text-white-50 since those (and additional transparency levels) can be generated on the fly

Change approach slightly to prevent cascade
- Adds grayscale colors
- Adds root and body variables

Note that some Sass variables default to `null`, so as we generate and use the CSS variable, we'll be potentially adding some lines of code.
@mdo mdo merged commit 1e9446c into main Aug 4, 2021
@mdo mdo deleted the v510-dev branch August 4, 2021 00:06
@mdo mdo mentioned this pull request Feb 11, 2022
41 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants