Skip to content

Commit

Permalink
Use brand color for background only and keep accessible color as colo…
Browse files Browse the repository at this point in the history
…r primary

Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Sep 29, 2022
1 parent 38033b1 commit 317e366
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions apps/theming/css/default.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
:root {
--color-main-background: #ffffff;
--color-main-background-plain-preview: #0082c9;
--color-main-background-rgb: 255,255,255;
--color-main-background-translucent: rgba(var(--color-main-background-rgb), .97);
--color-main-background-blur: rgba(var(--color-main-background-rgb), .8);
Expand Down
2 changes: 1 addition & 1 deletion apps/theming/css/settings-admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apps/theming/css/settings-admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
margin-top: 10px;
margin-bottom: 20px;
cursor: pointer;
background-color: var(--color-primary);
background-color: var(--color-main-background-plain-preview, var(--color-primary));
background-image: var(--image-background, var(--image-background-plain, url('../../../core/img/app-background.jpg'), linear-gradient(40deg, #0082c9 0%, #30b6ff 100%)));

#theming-preview-logo {
Expand Down Expand Up @@ -145,4 +145,4 @@
svg, img {
transition: 500ms filter linear;
}
}
}
6 changes: 4 additions & 2 deletions apps/theming/lib/Service/BackgroundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
class BackgroundService {
// true when the background is bright and need dark icons
public const THEMING_MODE_DARK = 'dark';
public const DEFAULT_COLOR = '#0082c9';
public const DEFAULT_ACCESSIBLE_COLOR = '#00639a';

public const SHIPPED_BACKGROUNDS = [
'anatoly-mikhaltsov-butterfly-wing-scale.jpg' => [
Expand Down Expand Up @@ -90,8 +92,8 @@ class BackgroundService {
'kamil-porembinski-clouds.jpg' => [
'attribution' => 'Clouds (Kamil Porembiński, CC BY-SA)',
'attribution_url' => 'https://www.flickr.com/photos/paszczak000/8715851521/',
// Originally #0082c9 but adjusted for accessibility
'primary_color' => '#00639a',
// Originally used the default color but adjusted for accessibility
'primary_color' => self::DEFAULT_ACCESSIBLE_COLOR,
],
'bernard-spragg-new-zealand-fern.jpg' => [
'attribution' => 'New zealand fern (Bernard Spragg, CC0)',
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 @@ -65,7 +65,7 @@ public function __construct(Util $util,
$this->config = $config;
$this->l = $l;

$this->primaryColor = $this->themingDefaults->getColorPrimary();
$this->primaryColor = $this->themingDefaults->getColorPrimary(true);
}

public function getId(): string {
Expand Down Expand Up @@ -105,6 +105,7 @@ public function getCSSVariables(): array {

$variables = [
'--color-main-background' => $colorMainBackground,
'--color-main-background-plain-preview' => $this->themingDefaults->getColorPrimary(),
'--color-main-background-rgb' => $colorMainBackgroundRGB,
'--color-main-background-translucent' => 'rgba(var(--color-main-background-rgb), .97)',
'--color-main-background-blur' => 'rgba(var(--color-main-background-rgb), .8)',
Expand Down Expand Up @@ -235,7 +236,7 @@ public function getCSSVariables(): array {
$variables['--image-main-background'] = "url('" . $this->urlGenerator->linkTo(Application::APP_ID, "/img/background/$themingBackground") . "')";
} elseif (substr($themingBackground, 0, 1) === '#') {
unset($variables['--image-main-background']);
$variables['--color-main-background-plain'] = $this->primaryColor;
$variables['--color-main-background-plain'] = $this->themingDefaults->getColorPrimary();
}
}

Expand Down
13 changes: 9 additions & 4 deletions apps/theming/lib/ThemingDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,32 @@ public function getShortFooter() {
/**
* Color that is used for the header as well as for mail headers
*
* @param bool $accessible Set to `true` to return the accessible color variant
*
* @return string
*/
public function getColorPrimary() {
public function getColorPrimary($accessible = false) {
$user = $this->userSession->getUser();
$color = $this->config->getAppValue(Application::APP_ID, 'color', '');

if ($color === '' && !empty($user)) {
$themingBackground = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background', 'default');
if (isset(BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'])) {
$this->increaseCacheBuster();
return BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'];
$color = BackgroundService::SHIPPED_BACKGROUNDS[$themingBackground]['primary_color'];
} else if ($themingBackground === 'default') {
$this->increaseCacheBuster();
return BackgroundService::SHIPPED_BACKGROUNDS['kamil-porembinski-clouds.jpg']['primary_color'];
$color = BackgroundService::DEFAULT_COLOR;
}
}

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

if ($accessible && $color === BackgroundService::DEFAULT_COLOR) {
return BackgroundService::DEFAULT_ACCESSIBLE_COLOR;
}
return $color;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/theming/src/components/BackgroundSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default {
}

&.color {
background-color: var(--color-primary);
background-color: var(--color-main-background-plain-preview, var(--color-primary));
color: var(--color-primary-text);
}

Expand Down
2 changes: 1 addition & 1 deletion core/css/guest.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ body {
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';
color: var(--color-text);
text-align: center;
background-color: var(--color-primary);
background-color: var(--color-main-background-plain-preview, var(--color-primary));
background-image: var(--image-background, var(--image-background-plain, url('../../../core/img/app-background.jpg'), linear-gradient(40deg, #0082c9 0%, #30b6ff 100%)));
background-attachment: fixed;
min-height: 100%; /* fix sticky footer */
Expand Down
4 changes: 2 additions & 2 deletions dist/theming-theming-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/theming-theming-settings.js.map

Large diffs are not rendered by default.

0 comments on commit 317e366

Please sign in to comment.