Skip to content

Commit f9b1386

Browse files
committed
Initiate Morpheus Dark mode
1 parent 0208e11 commit f9b1386

File tree

4 files changed

+58
-46
lines changed

4 files changed

+58
-46
lines changed

core/Plugin/Controller.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ protected function setBasicVariablesNoneAdminView($view)
762762
$view->logoSVG = $customLogo->getSVGLogoUrl();
763763
$view->hasSVGLogo = $customLogo->hasSVGLogo();
764764
$view->contactEmail = implode(',', Piwik::getContactEmailAddresses());
765+
// TODO: fetch dark mode preferences
765766
$view->themeStyles = ThemeStyles::get();
766767

767768
$general = PiwikConfig::getInstance()->General;

core/Plugin/ThemeStyles.php

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class ThemeStyles
1515
{
16+
1617
// to maintain BC w/ old names that were defined in LESS
1718
private static $propertyNamesToLessVariableNames = [
1819
'fontFamilyBase' => 'theme-fontFamily-base',
@@ -49,162 +50,168 @@ class ThemeStyles
4950
];
5051

5152
/**
52-
* @var string
53+
* @var boolean
54+
*/
55+
public $isDarkMode = false;
56+
57+
/**
58+
* @var string|array<string>
5359
*/
5460
public $fontFamilyBase = '-apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, Oxygen-Sans, Cantarell, \'Helvetica Neue\', sans-serif';
5561

5662
/**
57-
* @var string
63+
* @var string|array<string>
5864
*/
59-
public $colorBrand = '#43a047';
65+
public $colorBrand = ['#43a047', '#778fd4'];
6066

6167
/**
62-
* @var string
68+
* @var string|array<string>
6369
*/
64-
public $colorBrandContrast = '#fff';
70+
public $colorBrandContrast = ['#fff', '#ffffff'];
6571

6672
/**
67-
* @var string
73+
* @var string|array<string>
6874
*/
6975
public $colorFocusRing = '#0969da';
7076

7177
/**
72-
* @var string
78+
* @var string|array<string>
7379
*/
7480
public $colorFocusRingAlternative;
7581

7682
/**
77-
* @var string
83+
* @var string|array<string>
7884
*/
79-
public $colorText = '#212121';
85+
public $colorText = ['#212121', '#fff'];
8086

8187
/**
82-
* @var string
88+
* @var string|array<string>
8389
*/
84-
public $colorTextLight = '#444';
90+
public $colorTextLight = ['#444', '#ccc'];
8591

8692
/**
87-
* @var string
93+
* @var string|array<string>
8894
*/
89-
public $colorTextLighter = '#666666';
95+
public $colorTextLighter = ['#666666', '#aaa'];
9096

9197
/**
92-
* @var string
98+
* @var string|array<string>
9399
*/
94-
public $colorTextContrast = '#37474f';
100+
public $colorTextContrast = ['#37474f', '#fff'];
95101

96102
/**
97-
* @var string
103+
* @var string|array<string>
98104
*/
99-
public $colorLink = '#1976D2';
105+
public $colorLink = ['#1976D2', '#778fd4'];
100106

101107
/**
102-
* @var string
108+
* @var string|array<string>
103109
*/
104110
public $colorBaseSeries = '#ee3024';
105111

106112
/**
107-
* @var string
113+
* @var string|array<string>
108114
*/
109115
public $colorHeadlineAlternative = '#4E4E4E';
110116

111117
/**
112-
* @var string
118+
* @var string|array<string>
113119
*/
114-
public $colorHeaderBackground = '#3450A3';
120+
public $colorHeaderBackground = ['#3450A3', '#2b3138'];
115121

116122
/**
117-
* @var string
123+
* @var string|array<string>
118124
*/
119125
public $colorHeaderText = '#fff';
120126

121127
/**
122-
* @var string
128+
* @var string|array<string>
123129
*/
124130
public $colorMenuContrastText;
125131

126132
/**
127-
* @var string
133+
* @var string|array<string>
128134
*/
129135
public $colorMenuContrastTextSelected;
130136

131137
/**
132-
* @var string
138+
* @var string|array<string>
133139
*/
134-
public $colorMenuContrastTextActive = '#3450A3';
140+
public $colorMenuContrastTextActive = ['#3450A3', '#fff'];
135141

136142
/**
137-
* @var string
143+
* @var string|array<string>
138144
*/
139145
public $colorMenuContrastBackground;
140146

141147
/**
142-
* @var string
148+
* @var string|array<string>
143149
*/
144150
public $colorWidgetExportedBackgroundBase;
145151

146152
/**
147-
* @var string
153+
* @var string|array<string>
148154
*/
149155
public $colorWidgetTitleText;
150156

151157
/**
152-
* @var string
158+
* @var string|array<string>
153159
*/
154160
public $colorWidgetTitleBackground;
155161

156162
/**
157-
* @var string
163+
* @var string|array<string>
158164
*/
159-
public $colorBackgroundBase = '#eff0f1';
165+
public $colorBackgroundBase = ['#eff0f1', '#202329'];
160166

161167
/**
162-
* @var string
168+
* @var string|array<string>
163169
*/
164170
public $colorBackgroundTinyContrast = '#f2f2f2';
165171

166172
/**
167-
* @var string
173+
* @var string|array<string>
168174
*/
169175
public $colorBackgroundLowContrast = '#d9d9d9';
170176

171177
/**
172-
* @var string
178+
* @var string|array<string>
173179
*/
174-
public $colorBackgroundContrast = '#fff';
180+
public $colorBackgroundContrast = ['#fff', '#2b3138'];
175181

176182
/**
177-
* @var string
183+
* @var string|array<string>
178184
*/
179185
public $colorBackgroundHighContrast = '#202020';
180186

181187
/**
182-
* @var string
188+
* @var string|array<string>
183189
*/
184190
public $colorBorder = '#cccccc';
185191

186192
/**
187-
* @var string
193+
* @var string|array<string>
188194
*/
189195
public $colorCode = '#f3f3f3';
190196

191197
/**
192-
* @var string
198+
* @var string|array<string>
193199
*/
194200
public $colorCodeBackground = '#4d4d4d';
195201

196202
/**
197-
* @var string
203+
* @var string|array<string>
198204
*/
199205
public $colorWidgetBackground;
200206

201207
/**
202-
* @var string
208+
* @var string|array<string>
203209
*/
204210
public $colorWidgetBorder;
205211

206-
public function __construct()
212+
public function __construct($isDarkMode)
207213
{
214+
$this->isDarkMode = $isDarkMode;
208215
$this->colorFocusRingAlternative = $this->colorBrand;
209216
$this->colorMenuContrastText = $this->colorText;
210217
$this->colorMenuContrastTextSelected = $this->colorMenuContrastText;
@@ -219,9 +226,9 @@ public function __construct()
219226
/**
220227
* @return ThemeStyles
221228
*/
222-
public static function get()
229+
public static function get($isDarkMode = true)
223230
{
224-
$result = new self();
231+
$result = new self($isDarkMode);
225232

226233
/**
227234
* @ignore
@@ -235,6 +242,9 @@ public function toLessCode()
235242
{
236243
$result = '';
237244
foreach (get_object_vars($this) as $name => $value) {
245+
if (is_array($value)) {
246+
$value = $this->isDarkMode ? $value[1] : $value[0];
247+
}
238248
$varName = isset(self::$propertyNamesToLessVariableNames[$name]) ? self::$propertyNamesToLessVariableNames[$name] : $this->getGenericThemeVarName($name);
239249
$result .= "@$varName: $value;\n";
240250
}

core/View/HtmlReportEmailHeaderView.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct($reportTitle, $prettyDate, $description, $reportMeta
6262

6363
public static function assignCommonParameters(View $view)
6464
{
65-
$themeStyles = ThemeStyles::get();
65+
$themeStyles = ThemeStyles::get(false);
6666
$emailStyles = EmailStyles::get();
6767

6868
$view->currentPath = SettingsPiwik::getPiwikUrl();

plugins/CoreHome/CoreHome.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function setTrackerCacheGeneral(&$cacheGeneral)
7878

7979
public function addStylesheets(&$mergedContent)
8080
{
81+
// TODO: fetch dark mode preferences
8182
$themeStyles = ThemeStyles::get();
8283
$mergedContent = $themeStyles->toLessCode() . "\n" . $mergedContent;
8384
}

0 commit comments

Comments
 (0)