Skip to content

Commit 4fcf39b

Browse files
committed
Dark mode simplification
1 parent 10ded88 commit 4fcf39b

File tree

6 files changed

+355
-359
lines changed

6 files changed

+355
-359
lines changed

playgrounds/html/index.html

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@
1313
<body>
1414
<div class="container">
1515
<div class="col-md-12">
16-
<div class="docs-searchbar">
17-
<div class="searchbox">
18-
<input
19-
type="search"
20-
placeholder="docs-searchbar input"
21-
class="form-control"
22-
id="q"
23-
/>
24-
</div>
25-
</div>
16+
<input
17+
type="search"
18+
placeholder="docs-searchbar input"
19+
class="form-control"
20+
id="q"
21+
/>
2622
</div>
2723
</div>
2824
<!-- at the end of the BODY -->
@@ -43,25 +39,26 @@
4339
console.info(context)
4440
},
4541
debug: true, // Set debug to true if you want to inspect the dropdown
42+
enhancedSearchInput: true,
43+
enableDarkMode: true,
4644
})
4745
</script>
4846
<style>
4947
.container {
5048
margin: 10%;
5149
}
5250

53-
div[data-ds-theme] .searchbox {
51+
.searchbox[data-ds-theme] {
5452
width: 60%;
5553
margin: auto;
5654
margin-top: 10%;
5755
display: block;
5856
}
5957

60-
div[data-ds-theme] .searchbox input {
58+
.searchbox[data-ds-theme] input {
6159
height: 34px;
6260
border-radius: 4px;
6361
font-size: 14px;
64-
padding: 6px 12px;
6562
}
6663

6764
@media (prefers-color-scheme: dark) {

playgrounds/javascript/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@
3434
margin: 10%;
3535
}
3636

37-
div[data-ds-theme] .searchbox {
37+
.searchbox[data-ds-theme] {
3838
width: 60%;
3939
margin: auto;
4040
margin-top: 10%;
4141
display: block;
4242
}
4343

44-
div[data-ds-theme] .searchbox input {
44+
.searchbox[data-ds-theme] input {
4545
height: 34px;
4646
border-radius: 4px;
4747
font-size: 14px;
48-
padding: 6px 12px;
4948
}
5049

5150
@media (prefers-color-scheme: dark) {

src/lib/DocsSearchBar.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,6 @@ class DocsSearchBar {
9797
this.isSimpleLayout = layout === 'simple'
9898
this.enableDarkMode = enableDarkMode
9999

100-
const isSystemInDarkMode =
101-
window.matchMedia &&
102-
window.matchMedia('(prefers-color-scheme: dark)').matches
103-
const searchbox = document.querySelector('.docs-searchbar')
104-
if (searchbox) {
105-
if (this.enableDarkMode && isSystemInDarkMode) {
106-
searchbox.setAttribute('data-ds-theme', 'dark')
107-
} else {
108-
searchbox.setAttribute('data-ds-theme', 'light')
109-
}
110-
}
111-
112100
this.client = new MeiliSearch({
113101
host: hostUrl,
114102
apiKey: this.apiKey,
@@ -129,6 +117,18 @@ class DocsSearchBar {
129117
},
130118
])
131119

120+
const isSystemInDarkMode =
121+
window.matchMedia &&
122+
window.matchMedia('(prefers-color-scheme: dark)').matches
123+
const searchbox = document.querySelector('.searchbox')
124+
console.log(searchbox)
125+
if (searchbox) {
126+
searchbox.setAttribute('data-ds-theme', 'light')
127+
if (this.enableDarkMode && isSystemInDarkMode) {
128+
searchbox.setAttribute('data-ds-theme', 'dark')
129+
}
130+
}
131+
132132
const customHandleSelected = handleSelected
133133
this.handleSelected = customHandleSelected || this.handleSelected
134134

0 commit comments

Comments
 (0)