17
17
< link href ="css/select2-tailwindcss-theme-plain.min.css " rel ="stylesheet ">
18
18
< script src ="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js "> </ script >
19
19
< script src ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/js/select2.min.js "
> </ script >
20
+ < script >
21
+ tailwind . config = {
22
+ darkMode : 'selector' ,
23
+ }
24
+ </ script >
25
+
26
+ < script >
27
+ // On page load or when changing themes, best to add inline in `head` to avoid FOUC
28
+ document . documentElement . classList . toggle (
29
+ 'dark' ,
30
+ localStorage . theme === 'dark' || ( ! ( 'theme' in localStorage ) && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches )
31
+ ) ;
32
+ </ script >
20
33
</ head >
21
34
22
- < body class ="font-sans antialiased bg-gray-100 ">
35
+ < body class ="font-sans antialiased bg-gray-100 dark:bg-gray-900 ">
23
36
24
- < header class ="py-4 text-white bg-blue-600 shadow ">
37
+ < header class ="py-4 text-white bg-blue-600 shadow dark:bg-blue-950 ">
25
38
< h1 class ="text-xl font-bold text-center "> Select2 Tailwindcss Theme Demo</ h1 >
26
39
</ header >
27
40
28
- < main class ="max-w-4xl p-6 mx-auto mt-8 bg-white rounded-lg shadow-lg ">
29
- < h2 class ="mb-6 text-2xl font-semibold text-gray-800 ">
30
- Examples of
31
- < a href ="https://github.com/erimicel/select2-tailwindcss-theme " target ="_blank " class ="text-blue-600 ">
32
- @erimicel/select2-tailwindcss-theme
33
- </ a >
34
- </ h2 >
41
+ < main class ="max-w-4xl p-6 mx-auto mt-8 bg-white rounded-lg shadow-lg dark:bg-slate-800 ">
42
+ < div class ="flex flex-row flex-wrap justify-between ">
43
+ < h2 class ="mb-6 text-2xl font-semibold text-gray-800 dark:text-white ">
44
+ Examples of
45
+ < a href ="https://github.com/erimicel/select2-tailwindcss-theme " target ="_blank " class ="text-blue-600 ">
46
+ @erimicel/select2-tailwindcss-theme
47
+ </ a >
48
+ </ h2 >
49
+
50
+ < div class ="flex flex-row items-center mb-4 align-middle sm:mb-0 ">
51
+ < span class ="mr-2 text-sm font-semibold text-gray-700 dark:text-white "> Switch Dark Mode</ span >
52
+ < button id ="theme-toggle "
53
+ class ="w-12 h-12 p-2 border border-gray-100 rounded-lg bg-gray-50 hover:bg-gray-200 dark:bg-gray-700 dark:border-gray-800 dark:hover:bg-gray-600 ">
54
+ < svg class ="block fill-violet-700 dark:hidden " fill ="currentColor " viewBox ="0 0 20 20 ">
55
+ < path d ="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z "> </ path >
56
+ </ svg >
57
+ < svg class ="hidden fill-yellow-500 dark:block " fill ="currentColor " viewBox ="0 0 20 20 ">
58
+ < path
59
+ d ="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z "
60
+ fill-rule ="evenodd " clip-rule ="evenodd "> </ path >
61
+ </ svg >
62
+ </ button >
63
+ </ div >
64
+ </ div >
35
65
36
66
< form class ="space-y-4 ">
37
67
<!-- Single Select -->
38
68
< div >
39
- < label class ="block mb-2 text-sm font-medium text-gray-700 "> Example of single select</ label >
69
+ < label class ="block mb-2 text-sm font-medium text-gray-700 dark:text-white "> Example of single select</ label >
40
70
< select data-placeholder ="Choose one thing " data-allow-clear ="1 ">
41
71
< option > </ option >
42
72
< option > 1</ option >
@@ -49,7 +79,7 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
49
79
50
80
<!-- Tags Select -->
51
81
< div >
52
- < label class ="block mb-2 text-sm font-medium text-gray-700 "> Example of dynamic option creation</ label >
82
+ < label class ="block mb-2 text-sm font-medium text-gray-700 dark:text-white "> Example of dynamic option creation</ label >
53
83
< select multiple data-placeholder ="Type anything " data-allow-clear ="1 " data-tags ="1 ">
54
84
< option > Alaska</ option >
55
85
< option > Hawaii</ option >
@@ -59,7 +89,7 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
59
89
60
90
<!-- Multiple Select -->
61
91
< div >
62
- < label class ="block mb-2 text-sm font-medium text-gray-700 "> Example of multiple select</ label >
92
+ < label class ="block mb-2 text-sm font-medium text-gray-700 dark:text-white "> Example of multiple select</ label >
63
93
< select multiple data-placeholder ="Choose anything " data-allow-clear ="1 ">
64
94
< option > Alaska</ option >
65
95
< option > Hawaii</ option >
@@ -69,13 +99,13 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
69
99
70
100
<!-- Disabled Select -->
71
101
< div >
72
- < label class ="block mb-2 text-sm font-medium text-gray-700 "> Example of disabled select</ label >
102
+ < label class ="block mb-2 text-sm font-medium text-gray-700 dark:text-white "> Example of disabled select</ label >
73
103
< select disabled data-placeholder ="Cannot choose " data-allow-clear ="1 "> </ select >
74
104
</ div >
75
105
76
106
<!-- Multiple Disabled Select -->
77
107
< div >
78
- < label class ="block mb-2 text-sm font-medium text-gray-700 "> Example of disabled multiple select with selected items</ label >
108
+ < label class ="block mb-2 text-sm font-medium text-gray-700 dark:text-white "> Example of disabled multiple select with selected items</ label >
79
109
< select disabled multiple >
80
110
< option selected > Alaska</ option >
81
111
< option selected > Hawaii</ option >
@@ -84,7 +114,7 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
84
114
85
115
<!-- Select with Optgroup -->
86
116
< div >
87
- < label class ="block mb-2 text-sm font-medium text-gray-700 "> Example of select with optgroup</ label >
117
+ < label class ="block mb-2 text-sm font-medium text-gray-700 dark:text-white "> Example of select with optgroup</ label >
88
118
< select data-placeholder ="Choose one thing " data-allow-clear ="1 ">
89
119
< option > </ option >
90
120
< optgroup label ="Group A ">
@@ -102,7 +132,7 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
102
132
103
133
<!-- Input Group -->
104
134
< div >
105
- < label class ="block mb-2 text-sm font-medium text-gray-700 "> Example of input group (.input-group)</ label >
135
+ < label class ="block mb-2 text-sm font-medium text-gray-700 dark:text-white "> Example of input group (.input-group)</ label >
106
136
< div class ="flex input-group ">
107
137
< span class ="flex items-center px-3 text-base text-gray-500 bg-white border border-gray-300 shrink-0 rounded-l-md sm:text-sm/6 "> Prepend</ span >
108
138
< select data-placeholder ="Choose one thing " data-allow-clear ="1 ">
@@ -137,7 +167,7 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
137
167
138
168
<!-- Validated Select -->
139
169
< div >
140
- < label class ="block mb-2 text-sm font-medium text-gray-700 "> Example of validated select (.is-valid, :invalid)</ label >
170
+ < label class ="block mb-2 text-sm font-medium text-gray-700 dark:text-white "> Example of validated select (.is-valid, :invalid)</ label >
141
171
< select class ="is-invalid " data-placeholder ="Invalid example " data-allow-clear ="1 ">
142
172
< option > </ option >
143
173
</ select >
@@ -146,17 +176,24 @@ <h2 class="mb-6 text-2xl font-semibold text-gray-800">
146
176
</ form >
147
177
</ main >
148
178
149
- < footer class ="my-12 text-center text-gray-600 ">
179
+ < footer class ="my-12 text-center text-gray-600 dark:text-white ">
150
180
< p class ="text-sm "> Select2 4.1.0-rc.0, TailwindCSS 3.4.17, jQuery 3.7.1</ p >
151
181
</ footer >
152
182
153
183
< script >
154
184
$ ( function ( ) {
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
- ) ;
185
+ // Toggle dark mode
186
+ document . getElementById ( 'theme-toggle' ) . addEventListener ( 'click' , ( ) => {
187
+ localStorage . theme = localStorage . theme === 'dark' ? 'light' : 'dark' ;
188
+
189
+ // On page load or when changing themes, best to add inline in `head` to avoid FOUC
190
+ document . documentElement . classList . toggle (
191
+ 'dark' ,
192
+ localStorage . theme === 'dark' || ( ! ( 'theme' in localStorage ) && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches )
193
+ ) ;
194
+
195
+ console . log ( localStorage . theme ) ;
196
+ } ) ;
160
197
161
198
// Select2 init
162
199
$ ( 'select' ) . each ( function ( ) {
0 commit comments