-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Show dark logo on transparent background
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React from 'react'; | ||
import Link from '@docusaurus/Link'; | ||
import useBaseUrl from '@docusaurus/useBaseUrl'; | ||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
import { useThemeConfig, type NavbarLogo } from '@docusaurus/theme-common'; | ||
import ThemedImage from '@theme/ThemedImage'; | ||
import type { Props } from '@theme/Logo'; | ||
|
||
function LogoThemedImage({ | ||
logo, | ||
alt, | ||
imageClassName, | ||
}: { | ||
logo: NavbarLogo; | ||
alt: string; | ||
imageClassName?: string; | ||
}) { | ||
const sources = { | ||
light: useBaseUrl(logo.src), | ||
dark: useBaseUrl(logo.srcDark || logo.src), | ||
}; | ||
const themedImage = ( | ||
<ThemedImage | ||
className={logo.className} | ||
sources={sources} | ||
height={logo.height} | ||
width={logo.width} | ||
alt={alt} | ||
style={logo.style} | ||
/> | ||
); | ||
|
||
// Is this extra div really necessary? | ||
// introduced in https://github.com/facebook/docusaurus/pull/5666 | ||
return imageClassName ? ( | ||
<div className={`${imageClassName} relative`}> | ||
{themedImage} | ||
<img | ||
src={logo.srcDark} | ||
id="header-logo-dark" | ||
className={`${logo.className} hidden absolute top-0 right-0 bottom-0 left-0 opacity-0 transition-opacity duration-400`} | ||
style={logo.style} | ||
alt={alt} | ||
/> | ||
</div> | ||
) : ( | ||
themedImage | ||
); | ||
} | ||
|
||
export default function Logo(props: Props): JSX.Element { | ||
const { | ||
siteConfig: { title }, | ||
} = useDocusaurusContext(); | ||
const { | ||
navbar: { title: navbarTitle, logo }, | ||
} = useThemeConfig(); | ||
|
||
const { imageClassName, titleClassName, ...propsRest } = props; | ||
const logoLink = useBaseUrl(logo?.href || '/'); | ||
|
||
// If visible title is shown, fallback alt text should be | ||
// an empty string to mark the logo as decorative. | ||
const fallbackAlt = navbarTitle ? '' : title; | ||
|
||
// Use logo alt text if provided (including empty string), | ||
// and provide a sensible fallback otherwise. | ||
const alt = logo?.alt ?? fallbackAlt; | ||
|
||
return ( | ||
<Link | ||
to={logoLink} | ||
{...propsRest} | ||
{...(logo?.target && { target: logo.target })} | ||
> | ||
{logo && ( | ||
<LogoThemedImage | ||
logo={logo} | ||
alt={alt} | ||
imageClassName={imageClassName} | ||
/> | ||
)} | ||
{navbarTitle != null && <b className={titleClassName}>{navbarTitle}</b>} | ||
</Link> | ||
); | ||
} |