mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-08 05:42:34 +02:00
fix(theme): improve color toggle when using dark navbar (#8615)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
a12c6f8119
commit
e8d971d2d6
4 changed files with 23 additions and 1 deletions
|
@ -1243,6 +1243,7 @@ declare module '@theme/ColorModeToggle' {
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
readonly className?: string;
|
readonly className?: string;
|
||||||
|
readonly buttonClassName?: string;
|
||||||
readonly value: ColorMode;
|
readonly value: ColorMode;
|
||||||
/**
|
/**
|
||||||
* The parameter represents the "to-be" value. For example, if currently in
|
* The parameter represents the "to-be" value. For example, if currently in
|
||||||
|
|
|
@ -15,7 +15,12 @@ import type {Props} from '@theme/ColorModeToggle';
|
||||||
|
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
|
||||||
function ColorModeToggle({className, value, onChange}: Props): JSX.Element {
|
function ColorModeToggle({
|
||||||
|
className,
|
||||||
|
buttonClassName,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
}: Props): JSX.Element {
|
||||||
const isBrowser = useIsBrowser();
|
const isBrowser = useIsBrowser();
|
||||||
|
|
||||||
const title = translate(
|
const title = translate(
|
||||||
|
@ -47,6 +52,7 @@ function ColorModeToggle({className, value, onChange}: Props): JSX.Element {
|
||||||
'clean-btn',
|
'clean-btn',
|
||||||
styles.toggleButton,
|
styles.toggleButton,
|
||||||
!isBrowser && styles.toggleButtonDisabled,
|
!isBrowser && styles.toggleButtonDisabled,
|
||||||
|
buttonClassName,
|
||||||
)}
|
)}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => onChange(value === 'dark' ? 'light' : 'dark')}
|
onClick={() => onChange(value === 'dark' ? 'light' : 'dark')}
|
||||||
|
|
|
@ -9,10 +9,12 @@ import React from 'react';
|
||||||
import {useColorMode, useThemeConfig} from '@docusaurus/theme-common';
|
import {useColorMode, useThemeConfig} from '@docusaurus/theme-common';
|
||||||
import ColorModeToggle from '@theme/ColorModeToggle';
|
import ColorModeToggle from '@theme/ColorModeToggle';
|
||||||
import type {Props} from '@theme/Navbar/ColorModeToggle';
|
import type {Props} from '@theme/Navbar/ColorModeToggle';
|
||||||
|
import styles from './styles.module.css';
|
||||||
|
|
||||||
export default function NavbarColorModeToggle({
|
export default function NavbarColorModeToggle({
|
||||||
className,
|
className,
|
||||||
}: Props): JSX.Element | null {
|
}: Props): JSX.Element | null {
|
||||||
|
const navbarStyle = useThemeConfig().navbar.style;
|
||||||
const disabled = useThemeConfig().colorMode.disableSwitch;
|
const disabled = useThemeConfig().colorMode.disableSwitch;
|
||||||
const {colorMode, setColorMode} = useColorMode();
|
const {colorMode, setColorMode} = useColorMode();
|
||||||
|
|
||||||
|
@ -23,6 +25,9 @@ export default function NavbarColorModeToggle({
|
||||||
return (
|
return (
|
||||||
<ColorModeToggle
|
<ColorModeToggle
|
||||||
className={className}
|
className={className}
|
||||||
|
buttonClassName={
|
||||||
|
navbarStyle === 'dark' ? styles.darkNavbarColorModeToggle : undefined
|
||||||
|
}
|
||||||
value={colorMode}
|
value={colorMode}
|
||||||
onChange={setColorMode}
|
onChange={setColorMode}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.darkNavbarColorModeToggle:hover {
|
||||||
|
background: var(--ifm-color-gray-800);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue