From a0dd474bc6486ec573e7319aa9e95862f8ca923b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Poupard?= Date: Tue, 7 Apr 2020 15:59:51 +0200 Subject: [PATCH] docs(theming): display contrast ratios in color swatches --- site/assets/scss/_colors.scss | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/site/assets/scss/_colors.scss b/site/assets/scss/_colors.scss index 911c44c736..17c6783658 100644 --- a/site/assets/scss/_colors.scss +++ b/site/assets/scss/_colors.scss @@ -6,6 +6,37 @@ .swatch-#{$color} { color: color-contrast($value); background-color: #{$value}; + + &::after { + $contrast-ratio: "#{contrast-ratio($value, color-contrast($value))}"; + $against-white: "#{contrast-ratio($value, $white)}"; + $against-black: "#{contrast-ratio($value, $black)}"; + position: absolute; + top: 1rem; + right: 1rem; + padding-left: 1rem; + font-size: .75rem; + line-height: 1.35; + white-space: pre; + content: + str-slice($contrast-ratio, 1, 4) "\A" + str-slice($against-white, 1, 4) "\A" + str-slice($against-black, 1, 4); + background-color: $value; + background-image: + linear-gradient( + to bottom, + transparent .25rem, + color-contrast($value) .25rem .75rem, + transparent .75rem 1.25rem, + $white 1.25rem 1.75rem, + transparent 1.75rem 2.25rem, + $black 2.25rem 2.75rem, + transparent 2.75rem + ); + background-repeat: no-repeat; + background-size: .5rem 100%; + } } }