Skip to content

Commit 2138ec1

Browse files
add support for automatic color mode (#923)
* add support for automatic color mode * standardize naming * remove comments, fix formatting --------- Co-authored-by: Roman Lytvynenko <[email protected]>
1 parent 511f3d8 commit 2138ec1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

config/scramble.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'title' => null,
4343

4444
/*
45-
* Define the theme of the documentation. Available options are `light` and `dark`.
45+
* Define the theme of the documentation. Available options are `light`, `dark`, and `system`.
4646
*/
4747
'theme' => 'light',
4848

resources/views/docs.blade.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,24 @@
6565
docs.apiDescriptionDocument = @json($spec);
6666
})();
6767
</script>
68+
69+
@if($config->get('ui.theme', 'light') === 'system')
70+
<script>
71+
var mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
72+
73+
function updateTheme(e) {
74+
if (e.matches) {
75+
window.document.documentElement.setAttribute('data-theme', 'dark');
76+
window.document.getElementsByName('color-scheme')[0].setAttribute('content', 'dark');
77+
} else {
78+
window.document.documentElement.setAttribute('data-theme', 'light');
79+
window.document.getElementsByName('color-scheme')[0].setAttribute('content', 'light');
80+
}
81+
}
82+
83+
mediaQuery.addEventListener('change', updateTheme);
84+
updateTheme(mediaQuery);
85+
</script>
86+
@endif
6887
</body>
6988
</html>

0 commit comments

Comments
 (0)