2024-10-07 14:54:03 +00:00
|
|
|
// TODO: document this all, no tests are exercising this code.
|
|
|
|
|
|
|
|
import {getGristConfig} from 'app/common/urlUtils';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {styled} from 'grainjs';
|
|
|
|
|
2024-10-07 14:54:03 +00:00
|
|
|
/**
|
|
|
|
* Is this grist installation or someone's modified installation. We allow modifying logo
|
|
|
|
* at the right corner, and making it wider (removing site switcher in the process).
|
|
|
|
*
|
|
|
|
* If fieldLink, shows wide logo and hides the switcher, otherwise shows the regular logo.
|
|
|
|
*
|
|
|
|
* We can convert any org name to a ProductFlavor and any ProductFlavor to a CustomTheme.
|
|
|
|
*
|
|
|
|
* TODO: explain what is fieldlink, I think this is an user of custom Grist build.
|
|
|
|
*/
|
2023-05-05 01:09:51 +00:00
|
|
|
export type ProductFlavor = 'grist' | 'fieldlink';
|
2020-10-02 15:10:00 +00:00
|
|
|
|
|
|
|
export interface CustomTheme {
|
|
|
|
bodyClassName?: string;
|
|
|
|
wideLogo?: boolean; // Stretch the logo and hide the org name.
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFlavor(org?: string): ProductFlavor {
|
|
|
|
// Using a URL parameter e.g. __themeOrg=fieldlink allows overriding the org used for custom
|
|
|
|
// theming, for testing.
|
|
|
|
const themeOrg = new URLSearchParams(window.location.search).get('__themeOrg');
|
|
|
|
if (themeOrg) { org = themeOrg; }
|
|
|
|
|
2024-10-07 14:54:03 +00:00
|
|
|
// If still not set, use the org from the config.
|
|
|
|
org ||= getGristConfig()?.org;
|
|
|
|
|
|
|
|
// If the org is 'fieldlink', use the fieldlink flavor.
|
2020-10-02 15:10:00 +00:00
|
|
|
if (org === 'fieldlink') {
|
|
|
|
return 'fieldlink';
|
|
|
|
}
|
2024-10-07 14:54:03 +00:00
|
|
|
|
|
|
|
// For any other situation, use the grist flavor.
|
2020-10-02 15:10:00 +00:00
|
|
|
return 'grist';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTheme(flavor: ProductFlavor): CustomTheme {
|
|
|
|
switch (flavor) {
|
|
|
|
case 'fieldlink':
|
|
|
|
return {
|
|
|
|
wideLogo: true,
|
|
|
|
bodyClassName: cssFieldLinkBody.className,
|
|
|
|
};
|
|
|
|
default:
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const cssFieldLinkBody = styled('body', `
|
|
|
|
--icon-GristLogo: url("icons/logo-fieldlink.png");
|
|
|
|
--icon-GristWideLogo: url("icons/logo-fieldlink.png");
|
|
|
|
--grist-logo-bg: white;
|
|
|
|
`);
|