Skip to content
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

feat(v2): dark mode toggle customization #3127

Merged

Conversation

Drewbi
Copy link
Contributor

@Drewbi Drewbi commented Jul 27, 2020

Motivation

Feature was requested in #3052

Have you read the Contributing Guidelines on pull requests?

Yes

Does it work

The approach I took allows users to include any css that would work in an inline react style prop. This disqualifies attributes such as content as it requires the ::before selector.
This approach allows users to customize the margin or other styling of any text or emoji they choose.

Toggle

Docs

Added the new fields to the API themeConfig section of the docusaurus.config.js doc

themeConfig: {
    colorMode: {
      defaultMode: 'light',
      disableSwitch: false,
      respectPrefersColorScheme: true,
      switchConfig: {
        darkIcon: '🌙',
        darkIconStyle: {
          marginLeft: '2px',
        },
        lightIcon: '☀️',
        lightIconStyle: {
          marginLeft: '1px',
        },
      },
    },

I was considering including a link to this page where they explain about how react does inline css. Let me know if you think it needs it.

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jul 27, 2020
@Drewbi Drewbi changed the title Drewbi/dark toggle customization feat(v2): dark mode toggle customization Jul 27, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Jul 27, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 503c613

https://deploy-preview-3127--docusaurus-2.netlify.app

@Drewbi Drewbi force-pushed the drewbi/dark-toggle-customization branch from 1c92cc1 to 4846ae1 Compare July 27, 2020 07:56
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Thanks, that seems almost fine.

I'd like a few changes:

  • Fix e2e tests when colorMode=undefined
  • Add unit tests for such edge cases so it never happen again
  • Add documentation

packages/docusaurus-theme-classic/src/themeConfigSchema.js Outdated Show resolved Hide resolved
@slorber
Copy link
Collaborator

slorber commented Jul 27, 2020

if that helps here's a pr where I validate algolia theme config: https://github.com/facebook/docusaurus/pull/3133/files

@Drewbi Drewbi marked this pull request as draft July 28, 2020 08:54
@Drewbi Drewbi marked this pull request as ready for review July 30, 2020 09:40
@Drewbi
Copy link
Contributor Author

Drewbi commented Jul 30, 2020

I opted to use lodash/merge as the nested config fields were being overwritten if only one of them had been changed. I hope the tests are adequate as well. I previously added the new fields to the API docs, should I add a section about the switch config to the guide as well?

@Drewbi Drewbi requested a review from slorber July 30, 2020 09:50
Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Thanks, that looks nice

mergeDefault should not be used in production code, Joi already does that. it's only useful for the tests

@slorber
Copy link
Collaborator

slorber commented Jul 30, 2020

I opted to use lodash/merge as the nested config fields were being overwritten if only one of them had been changed.

What do you mean? which nested config field exactly?
Can you add a test to cover the case you describe?

should I add a section about the switch config to the guide as well?

All config options should be documented, so if it's not in the doc already, it should be added

@Drewbi
Copy link
Contributor Author

Drewbi commented Jul 30, 2020

I've added some more comments to the documentation about the styling options.
I also think I finally understand how config validation works now.
Hopefully this should be good to go.

@Drewbi Drewbi requested a review from slorber July 30, 2020 16:02
@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Jul 31, 2020
@slorber slorber merged commit 53b28d2 into facebook:master Jul 31, 2020
@slorber
Copy link
Collaborator

slorber commented Jul 31, 2020

thanks that looks good :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants