Skip to content

Commit 19c71c7

Browse files
committed
Allow dark mode on demo
1 parent 58ad61a commit 19c71c7

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ npm install
8181
Modify the SCSS file in src/.scss. Build the CSS:
8282

8383
```bash
84-
npm run build # Regular CSS with @apply classes
85-
npm run build:min # Minified CSS
84+
npm run build:all # Build all files and update demo as-well
8685
```
8786

8887
## Contributing

docs/index.html

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<html lang="en">
2+
<html lang="en" class="dark">
33

44
<head>
55
<meta charset="UTF-8">
@@ -152,17 +152,24 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
152152

153153
<script>
154154
$(function () {
155-
$('select').each(function () {
156-
$(this).select2({
157-
theme: 'tailwindcss-3',
158-
width: $(this).data('width') ? $(this).data('width') : $(this).hasClass('w-100') ? '100%' : 'style',
159-
placeholder: $(this).data('placeholder') || 'Select an option',
160-
allowClear: Boolean($(this).data('allow-clear')),
161-
closeOnSelect: !$(this).attr('multiple'),
162-
tags: Boolean($(this).data('tags')),
163-
});
155+
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
156+
document.documentElement.classList.toggle(
157+
'dark',
158+
localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
159+
);
160+
161+
// Select2 init
162+
$('select').each(function () {
163+
$(this).select2({
164+
theme: 'tailwindcss-3',
165+
width: $(this).data('width') ? $(this).data('width') : $(this).hasClass('w-100') ? '100%' : 'style',
166+
placeholder: $(this).data('placeholder') || 'Select an option',
167+
allowClear: Boolean($(this).data('allow-clear')),
168+
closeOnSelect: !$(this).attr('multiple'),
169+
tags: Boolean($(this).data('tags')),
164170
});
165171
});
172+
});
166173
</script>
167174

168175
</body>

docs/tailwind.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/** @type {import('tailwindcss').Config} */
22
module.exports = {
3+
// The selector strategy replaced the class strategy in Tailwind CSS v3.4.1.
4+
darkMode: 'selector',
35
content: [
46
'./**/*.{html,js}',
57
],

0 commit comments

Comments
 (0)