Skip to content

Add dark mode #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ module.exports = {
CROP_LENGTH: 'readonly',
HOT_KEYS: 'readonly',
PLACEHOLDER: 'readonly',
LAYOUT: 'readonly'
LAYOUT: 'readonly',
DEBUG: 'readonly',
ENABLE_DARK_MODE: 'readonly'
},
parserOptions: {
parser: 'babel-eslint',
Expand Down
111 changes: 87 additions & 24 deletions MeiliSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export default {
autocompleteOptions: {
keyboardShortcuts: HOT_KEYS
},
layout: LAYOUT
layout: LAYOUT,
debug: DEBUG,
enableDarkMode: ENABLE_DARK_MODE
}
this.initialize(options)
this.placeholder =
Expand Down Expand Up @@ -78,28 +80,7 @@ export default {
</script>

<style lang="stylus">
.search-box
display inline-block
position relative
margin-right 1rem
input
cursor text
width 10rem
height: 2rem
color lighten($textColor, 25%)
display inline-block
border 1px solid darken($borderColor, 10%)
border-radius 2rem
font-size 0.9rem
line-height 2rem
padding 0 0.5rem 0 2rem
outline none
transition all .2s ease
&:focus
cursor auto
border-color $accentColor
background #fff url(assets/search.svg) 0.6rem 0.5rem no-repeat
background-size 1rem
@require './styles/palette.styl'

.meilisearch-search-wrapper
& > span
Expand All @@ -108,6 +89,27 @@ export default {
background rgba($accentColor, 0.05)
.meilisearch-autocomplete
line-height 2
// Searchbox
input
cursor text
width 10rem
height: 2rem
color lighten($textColor, 25%)
display inline-block
border 1px solid darken($borderColor, 10%)
border-radius 2rem
font-size 0.9rem
line-height 2rem
padding 0 0.5rem 0 2rem
outline none
transition all .2s ease
&:focus
cursor auto
border-color $accentColor
background #fff url(assets/search.svg) 0.6rem 0.5rem no-repeat
background-size 1rem

// Layout "columns"
.docs-searchbar-suggestion:not(.suggestion-layout-simple)
border-color $borderColor
.docs-searchbar-suggestion--category-header
Expand All @@ -121,6 +123,7 @@ export default {
box-shadow none
background lighten($accentColor, 70%)
.docs-searchbar-suggestion--wrapper
display flex
padding 0
.docs-searchbar-suggestion--highlight
color darken($accentColor, 20%)
Expand All @@ -135,6 +138,8 @@ export default {
.docs-searchbar-suggestion--highlight
box-shadow inset 0 -2px 0 0 lighten($accentColor, 20%)
color: inherit

// Layout simple
.suggestion-layout-simple
.docs-searchbar-suggestion--title
color: $accentColor
Expand All @@ -150,16 +155,74 @@ export default {
background-color: transparent
box-shadow inset 0 -2px 0 0 lighten($accentColor, 20%)
color inherit

// Footer
.docs-searchbar-footer
display flex !important
justify-content space-between !important
align-items center !important
.docs-searchbar-footer-logo
margin-bottom -4px
.dsb-cursor .docs-searchbar-suggestion--content
background-color #e7edf3 !important
background-color #e7edf3
color $textColor

// Dark theme
div[data-ds-theme="dark"]
.meilisearch-autocomplete
.dsb-dropdown-menu [class^=dsb-dataset-], .docs-searchbar-suggestion
background $dropdownBgDarkColor

// Searchbox
input
color $textDarkColor
border 1px solid $borderDarkColor
background-color $inputDarkBgColor
&:focus
border-color $accentDarkColor

// Layout "columns"
.docs-searchbar-suggestion:not(.suggestion-layout-simple)
border-color $borderDarkColor
.docs-searchbar-suggestion--wrapper
.docs-searchbar-suggestion--highlight
color $accentDarkColor
.docs-searchbar-suggestion--category-header
background $accentDarkColor
.docs-searchbar-suggestion--highlight
background lighten($accentDarkColor, 20%)
.docs-searchbar-suggestion--title
color $textDarkColor
.docs-searchbar-suggestion--subcategory-column
border-color $borderDarkColor // Simple ?
.docs-searchbar-suggestion--subcategory-column-text
color $textDarkColor
.docs-searchbar-suggestion--text
.docs-searchbar-suggestion--highlight
box-shadow inset 0 -2px 0 0 lighten($accentDarkColor, 20%)

// Layout "simple"
.suggestion-layout-simple
.docs-searchbar-suggestion--category-header
.docs-searchbar-suggestion--category-header-lvl0, .docs-searchbar-suggestion--category-header-lvl1
.docs-searchbar-suggestion--highlight
box-shadow inset 0 -2px 0 0 darken($accentDarkColor, 10%)
.docs-searchbar-suggestion--title
.docs-searchbar-suggestion--highlight
color lighten($accentDarkColor, 20%)
background rgba($accentDarkColor, 10%)
.docs-searchbar-suggestion--category-header-lvl0, .docs-searchbar-suggestion--category-header-lvl1
.docs-searchbar-suggestion--highlight
color inherit

// Suggestion on hover
.dsb-dropdown-menu .dsb-suggestions .dsb-cursor
.docs-searchbar-suggestion.suggestion-layout-simple
background-color rgba($accentDarkColor, 30%)
.docs-searchbar-suggestion:not(.suggestion-layout-simple)
.docs-searchbar-suggestion--content
background-color rgba($accentDarkColor, 30%)

@media (min-width: $MQMobile)
.meilisearch-search-wrapper
.meilisearch-autocomplete
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,32 @@ module.exports = {
maxSuggestions: 10, // Default: 5
hotKeys: [], // Default: ['s', '/']
cropLength: 50, // Default: 30
layout: 'simple' // Default: "columns"
layout: 'simple', // Default: "columns"
debug: true, // Default: false
enableDarkMode: true // Default: false
}
]
]
}
```

#### Dark mode

You can enable dark mode by adding `enableDarkMode: true` to your configuration file.

To override the default theme of the search bar, you can edit your `.vuepress/styles/palette.styl` file.<br>
A few variables are available:

```js
$accentDarkColor
$inputDarkBgColor
$textDarkColor
$borderDarkColor
$dropdownBgDarkColor
```

You can also find an example in our [playground's `palette.styl` file](./playground/.vuepress/styles/palette.styl)

## Compatibility with MeiliSearch

This package only guarantees the compatibility with the [version v0.20.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.20.0).
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ module.exports = (options) => {
MAX_SUGGESTIONS: options.maxSuggestions || null,
HOT_KEYS: options.hotKeys || ['s', '/'],
CROP_LENGTH: options.cropLength || 30,
LAYOUT: options.layout || 'columns'
LAYOUT: options.layout || 'columns',
DEBUG: options.debug || false,
ENABLE_DARK_MODE: options.enableDarkMode || false
}
}
}
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module.exports = {
MAX_SUGGESTIONS: null,
HOT_KEYS: ['s', '/'],
CROP_LENGTH: 30,
LAYOUT: 'columns'
LAYOUT: 'columns',
DEBUG: false,
ENABLE_DARK_MODE: false
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"main": "index.js",
"dependencies": {
"docs-searchbar.js": "^1.2.0"
"docs-searchbar.js": "^1.3.0"
},
"resolutions": {
"yargs-parser": "^13.1.2"
Expand Down
10 changes: 8 additions & 2 deletions playground/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module.exports = {
title: 'Welcome to the Playground!',
theme: 'default-prefers-color-scheme',
themeConfig: {
prefersTheme: 'dark'
},
plugins: [
[
require('../../index.js'),
Expand All @@ -8,9 +12,11 @@ module.exports = {
hostUrl: 'https://docs-search-bar.meilisearch.com',
apiKey:
'd79226ae89f29d4dadba8d0c30c240e435f584fb83a7ae573b13eb62edec35cd',
indexUid: 'docs'
indexUid: 'docs',
debug: true,
enableDarkMode: true
// "maxSuggestions": 10,
// "placeholder": "Search as you type..."
// placeholder: 'Search as you type...'
}
]
]
Expand Down
8 changes: 8 additions & 0 deletions playground/.vuepress/styles/palette.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

$accentDarkColor = #a29bfe

$inputDarkBgColor = #444d52

$textDarkColor = #eaeaea

$borderDarkColor = lighten($inputDarkBgColor, 10%)
2 changes: 2 additions & 0 deletions playground/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# MeiliSearch and vuepress

Use the search bar to test the plugin!

[I'm a link](/)
2 changes: 1 addition & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
},
"dependencies": {
"vuepress": "^1.4.1",
"vuepress-plugin-meilisearch": "^0.0.6"
"vuepress-theme-default-prefers-color-scheme": "^2.0.0"
}
}
Loading