37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { useTranslation } from 'react-i18next';
|
|
import { cn } from '@/lib/utils';
|
|
import { getBrand } from '@/lib/brand';
|
|
import type { BrandLogo as BrandLogoFiles } from '@/lib/brand';
|
|
|
|
interface BrandLogoProps {
|
|
/** Overrides the site brand; mainly for tests and, later, a logo loaded from site settings. */
|
|
logo?: BrandLogoFiles | null;
|
|
className?: string;
|
|
}
|
|
|
|
/**
|
|
* The site's logo, or, when it has none, the application name with its dot (what the admin always
|
|
* showed). The single place the admin draws the brand: do not hardcode it elsewhere.
|
|
*/
|
|
export function BrandLogo({ logo, className }: BrandLogoProps) {
|
|
const { t } = useTranslation();
|
|
const resolved = logo === undefined ? getBrand().logo : logo;
|
|
const name = t('common.appName');
|
|
|
|
if (resolved === null) {
|
|
return (
|
|
<div className={cn('flex items-center gap-2', className)} data-testid="brand-fallback">
|
|
<span className="h-3 w-3 rounded-full bg-primary" aria-hidden="true" />
|
|
<span className="text-lg font-semibold">{name}</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className={cn('flex items-center', className)} data-testid="brand-logo">
|
|
<img src={resolved.onLight} alt={name} className="h-10 w-auto dark:hidden" />
|
|
<img src={resolved.onDark} alt={name} className="hidden h-10 w-auto dark:block" />
|
|
</div>
|
|
);
|
|
}
|