Skip to content

Commit

Permalink
Implement Dark Mode (CFM-239) (#94)
Browse files Browse the repository at this point in the history
* First commit for Dark Mode: enable dark mode toggle and OS system checking; rename all color variables; add color-scheme meta tag to all layouts. (CFM-239)

* Clean-up more styles for dark mode. (CFM-239)

* Fine-tune color contrasts for dark mode. (CFM-239)

* Add comments for future development (concerning dark mode and select2) (CFM-239)

* Trivial fix (color variable name change) post-rebase and addition of introductory dashboard message to lang files. (CFM-239)
  • Loading branch information
arlen authored Jun 13, 2023
1 parent 206d440 commit 50b430b
Show file tree
Hide file tree
Showing 10 changed files with 434 additions and 274 deletions.
18 changes: 18 additions & 0 deletions app/resources/locales/en_US/menu.po
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,27 @@ msgstr "Switch CO"
msgid "menu.advanced"
msgstr "Advanced Menu"

msgid "menu.darkmode"
msgstr "Dark mode"

msgid "menu.density.small"
msgstr "Density small"

msgid "menu.density.medium"
msgstr "Density medium"

msgid "menu.density.large"
msgstr "Density large"

msgid "menu.introduction"
msgstr "Please select an action from the menu."

msgid "menu.main"
msgstr "Main Menu"

msgid "menu.settings"
msgstr "Settings"

msgid "menu.user"
msgstr "User Menu"

Expand Down
4 changes: 3 additions & 1 deletion app/templates/Dashboards/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
// XXX This is a placeholder
?>

Please select an action from the menu.
<div id="introduction">
<p><?= __d('menu','menu.introduction') ?></p>
</div>
27 changes: 21 additions & 6 deletions app/templates/element/javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@
$("select").addClass("form-select");

// Use select2 library everywhere except
// XXX TODO: Find a replacement for Select2 - it is not accessible.
// - duet-date
$("select").not("#limit").not(".duet-date__select--month").not(".duet-date__select--year").select2({
width: '100%',
tags: true,
placeholder: "-- Select --",
allowClear: true
});
// $("select").not("#limit").not(".duet-date__select--month").not(".duet-date__select--year").select2({
// width: '100%',
// tags: true,
// placeholder: "-- Select --",
// allowClear: true
// });

// Generic row click handling
// First capture mouse location to test if we're clicking or drag-selecting (for copy)
Expand Down Expand Up @@ -252,6 +253,20 @@

});

// SETTINGS (from User Menu)
// Dark Mode toggle
$("#dark-mode-toggle").click(function(e) {
e.preventDefault();
$('html').toggleClass('dark-mode');
});

// Test for dark mode OS preference, and add the 'dark-mode' body class by default if it is present.
// XXX TODO: Replace this with setting an application variable (when available) so we do not flash the light color briefly on each page load
const darkModeOsEnabled = window.matchMedia("(prefers-color-scheme: dark)");
if(darkModeOsEnabled.matches) {
$('html').addClass('dark-mode');
}

});

// Define default text for confirm dialog
Expand Down
8 changes: 4 additions & 4 deletions app/templates/element/menuTop.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class="dropdown-toggle top-menu-button"
Settings
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#"><span class="material-icons" aria-hidden="true">dark_mode</span> Dark mode</a></li>
<li><a class="dropdown-item nospin" href="#" id="dark-mode-toggle"><span class="material-icons" aria-hidden="true">dark_mode</span><?= __d('menu','menu.darkmode'); ?></a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#"><span class="material-icons" aria-hidden="true">density_small</span>Density small</a></li>
<li><a class="dropdown-item" href="#"><span class="material-icons" aria-hidden="true">density_medium</span>Density medium</a></li>
<li><a class="dropdown-item" href="#"><span class="material-icons" aria-hidden="true">density_large</span>Density large</a></li>
<li><a class="dropdown-item nospin" href="#"><span class="material-icons" aria-hidden="true">density_small</span><?= __d('menu','menu.density.small'); ?></a></li>
<li><a class="dropdown-item nospin" href="#"><span class="material-icons" aria-hidden="true">density_medium</span><?= __d('menu','menu.density.medium'); ?></a></li>
<li><a class="dropdown-item nospin" href="#"><span class="material-icons" aria-hidden="true">density_large</span><?= __d('menu','menu.density.large'); ?></a></li>
</ul>
</div>
<?php if(count($vv_available_cos) > 1): // More than one CO is available, so present the switch button ?>
Expand Down
1 change: 1 addition & 0 deletions app/templates/layout/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<html lang="<?= __('registry.meta.lang'); ?>">
<head>
<?= $this->Html->meta('viewport', 'width=device-width, initial-scale=1.0') . PHP_EOL ?>
<?= $this->Html->meta('color-scheme', 'light dark') . PHP_EOL ?>
<?= $this->Html->charset(); ?>

<title><?= (!empty($vv_title) ? $vv_title : __('registry.meta.registry')); ?></title>
Expand Down
1 change: 1 addition & 0 deletions app/templates/layout/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<html lang="<?= __('registry.meta.lang'); ?>">
<head>
<?= $this->Html->meta('viewport', 'width=device-width, initial-scale=1.0') . PHP_EOL ?>
<?= $this->Html->meta('color-scheme', 'light dark') . PHP_EOL ?>
<?= $this->Html->charset() ?>

<title><?= $this->fetch('title') ?></title>
Expand Down
1 change: 1 addition & 0 deletions app/templates/layout/iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<html lang="<?= __('registry.meta.lang'); ?>">
<head>
<?= $this->Html->meta('viewport', 'width=device-width, initial-scale=1.0') . PHP_EOL ?>
<?= $this->Html->meta('color-scheme', 'light dark') . PHP_EOL ?>
<?= $this->Html->charset(); ?>

<title><?= (!empty($vv_title) ? $vv_title : __('registry.meta.registry')); ?></title>
Expand Down
Loading

0 comments on commit 50b430b

Please sign in to comment.