index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { css, cx } from '@emotion/css';
  2. import React from 'react';
  3. import { config } from '@grafana/runtime';
  4. import { styleMixins } from '@grafana/ui';
  5. import { Branding, BrandComponentProps } from 'app/core/components/Branding/Branding';
  6. import { setFooterLinksFn, FooterLink } from 'app/core/components/Footer/Footer';
  7. interface WhitelabelingSettings {
  8. links: FooterLink[];
  9. appTitle: string;
  10. loginSubtitle: string;
  11. loginTitle: string;
  12. loginLogo: string;
  13. loginBackground: string;
  14. loginBoxBackground: string;
  15. menuLogo: string;
  16. }
  17. export function initWhitelabeling() {
  18. const settings = (config as any).whitelabeling as WhitelabelingSettings;
  19. if (!settings) {
  20. return;
  21. }
  22. Branding.LoginTitle = 'Welcome to Grafana Enterprise';
  23. if (settings.links.length > 0) {
  24. setFooterLinksFn(() => {
  25. return settings.links.map((link) => ({ ...link, target: '_blank' }));
  26. });
  27. }
  28. if (settings.appTitle) {
  29. Branding.AppTitle = settings.appTitle;
  30. }
  31. if (settings.loginLogo) {
  32. Branding.LoginLogo = (props: BrandComponentProps) => (
  33. <img
  34. className={cx(
  35. props.className,
  36. css`
  37. max-width: 150px;
  38. max-height: 250px;
  39. width: auto;
  40. @media ${styleMixins.mediaUp(config.theme.breakpoints.sm)} {
  41. max-width: 250px;
  42. }
  43. `
  44. )}
  45. src={settings.loginLogo}
  46. />
  47. );
  48. Branding.LoginLogo.displayName = 'BrandingLoginLogo';
  49. // Reset these to not break existing login screens
  50. Branding.LoginTitle = '';
  51. Branding.GetLoginSubTitle = () => '';
  52. }
  53. if (settings.loginTitle) {
  54. Branding.LoginTitle = settings.loginTitle;
  55. }
  56. if (settings.loginSubtitle) {
  57. Branding.GetLoginSubTitle = () => settings.loginSubtitle;
  58. }
  59. if (settings.menuLogo) {
  60. Branding.MenuLogo = (props: BrandComponentProps) => <img className={props.className} src={settings.menuLogo} />;
  61. Branding.MenuLogo.displayName = 'BrandingMenuLogo';
  62. }
  63. if (settings.loginBackground) {
  64. const background = css`
  65. background: ${settings.loginBackground};
  66. background-size: cover;
  67. `;
  68. Branding.LoginBackground = (props: BrandComponentProps) => (
  69. <div className={cx(background, props.className)}>{props.children}</div>
  70. );
  71. Branding.LoginBackground.displayName = 'BrandingLoginBackground';
  72. }
  73. if (settings.loginBoxBackground) {
  74. const background = css`
  75. background: ${settings.loginBoxBackground};
  76. background-size: cover;
  77. `;
  78. Branding.LoginBoxBackground = () => background;
  79. }
  80. }