Add light/dark theme switch
Theme follows the system by default; the header switch cycles auto/light/dark and is stored per browser. The presenter has its own switch (T), dark by default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f0c6687100
commit
58145e9753
9 files changed
+187
-18
No files matched your search
@@ -3,7 +3,7 @@
|
||||
* Presenter screen. Rendered empty and filled by webroot/js/plenario.js
|
||||
* (Plenario.presenter) from /admin/{token}/state.
|
||||
*
|
||||
* Keyboard: ←/→ slides, V voting on/off, H hide results, F fullscreen, Q QR code.
|
||||
* Keyboard: ←/→ slides, V voting on/off, H hide results, F fullscreen, Q QR code, T light/dark.
|
||||
* Q&A slides: V switches to the next stage; while discussing ←/→ step through the questions first.
|
||||
*
|
||||
* @var \App\View\AppView $this
|
||||
@@ -57,6 +57,12 @@ $host = preg_replace('#^https?://#', '', $joinBaseUrl);
|
||||
<span data-label><?= __('Ergebnisse verbergen') ?></span> <kbd class="ctrl__key" aria-hidden="true">[H]</kbd>
|
||||
</button>
|
||||
<span class="ctrl-counter" data-participants></span>
|
||||
<?= $this->element('theme_switch', [
|
||||
'key' => 'plenario-theme-present',
|
||||
'modes' => 'dark,light',
|
||||
'class' => 'ctrl ctrl--wide',
|
||||
'shortcut' => 'T',
|
||||
]) ?>
|
||||
<button type="button" class="ctrl" data-fullscreen aria-keyshortcuts="F" title="<?= __('Vollbild (F)') ?>">
|
||||
<span aria-hidden="true">⛶</span><span class="sr-only"><?= __('Vollbild') ?></span>
|
||||
<kbd class="ctrl__key" aria-hidden="true">[F]</kbd>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Applies the stored colour scheme before first paint (no flash of the wrong theme).
|
||||
* Must be included in <head>. The theme switch (element theme_switch, webroot/js/plenario.js
|
||||
* `Theme`) writes the same localStorage key.
|
||||
*
|
||||
* @var \App\View\AppView $this
|
||||
* @var string $key localStorage key (presenter uses its own, the beamer is not the laptop)
|
||||
* @var string $fallback Theme without stored choice: '' = follow the system, 'dark' or 'light'
|
||||
*/
|
||||
$key ??= 'plenario-theme';
|
||||
$fallback ??= '';
|
||||
?>
|
||||
<script>
|
||||
(function () {
|
||||
var theme = <?= json_encode($fallback) ?>;
|
||||
try {
|
||||
theme = localStorage.getItem(<?= json_encode($key) ?>) || theme;
|
||||
} catch (e) {}
|
||||
if (theme === 'light' || theme === 'dark') {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Button that cycles the colour scheme (wired up by webroot/js/plenario.js `Theme`).
|
||||
* Without JavaScript it stays hidden, the system setting applies.
|
||||
*
|
||||
* @var \App\View\AppView $this
|
||||
* @var string $key localStorage key, same as in element theme_init
|
||||
* @var string $modes Comma separated cycle order of auto|light|dark
|
||||
* @var string $class CSS class of the button
|
||||
*/
|
||||
$key ??= 'plenario-theme';
|
||||
$modes ??= 'auto,light,dark';
|
||||
$class ??= 'theme-switch';
|
||||
?>
|
||||
<button type="button" class="<?= h($class) ?>" data-theme-switch hidden
|
||||
data-theme-key="<?= h($key) ?>" data-theme-modes="<?= h($modes) ?>"
|
||||
data-label-auto="<?= __('Automatisch') ?>" data-label-light="<?= __('Hell') ?>" data-label-dark="<?= __('Dunkel') ?>"
|
||||
data-label-prefix="<?= __('Farbschema') ?>" data-label-next="<?= __('wechseln zu') ?>"
|
||||
<?= !empty($shortcut) ? 'aria-keyshortcuts="' . h($shortcut) . '"' : '' ?>>
|
||||
<span class="theme-switch__icon" aria-hidden="true" data-theme-icon></span>
|
||||
<span data-theme-label></span>
|
||||
<?php if (!empty($shortcut)) : ?>
|
||||
<kbd class="ctrl__key" aria-hidden="true">[<?= h($shortcut) ?>]</kbd>
|
||||
<?php endif; ?>
|
||||
</button>
|
||||
@@ -16,6 +16,7 @@ $title = $this->fetch('title');
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<?php endif; ?>
|
||||
<title><?= $title ? h($title) . ' · ' : '' ?>Plenario</title>
|
||||
<?= $this->element('theme_init') ?>
|
||||
<?= $this->Html->meta('icon') ?>
|
||||
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
|
||||
<?= $this->fetch('meta') ?>
|
||||
@@ -31,6 +32,7 @@ $title = $this->fetch('title');
|
||||
<a href="<?= $this->Url->build(['_name' => 'join']) ?>"><?= __('Teilnehmen') ?></a>
|
||||
<a href="<?= $this->Url->build(['_name' => 'recover']) ?>"><?= __('Admin-Link verloren?') ?></a>
|
||||
</nav>
|
||||
<?= $this->element('theme_switch') ?>
|
||||
</div>
|
||||
</header>
|
||||
<main class="container main">
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex">
|
||||
<title><?= h($this->fetch('title')) ?> · Plenario</title>
|
||||
<?= $this->element('theme_init') ?>
|
||||
<?= $this->Html->meta('icon') ?>
|
||||
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
|
||||
</head>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Full screen presenter layout (dark, no navigation).
|
||||
* Full screen presenter layout (dark by default, own theme switch in the controls, no navigation).
|
||||
*
|
||||
* @var \App\View\AppView $this
|
||||
*/
|
||||
@@ -13,6 +13,7 @@
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<meta name="csrf-token" content="<?= h((string)$this->request->getAttribute('csrfToken')) ?>">
|
||||
<title><?= h($this->fetch('title')) ?> · Plenario</title>
|
||||
<?= $this->element('theme_init', ['key' => 'plenario-theme-present', 'fallback' => 'dark']) ?>
|
||||
<?= $this->Html->meta('icon') ?>
|
||||
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
|
||||
</head>
|
||||
|
||||
Reference in new issue
Block a user