Skip to content

Commit bcc6db7

Browse files
committed
refactor: add contrast ratio checker
1 parent a165df0 commit bcc6db7

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

scss/_alert.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@
4848
$border: var(--#{$variable-prefix}alert-#{$state}-border-color, map-get($map, "border"));
4949
$color: var(--#{$variable-prefix}alert-#{$state}-color, map-get($map, "color"));
5050
$link-color: var(--#{$variable-prefix}alert-#{$state}-link-color, map-get($map, "link-color"));
51-
// @if (contrast-ratio($background, $color) < $min-contrast-ratio) {
52-
// $color: mix($value, color-contrast($background), abs($alert-color-scale));
53-
// }
51+
// TODO: refactor
52+
@if ($enable-contrast-ratio-correction and contrast-ratio(map-get($map, "background"), map-get($map, "color")) < $min-contrast-ratio) {
53+
@if $enable-contrast-ratio-warnings {
54+
@warn "Alert #{$state} contrast ratio #{contrast-ratio(map-get($map, "background"), map-get($map, "color"))}.";
55+
}
56+
$color: var(--#{$variable-prefix}alert-#{$state}-color, mix(map-get($map, "color"), color-contrast(map-get($map, "background")), abs($alert-color-scale)));
57+
}
5458
.alert-#{$state} {
5559
@include alert-variant($background, $border, $color, $link-color);
5660
}

scss/_list-group.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,13 @@
155155
$background: var(--#{$variable-prefix}list-group-#{$state}-background, map-get($map, "background"));
156156
$background-hover: var(--#{$variable-prefix}list-group-#{$state}-background-hover, map-get($map, "background-hover"));
157157
$color: var(--#{$variable-prefix}list-group-#{$state}-color, map-get($map, "color"));
158-
// @if (contrast-ratio($background, $color) < $min-contrast-ratio) {
159-
// $color: mix($value, color-contrast($background), abs($alert-color-scale));
160-
// }
158+
// TODO: refactor
159+
@if ($enable-contrast-ratio-correction and contrast-ratio(map-get($map, "background"), map-get($map, "color")) < $min-contrast-ratio) {
160+
@if $enable-contrast-ratio-warnings {
161+
@warn "List group item #{$state} contrast ratio #{contrast-ratio(map-get($map, "background"), map-get($map, "color"))}.";
162+
}
163+
$color: var(--#{$variable-prefix}list-group-#{$state}-color, mix(map-get($map, "color"), color-contrast(map-get($map, "background")), abs($alert-color-scale)));
164+
}
161165

162166
@include list-group-item-variant($state, $background, $background-hover, $color);
163167
}

scss/_variables.scss

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -262,20 +262,22 @@ $escaped-characters: (
262262
//
263263
// Quickly modify global styling by enabling or disabling optional features.
264264

265-
$enable-caret: true !default;
266-
$enable-rounded: true !default;
267-
$enable-shadows: false !default;
268-
$enable-gradients: false !default;
269-
$enable-transitions: true !default;
270-
$enable-reduced-motion: true !default;
271-
$enable-smooth-scroll: true !default;
272-
$enable-grid-classes: true !default;
273-
$enable-button-pointers: true !default;
274-
$enable-rfs: true !default;
275-
$enable-validation-icons: true !default;
276-
$enable-negative-margins: false !default;
277-
$enable-deprecation-messages: true !default;
278-
$enable-important-utilities: true !default;
265+
$enable-caret: true !default;
266+
$enable-rounded: true !default;
267+
$enable-shadows: false !default;
268+
$enable-gradients: false !default;
269+
$enable-transitions: true !default;
270+
$enable-reduced-motion: true !default;
271+
$enable-smooth-scroll: true !default;
272+
$enable-grid-classes: true !default;
273+
$enable-button-pointers: true !default;
274+
$enable-rfs: true !default;
275+
$enable-validation-icons: true !default;
276+
$enable-negative-margins: false !default;
277+
$enable-deprecation-messages: true !default;
278+
$enable-important-utilities: true !default;
279+
$enable-contrast-ratio-correction: true !default;
280+
$enable-contrast-ratio-warnings: true !default;
279281

280282
// Set mobile breakpoint
281283

0 commit comments

Comments
 (0)