2023-02-06 10:01:03 -08:00
|
|
|
import clsx from 'clsx';
|
2022-05-11 17:54:23 -07:00
|
|
|
import React from 'react';
|
|
|
|
|
2022-07-22 15:25:52 -07:00
|
|
|
import { useSoapboxConfig, useSettings, useTheme } from 'soapbox/hooks';
|
2022-05-11 17:54:23 -07:00
|
|
|
|
2022-05-15 20:30:48 -07:00
|
|
|
interface ISiteLogo extends React.ComponentProps<'img'> {
|
|
|
|
/** Extra class names for the <img> element. */
|
2023-02-15 13:26:27 -08:00
|
|
|
className?: string
|
2022-05-28 09:02:04 -07:00
|
|
|
/** Override theme setting for <SitePreview /> */
|
2023-02-15 13:26:27 -08:00
|
|
|
theme?: 'dark' | 'light'
|
2022-05-15 20:30:48 -07:00
|
|
|
}
|
|
|
|
|
2022-05-11 17:54:23 -07:00
|
|
|
/** Display the most appropriate site logo based on the theme and configuration. */
|
2022-05-28 09:02:04 -07:00
|
|
|
const SiteLogo: React.FC<ISiteLogo> = ({ className, theme, ...rest }) => {
|
2022-05-11 17:54:23 -07:00
|
|
|
const { logo, logoDarkMode } = useSoapboxConfig();
|
|
|
|
const settings = useSettings();
|
2022-11-26 03:19:57 -08:00
|
|
|
|
|
|
|
let darkMode = useTheme() === 'dark';
|
|
|
|
if (theme === 'dark') darkMode = true;
|
2022-05-11 17:54:23 -07:00
|
|
|
|
2022-05-11 18:47:21 -07:00
|
|
|
/** Soapbox logo. */
|
|
|
|
const soapboxLogo = darkMode
|
2022-11-15 05:23:36 -08:00
|
|
|
? require('assets/images/soapbox-logo-white.svg')
|
|
|
|
: require('assets/images/soapbox-logo.svg');
|
2022-05-11 18:47:21 -07:00
|
|
|
|
2022-05-11 17:54:23 -07:00
|
|
|
// Use the right logo if provided, then use fallbacks.
|
|
|
|
const getSrc = () => {
|
|
|
|
// In demo mode, use the Soapbox logo.
|
2022-05-11 18:47:21 -07:00
|
|
|
if (settings.get('demo')) return soapboxLogo;
|
2022-05-11 17:54:23 -07:00
|
|
|
|
|
|
|
return (darkMode && logoDarkMode)
|
|
|
|
? logoDarkMode
|
2022-05-11 18:47:21 -07:00
|
|
|
: logo || logoDarkMode || soapboxLogo;
|
2022-05-11 17:54:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
// eslint-disable-next-line jsx-a11y/alt-text
|
2022-05-15 20:30:48 -07:00
|
|
|
<img
|
2023-02-06 10:01:03 -08:00
|
|
|
className={clsx('object-contain', className)}
|
2022-05-15 20:30:48 -07:00
|
|
|
src={getSrc()}
|
|
|
|
{...rest}
|
|
|
|
/>
|
2022-05-11 17:54:23 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SiteLogo;
|