Skip to content

Commit

Permalink
fix(theming): Ensure that maxcontrast text has always a contrast of 4…
Browse files Browse the repository at this point in the history
….5:1 even on hover

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Oct 4, 2023
1 parent 7641af5 commit 17a051a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
6 changes: 3 additions & 3 deletions apps/theming/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
--color-placeholder-light: #e6e6e6;
--color-placeholder-dark: #cccccc;
--color-main-text: #222222;
--color-text-maxcontrast: #767676;
--color-text-maxcontrast-default: #767676;
--color-text-maxcontrast: #707070;
--color-text-maxcontrast-default: #707070;
--color-text-maxcontrast-background-blur: #646464;
--color-text-light: #222222;
--color-text-lighter: #767676;
--color-text-lighter: #707070;
--color-scrollbar: rgba(34,34,34, .15);
--color-error: #d91812;
--color-error-rgb: 217,24,18;
Expand Down
5 changes: 3 additions & 2 deletions apps/theming/lib/Themes/DefaultTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public function getMediaQuery(): string {
public function getCSSVariables(): array {
$colorMainText = '#222222';
$colorMainTextRgb = join(',', $this->util->hexToRGB($colorMainText));
$colorTextMaxcontrast = $this->util->lighten($colorMainText, 33);
// Color that still provides enough contrast for text, so we need a ratio of 4.5:1 on main background AND hover
$colorTextMaxcontrast = '#707070'; // 4.54 : 1 for hover background
$colorMainBackground = '#ffffff';
$colorMainBackgroundRGB = join(',', $this->util->hexToRGB($colorMainBackground));
$colorBoxShadow = $this->util->darken($colorMainBackground, 70);
Expand Down Expand Up @@ -138,7 +139,7 @@ public function getCSSVariables(): array {
'--color-text-maxcontrast-default' => $colorTextMaxcontrast,
'--color-text-maxcontrast-background-blur' => $this->util->darken($colorTextMaxcontrast, 7),
'--color-text-light' => $colorMainText,
'--color-text-lighter' => $this->util->lighten($colorMainText, 33),
'--color-text-lighter' => $this->util->lighten($colorMainText, 30),

'--color-scrollbar' => 'rgba(' . $colorMainTextRgb . ', .15)',

Expand Down
13 changes: 13 additions & 0 deletions apps/theming/lib/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ public function toHSL(int $red, int $green, int $blue): array {
return array_values($color->getHsl());
}

/**
* Convert HSL to RGB Hex
*
* @param float $hue
* @param float $saturation
* @param float $lightness
*
* @return string
*/
public function toHex(float $hue, float $saturation, float $lightness): string {
return Color::hslToHex(['H' => $hue, 'S' => $saturation, 'L' => $lightness]);
}

/**
* @param string $color rgb color value
* @return float
Expand Down
2 changes: 1 addition & 1 deletion core/css/server.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/css/server.css.map

Large diffs are not rendered by default.

0 comments on commit 17a051a

Please sign in to comment.