Skip to content

Commit eb527ea

Browse files
committedOct 5, 2022
Use brand color for background only and keep accessible color as color primary
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent 397afa6 commit eb527ea

File tree

12 files changed

+45
-19
lines changed

12 files changed

+45
-19
lines changed
 

‎apps/theming/css/default.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
:root {
22
--color-main-background: #ffffff;
3+
--color-main-background-not-plain: #0082c9;
34
--color-main-background-rgb: 255,255,255;
45
--color-main-background-translucent: rgba(var(--color-main-background-rgb), .97);
56
--color-main-background-blur: rgba(var(--color-main-background-rgb), .8);

‎apps/theming/css/settings-admin.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎apps/theming/css/settings-admin.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
margin-top: 10px;
101101
margin-bottom: 20px;
102102
cursor: pointer;
103-
background-color: var(--color-primary);
103+
background-color: var(--color-main-background-not-plain, var(--color-primary));
104104
background-image: var(--image-background, var(--image-background-plain, url('../../../core/img/app-background.jpg'), linear-gradient(40deg, #0082c9 0%, #30b6ff 100%)));
105105

106106
#theming-preview-logo {
@@ -145,4 +145,4 @@
145145
svg, img {
146146
transition: 500ms filter linear;
147147
}
148-
}
148+
}

‎apps/theming/lib/Service/BackgroundService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
class BackgroundService {
4545
// true when the background is bright and need dark icons
4646
public const THEMING_MODE_DARK = 'dark';
47+
public const DEFAULT_COLOR = '#0082c9';
48+
public const DEFAULT_ACCESSIBLE_COLOR = '#00639a';
4749

4850
public const SHIPPED_BACKGROUNDS = [
4951
'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [
@@ -90,8 +92,7 @@ class BackgroundService {
9092
'kamil-porembinski-clouds.jpg' => [
9193
'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)',
9294
'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/',
93-
// Originally #0082c9 but adjusted for accessibility
94-
'primary_color' => '#00639a',
95+
'primary_color' => self::DEFAULT_COLOR,
9596
],
9697
'bernard-spragg-new-zealand-fern.jpg' => [
9798
'attribution' => 'New zealand fern (Bernard Spragg, CC0)',

‎apps/theming/lib/Themes/DefaultTheme.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public function __construct(Util $util,
6565
$this->config = $config;
6666
$this->l = $l;
6767

68-
$this->primaryColor = $this->themingDefaults->getColorPrimary();
68+
$initialPrimaryColor = $this->themingDefaults->getColorPrimary();
69+
// Override default color if set to improve accessibility
70+
$this->primaryColor = $initialPrimaryColor === BackgroundService::DEFAULT_COLOR ? BackgroundService::DEFAULT_ACCESSIBLE_COLOR : $initialPrimaryColor;
6971
}
7072

7173
public function getId(): string {
@@ -105,6 +107,7 @@ public function getCSSVariables(): array {
105107

106108
$variables = [
107109
'--color-main-background' => $colorMainBackground,
110+
'--color-main-background-not-plain' => $this->themingDefaults->getColorPrimary(),
108111
'--color-main-background-rgb' => $colorMainBackgroundRGB,
109112
'--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
110113
'--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
@@ -235,7 +238,7 @@ public function getCSSVariables(): array {
235238
$variables['--image-main-background'] = "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "/img/background/$themingBackground") . "')";
236239
} elseif (substr($themingBackground, 0, 1) === '#') {
237240
unset($variables['--image-main-background']);
238-
$variables['--color-main-background-plain'] = $this->primaryColor;
241+
$variables['--color-main-background-plain'] = $this->themingDefaults->getColorPrimary();
239242
}
240243
}
241244

‎apps/theming/lib/ThemingDefaults.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,17 @@ public function getColorPrimary() {
223223

224224
if ($color === '' && !empty($user)) {
225225
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
226-
if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) {
226+
if ($themingBackground === 'default') {
227227
$this->increaseCacheBuster();
228-
return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'];
229-
} else if ($themingBackground === 'default') {
228+
return BackgroundService::DEFAULT_COLOR;
229+
} else if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) {
230230
$this->increaseCacheBuster();
231-
return BackgroundService::SHIPPED_BACKGROUNDS['kamil-porembinski-clouds.jpg']['primary_color'];
231+
return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'];
232232
}
233233
}
234234

235235
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $color)) {
236-
return BackgroundService::SHIPPED_BACKGROUNDS['kamil-porembinski-clouds.jpg']['primary_color'];
236+
return BackgroundService::DEFAULT_COLOR;
237237
}
238238

239239
return $color;

‎apps/theming/src/components/BackgroundSettings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export default {
171171
}
172172

173173
&.color {
174-
background-color: var(--color-primary);
174+
background-color: var(--color-main-background-not-plain, var(--color-primary));
175175
color: var(--color-primary-text);
176176
}
177177

‎core/css/guest.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ body {
2323
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
2424
color: var(--color-text);
2525
text-align: center;
26-
background-color: var(--color-primary);
26+
background-color: var(--color-main-background-not-plain, var(--color-primary));
2727
background-image: var(--image-background, var(--image-background-plain, url('../../../core/img/app-background.jpg'), linear-gradient(40deg, #0082c9 0%, #30b6ff 100%)));
2828
background-attachment: fixed;
2929
min-height: 100%; /* fix sticky footer */

‎dist/theming-theming-settings.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/theming-theming-settings.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/acceptance/features/app-theming.feature

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ Feature: app-theming
99
# The "eventually" part is not really needed here, as the colour is not
1010
# being animated at this point, but there is no need to create a specific
1111
# step just for this.
12-
And I see that the primary color is eventually "#0082C9"
12+
And I see that the primary color is eventually "#00639a"
13+
And I see that the non-plain background color variable is eventually "#0082c9"
1314
When I set the "Color" parameter in the Theming app to "#C9C9C9"
1415
Then I see that the parameters in the Theming app are eventually saved
1516
And I see that the primary color is eventually "#C9C9C9"
17+
And I see that the non-plain background color variable is eventually "#C9C9C9"
1618

1719
Scenario: resetting the color updates the primary color
1820
Given I am logged in as the admin
@@ -22,6 +24,8 @@ Feature: app-theming
2224
And I set the "Color" parameter in the Theming app to "#C9C9C9"
2325
And I see that the parameters in the Theming app are eventually saved
2426
And I see that the primary color is eventually "#C9C9C9"
27+
And I see that the non-plain background color variable is eventually "#C9C9C9"
2528
When I reset the "Color" parameter in the Theming app to its default value
2629
Then I see that the parameters in the Theming app are eventually saved
27-
And I see that the primary color is eventually "#0082C9"
30+
And I see that the primary color is eventually "#00639a"
31+
And I see that the non-plain background color variable is eventually "#0082c9"

‎tests/acceptance/features/bootstrap/ThemingAppContext.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,23 @@ public function iSeeThatThePrimaryColorIsEventually($color) {
141141
}
142142
}
143143

144+
/**
145+
* @Then I see that the non-plain background color variable is eventually :color
146+
*/
147+
public function iSeeThatTheNonPlainBackgroundColorVariableIsEventually($color) {
148+
$colorVariableMatchesCallback = function () use ($color) {
149+
$colorVariable = $this->actor->getSession()->evaluateScript("return getComputedStyle(document.documentElement).getPropertyValue('--color-main-background-not-plain').trim();");
150+
$colorVariable = $this->getRGBArray($colorVariable);
151+
$color = $this->getRGBArray($color);
152+
153+
return $colorVariable == $color;
154+
};
155+
156+
if (!Utils::waitFor($colorVariableMatchesCallback, $timeout = 10 * $this->actor->getFindTimeoutMultiplier(), $timeoutStep = 1)) {
157+
Assert::fail("The non-plain background color variable is not $color yet after $timeout seconds");
158+
}
159+
}
160+
144161
/**
145162
* @Then I see that the parameters in the Theming app are eventually saved
146163
*/

0 commit comments

Comments
 (0)