Skip to content

Commit

Permalink
feat(v2): add ability disable dark mode toggle (#1956)
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 authored and yangshun committed Nov 11, 2019
1 parent 3be2e86 commit 9e290c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/docusaurus-theme-classic/src/theme/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Navbar() {
const [theme, setTheme] = useTheme();
const {siteConfig = {}} = context;
const {baseUrl, themeConfig = {}} = siteConfig;
const {navbar = {}} = themeConfig;
const {navbar = {}, disableDarkMode = false} = themeConfig;
const {title, logo = {}, links = []} = navbar;

const showSidebar = useCallback(() => {
Expand Down Expand Up @@ -127,16 +127,18 @@ function Navbar() {
.map((linkItem, i) => (
<NavLink {...linkItem} key={i} />
))}
<Toggle
className={styles.displayOnlyInLargeViewport}
aria-label="Dark mode toggle"
checked={theme === 'dark'}
onChange={onToggleChange}
icons={{
checked: <Moon />,
unchecked: <Sun />,
}}
/>
{!disableDarkMode && (
<Toggle
className={styles.displayOnlyInLargeViewport}
aria-label="Dark mode toggle"
checked={theme === 'dark'}
onChange={onToggleChange}
icons={{
checked: <Moon />,
unchecked: <Sun />,
}}
/>
)}
<SearchBar
handleSearchBarToggle={setIsSearchBarExpanded}
isSearchBarExpanded={isSearchBarExpanded}
Expand All @@ -158,7 +160,7 @@ function Navbar() {
)}
{title != null && <strong>{title}</strong>}
</Link>
{sidebarShown && (
{!disableDarkMode && sidebarShown && (
<Toggle
aria-label="Dark mode toggle in sidebar"
checked={theme === 'dark'}
Expand Down
6 changes: 6 additions & 0 deletions website/docs/theme-classic.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ title: Classic Theme Configuration

_This section is a work in progress._

## Common

### Dark mode

To remove the ability to switch on dark mode, there is an option `themeConfig.disableDarkMode`, which is implicitly set to `false`.

## Navbar

### Navbar Title & Logo
Expand Down

0 comments on commit 9e290c9

Please sign in to comment.