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

Add dark mode #164

merged 13 commits into from
Jun 29, 2021

Conversation

mdubus
Copy link
Member

@mdubus mdubus commented Jun 21, 2021

Closes #127

What's inside this PR ?

Dark mode support as requested in #127.

3 more changes were made :

  • Upgrade of docs-searchbar version inside thepackage.json (v1.3.0)
  • Removal of the surrounding .search-box div according to this PR
  • Exposure of the debug option which was available in docs-searchbar but not in this plugin

How to test ?

Run the playground

You can run the playground with yarn serve

Change the color palette

If you want to change the color palette, you can do so by changing the colors inside the playground/.vuepress/styles/palette.styl file

Enable / disable dark mode

You can also enable/disable the dark mode (disabled by default) by adding/removing the enableDarkMode option in the playground/.vuepress/config.js file (don't forget to restart the server !):
Capture d’écran 2021-06-23 à 08 46 27

Screenshots

Column layout (default)
layout columns

Simple layout
layout simple

Change $accentDarkColor to #a29bfe (full change of the dark theme, cohabitation with the vuepress-theme-default-prefers-color-scheme plugin)
change all colors

@mdubus mdubus marked this pull request as ready for review June 22, 2021 13:03
@mdubus mdubus added the enhancement New feature or request label Jun 22, 2021
@mdubus mdubus requested review from curquiza and bidoubiwa June 22, 2021 13:03
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@bidoubiwa
Copy link
Contributor

bidoubiwa commented Jun 22, 2021

# At the root of the plugin (vuepress-plugin-meilisearch for me):

`yarn link`

#Inside the playground folder:

rm -rf node_modules
# Remove the vuepress-plugin-meilisearch from the playground/package.json
yarn link "vuepress-plugin-meilisearch"
yarn

This shouln't be necessary as the playground is already connected to its root folder that contains the plugin.

Remove the vuepress-plugin-meilisearch from the playground/package.json

There is no vuepress-plugin-meilisearch in the package.json in the playground

@curquiza
Copy link
Member

There is no vuepress-plugin-meilisearch in the package.json in the playground

"vuepress-plugin-meilisearch": "^0.0.6"

@bidoubiwa
Copy link
Contributor

bidoubiwa commented Jun 22, 2021

In the config.js from the playground: the plugin takes its root from the parent directory

module.exports = {
  title: 'Welcome to the Playground!',
  plugins: [
    [
      require('../../index.js'),
      {
        // Testing with MeiliSearch documentation content (https://docs.meilisearch.com/)
        hostUrl: 'https://docs-search-bar.meilisearch.com',
        apiKey:
          'd79226ae89f29d4dadba8d0c30c240e435f584fb83a7ae573b13eb62edec35cd',
        indexUid: 'docs'
        // "maxSuggestions": 10,
        // "placeholder": "Search as you type..."
      }
    ]
  ]
}

not the plugin that is in the package.json. The plugin in the package.json should not have any impact in the playground since it is not used in the config file

@mdubus
Copy link
Member Author

mdubus commented Jun 23, 2021

Awesome!

  • It provides the same option as in docs-searchbar enableDarkMode, I'm going to add this to the body of the PR :)
  • Yes it does ! I provided examples in the screenshots section (the screenshots in purple are the one you are looking for)

@mdubus
Copy link
Member Author

mdubus commented Jun 23, 2021

In the config.js from the playground: the plugin takes its root from the parent directory

module.exports = {
  title: 'Welcome to the Playground!',
  plugins: [
    [
      require('../../index.js'),
      {
        // Testing with MeiliSearch documentation content (https://docs.meilisearch.com/)
        hostUrl: 'https://docs-search-bar.meilisearch.com',
        apiKey:
          'd79226ae89f29d4dadba8d0c30c240e435f584fb83a7ae573b13eb62edec35cd',
        indexUid: 'docs'
        // "maxSuggestions": 10,
        // "placeholder": "Search as you type..."
      }
    ]
  ]
}

not the plugin that is in the package.json. The plugin in the package.json should not have any impact in the playground since it is not used in the config file

Ok I got it.
I didn't managed to make it work this way, so I thought they weren't linked together. The method described in the body of the PR was the only way to make it work.
I took a look at it, and the docs-searchbar used in the playground was the old one (without the enableDarkMode option), so it obviously couldn't work 😀
The problem was the vuepress-plugin-meilisearch in the playground/package.json. As it was in v0.0.6, it also used the wrong version of docs-searchbar. After removing this useless dependency, there is not problem anymore 🎉

I'm updating the body of the PR according to this.
Thanks for pointing out this problem ! ❤️

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the README according to your new feature? 🙂

@mdubus
Copy link
Member Author

mdubus commented Jun 23, 2021

Can you update the README according to your new feature? 🙂

It's already done 🤩
I added a Dark mode section inside the Customization one

@curquiza
Copy link
Member

My bad! I completely missed it in the middle of the files 😅

curquiza
curquiza previously approved these changes Jun 23, 2021
Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve because I don't want to block the PR, but of course we need to wait for @bidoubiwa approval 🙂

@mdubus, you have write access to this repo, you don't need to work on your fork anymore 🙂

Thanks a lot!!!

Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks super fine except for one thing. When you remove the following line from playground/.vuepress/config.jsthe app throws an error.

  theme: 'default-prefers-color-scheme',

The following error is thrown:

vue.runtime.esm.js?2b0e:619 [Vue warn]: Failed to resolve async component: function Layout() {
    return Promise.all(/*! import() */[__webpack_require__.e(0), __webpack_require__.e(1)]).then(__webpack_require__.bind(null, /*! ./node_modules/@vuepress/theme-default/layouts/Layout.vue */ "./node_modules/@vuepress/theme-default/layouts/Layout.vue"));
  }
Reason: Error: Module build failed (from ./node_modules/stylus-loader/index.js):
Error: vuepress-plugin-meilisearch/playground/node_modules/stylus/lib/functions/index.styl:133:3
   129| 
   130| // lighten by the given amount
   131| 
   132| lighten(color, amount)
   133|   adjust(color, 'lightness', amount)
----------^
   134| 
   135| // decrease opacity by amount
   136| 

Thanks for pointing this error ! I added a new variable $msDropdownBgDarkColor to resolve this problem ❤️

@mdubus mdubus requested a review from bidoubiwa June 24, 2021 12:04
@bidoubiwa
Copy link
Contributor

I looked at the default palette of vuepress and it seems it is using the variable used by default-prefers-color-scheme.

See Styling in VuePress.

Furthermore there is a default palette provided by vuepress. I think it is possible to rely on these values to have default values.

As an example, if we look at the default search bar component that is provided by vuepress it lets us tweak with the following variable.

$accentColor = #3eaf7c
$textColor = #2c3e50
$borderColor = #eaecef
$codeBgColor = #282c34
$arrowBgColor = #ccc

Because of that, I think we should be consistent with these variable naming and our variables by just adding dark and not use ms.
It seems that we can use vuepress default theme to avoid the previous error.

@bidoubiwa
Copy link
Contributor

bidoubiwa commented Jun 25, 2021

So I tried with and without the dark theme and it worked, I'm not sure what provoked the bug the first time around:

Update styles/palette.style to comply to naming convention (see previous comment)

$accentDarkColor ?= $accentColor

$inputDarkBgColor ?= #444d52

$textDarkColor ?= #eaeaea

$borderDarkColor ?= lighten($inputDarkBgColor, 10%)

$dropdownBgDarkColor ?= darken($inputDarkBgColor, 25%)

Play with ./vuepress/styles/palette.style

// No need to define accentColor, works in both cases
$accentDarkColor = $accentColor // $accentColor comes from default vuepress theme see link below

$inputDarkBgColor = #444d52
$textDarkColor = #eaeaea
// $borderDarkColor needs to have inputDarkBgColor defined as information goes down to the plugin palette, so it is not aware that this variable exists since it does not exists in both the default palette and the palette from the dark-theme
$borderDarkColor = lighten($inputDarkBgColor, 10%) 

default vuepress palette

Other changes this emply:

  • changing the names in MeiliSearchVueBox
  • changing the names in README

Unless there is another reason not to go with these variable names?

@mdubus
Copy link
Member Author

mdubus commented Jun 28, 2021

We agreed with @bidoubiwa to rename the style variables by removing the ms prefix.
It's now done 🚀

Copy link
Contributor

@bidoubiwa bidoubiwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🔥🔥🔥

@mdubus
Copy link
Member Author

mdubus commented Jun 29, 2021

bors merge

@bors
Copy link
Contributor

bors bot commented Jun 29, 2021

🔒 Permission denied

Existing reviewers: click here to make mdubus a reviewer

@bidoubiwa
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Jun 29, 2021

Build succeeded:

@bors bors bot merged commit 430a1b8 into meilisearch:main Jun 29, 2021
@mdubus mdubus deleted the add_dark_mode branch June 29, 2021 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ask for dark mode
3 participants