Skip to content

Commit 68b8463

Browse files
committed
refactor: change doc, remove inputElement check, styling
1 parent 0720c2a commit 68b8463

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ docsSearchBar({
191191
Allows you to display the searchbar in dark mode. It is useful if your website has dark mode support and you also want the searchbar to appear in a dark version.
192192
You can always edit the style of the searchbar to match the style of your website. When the option `enableDarkMode` is set to `auto`, the searchbar automatically sets the mode to the system mode.
193193

194+
`enableDarkMode` has three possible states:
195+
- `false`: enforce light mode.
196+
- `true`: enforce dark mode.
197+
- `auto`: system mode (light or dark).
198+
194199
Example:
195200

196201
```javascript

src/lib/DocsSearchBar.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { MeiliSearch } from 'meilisearch'
2121
* @param {function} [options.handleSelected] This function is called when a suggestion is selected
2222
* @param {function} [options.enhancedSearchInput] When set to true, a theme is applied to the search box to improve its appearance
2323
* @param {'column'|'simple'} [options.layout] Layout of the search bar
24-
* @param {boolean|'auto'} [options.enableDarkMode] Allows you to display the searchbar in dark mode. Option 'auto' automatically sets the mode based on the system mode
24+
* @param {boolean|'auto'} [options.enableDarkMode] Allows you to enforce, light theme, dark theme, or auto mode on the searchbar.
2525
* @return {Object}
2626
*/
2727
const usage = `Usage:
@@ -174,7 +174,7 @@ class DocsSearchBar {
174174
* Wraps input selector in a docs-searchbar-js div
175175
* @function addThemeWrapper
176176
* @param {string} inputSelector Selector of the input element
177-
* @param {boolean|'auto'} enableDarkMode Wether darkMode is enabled
177+
* @param {boolean|'auto'} enableDarkMode Allows you to enforce, light theme, dark theme, or auto mode on the searchbar.
178178
* @returns {void}
179179
*/
180180
static addThemeWrapper(inputSelector, enableDarkMode) {
@@ -185,8 +185,8 @@ class DocsSearchBar {
185185
parent.replaceChild(wrapper, inputElement)
186186
wrapper.appendChild(inputElement)
187187

188-
let isSystemInDarkMode = inputElement && enableDarkMode === true
189-
if (inputElement && enableDarkMode === 'auto' && window.matchMedia) {
188+
let isSystemInDarkMode = Boolean(enableDarkMode)
189+
if (enableDarkMode === 'auto' && window.matchMedia) {
190190
const mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)')
191191
isSystemInDarkMode = mediaQueryList.matches
192192

@@ -199,6 +199,7 @@ class DocsSearchBar {
199199
mediaQueryList.removeListener(listener)
200200
}
201201
}
202+
202203
if (mediaQueryList.addEventListener) {
203204
mediaQueryList.addEventListener('change', listener)
204205
} else if (mediaQueryList.addListener) {

0 commit comments

Comments
 (0)