Init CSS variables

This commit is contained in:
Jeremy Thomas
2019-09-20 11:40:21 +01:00
parent d4b86bb4d5
commit 4be21d8b75
6 changed files with 193 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
@charset "utf-8"
@import "initial-variables.sass"
@import "functions.sass"
@import "functions.scss"
@import "derived-variables.sass"
@import "animations.sass"
@import "mixins.sass"

View File

@@ -81,7 +81,53 @@ $size-large: $size-4 !default
$custom-colors: null !default
$custom-shades: null !default
$colors: mergeColorMaps(("white": ($white, $black), "black": ($black, $white), "light": ($light, $light-invert), "dark": ($dark, $dark-invert), "primary": ($primary, $primary-invert), "link": ($link, $link-invert), "info": ($info, $info-invert), "success": ($success, $success-invert), "warning": ($warning, $warning-invert), "danger": ($danger, $danger-invert)), $custom-colors) !default
$colors: mergeColorMaps(("white": ($white, $black, "black"), "black": ($black, $white, "white"), "light": ($light, $light-invert, "dark"), "dark": ($dark, $dark-invert, "light"), "primary": ($primary, $primary-invert), "link": ($link, $link-invert), "info": ($info, $info-invert), "success": ($success, $success-invert), "warning": ($warning, $warning-invert), "danger": ($danger, $danger-invert)), $custom-colors) !default
$shades: mergeColorMaps(("black-bis": $black-bis, "black-ter": $black-ter, "grey-darker": $grey-darker, "grey-dark": $grey-dark, "grey": $grey, "grey-light": $grey-light, "grey-lighter": $grey-lighter, "white-ter": $white-ter, "white-bis": $white-bis), $custom-shades) !default
$sizes: $size-1 $size-2 $size-3 $size-4 $size-5 $size-6 $size-7 !default
@function findLightColor($color)
@if type-of($color) == 'color'
@return change-color($color, $lightness: 96%)
@return $background
@function findDarkColor($color)
@if type-of($color) == 'color'
@return change-color($color, $lightness: 29%)
@return $text-strong
=css-variable($color, $name, $cssvar-invert)
$hue: hue($color)
$saturation: saturation($color)
$lightness: lightness($color)
$base: "#{$prefix}#{$name}"
--#{$base}-h: #{$hue}
--#{$base}-s: #{$saturation}
--#{$base}-l: #{$lightness}
--#{$base}: hsl(var(--#{$base}-h), calc(var(--#{$base}-s)), calc(var(--#{$base}-l)))
--#{$base}-hover: hsl(var(--#{$base}-h), calc(var(--#{$base}-s)), calc(var(--#{$base}-l) - 5%))
--#{$base}-active: hsl(var(--#{$base}-h), calc(var(--#{$base}-s)), calc(var(--#{$base}-l) - 10%))
$light: findLightColor($color)
--#{$base}-light: #{$light}
--#{$base}-light-hover: #{darken($light, 5%)}
--#{$base}-light-active: #{darken($light, 10%)}
$dark: findDarkColor($color)
--#{$base}-dark: #{$dark}
--#{$base}-dark-hover: #{darken($dark, 5%)}
--#{$base}-dark-active: #{darken($dark, 10%)}
@if $cssvar-invert
--#{$base}-invert: var(--#{$prefix}#{$cssvar-invert})
@else
--#{$base}-invert: #{findColorInvert($color)}
\:root
@each $name, $trio in $colors
$color: nth($trio, 1)
$color-invert: nth($trio, 2)
$cssvar-invert: false
@if length($trio) > 2
$cssvar-invert: nth($trio, 3)
+css-variable($color, $name, $cssvar-invert)

View File

@@ -65,3 +65,20 @@
@return rgba(#000, 0.7)
@else
@return #fff
@function findLightColor($color)
@if type-of($color) == 'color'
@return change-color($color, $lightness: 96%)
@return $background
@function findDarkColor($color)
@if type-of($color) == 'color'
@return change-color($color, $lightness: 29%)
@return $text-strong
@function getCssVariable($color, $name)
$hue: hue($color)
$saturation: saturation($color)
$lightness: lightness($color)
$alpha: alpha($color)
@return $hue, $saturation, $lightness

View File

@@ -71,7 +71,9 @@ $radius: 4px !default
$radius-large: 6px !default
$radius-rounded: 290486px !default
$speed: 86ms !default
$prefix: "bulma-"
// Flags
$variable-columns: true !default
$css-variables: true !default