0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-03 21:48:55 -05:00
logto/packages/ui/src/utils/logo.ts

42 lines
961 B
TypeScript

import type { Branding } from '@logto/schemas';
import { Theme } from '@logto/schemas';
import type { Nullable } from '@silverhand/essentials';
export type GetLogoUrl = {
theme: Theme;
logoUrl: string;
darkLogoUrl?: Nullable<string>;
isApple?: boolean;
};
export const getLogoUrl = ({ theme, logoUrl, darkLogoUrl, isApple }: GetLogoUrl) => {
if (theme === (isApple ? Theme.Light : Theme.Dark)) {
return darkLogoUrl ?? logoUrl;
}
return logoUrl;
};
export type GetBrandingLogoUrl = {
theme: Theme;
branding: Branding;
isDarkModeEnabled: boolean;
};
export const getBrandingLogoUrl = ({ theme, branding, isDarkModeEnabled }: GetBrandingLogoUrl) => {
const { logoUrl, darkLogoUrl } = branding;
if (!isDarkModeEnabled) {
return logoUrl;
}
if (!logoUrl && !darkLogoUrl) {
return null;
}
if (logoUrl && darkLogoUrl) {
return getLogoUrl({ theme, logoUrl, darkLogoUrl });
}
return logoUrl ?? darkLogoUrl;
};