Skip to content

Commit c3e2cdc

Browse files
committed
feat: add contrast-ratio-correction function
1 parent 554aa81 commit c3e2cdc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

scss/_functions.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003
126126
@return if($l1 > $l2, ($l1 + .05) / ($l2 + .05), ($l2 + .05) / ($l1 + .05));
127127
}
128128

129+
@function contrast-ratio-correction($color, $background, $scale, $state) {
130+
@if ($enable-contrast-ratio-correction) {
131+
$contrast-ratio: contrast-ratio($background, $color);
132+
@if $contrast-ratio < $min-contrast-ratio {
133+
@if $enable-contrast-ratio-warnings {
134+
@warn "#{$state} contrast ratio #{$contrast-ratio}.";
135+
}
136+
@return mix($color, color-contrast($background), abs($scale));
137+
}
138+
}
139+
@return $color;
140+
}
141+
129142
// Return WCAG2.0 relative luminance
130143
// See https://www.w3.org/WAI/GL/wiki/Relative_luminance
131144
// See https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests

0 commit comments

Comments
 (0)