Files
authentik/web/src/elements/mixins/branding.ts
Teffen Ellis c28b65a3f2 Web: Controllers cleanup (#14616)
* web: Fix issues surrounding availability of controllers during init.

web: Fix edgecase where flow does not have brand.

* web: Fix import path.

* web: Clean up mixin/controller paths.

* web: Prepare for consistent import styling.

- Prep for Storybook fixes.

* web: Update MDX types.

* web: Fix issues surrounding async imports, MDX typing, relative paths.

* web: Format. Clarify.

* web: Group module types.
2025-05-26 07:06:14 -04:00

81 lines
2.2 KiB
TypeScript

import { DefaultBrand } from "#common/ui/config";
import { createMixin } from "#elements/types";
import { consume, createContext } from "@lit/context";
import type { CurrentBrand, FooterLink } from "@goauthentik/api";
/**
* The Lit context for application branding.
*
* @category Context
* @see {@linkcode BrandingMixin}
* @see {@linkcode WithBrandConfig}
*/
export const BrandingContext = createContext<CurrentBrand>(
Symbol.for("authentik-branding-context"),
);
/**
* A mixin that provides the current brand to the element.
*
* @see {@linkcode WithBrandConfig}
*/
export interface BrandingMixin {
/**
* The current style branding configuration.
*/
readonly brand: Readonly<CurrentBrand>;
readonly brandingTitle: string;
readonly brandingLogo: string;
readonly brandingFavicon: string;
readonly brandingFooterLinks: FooterLink[];
}
/**
* A mixin that provides the current brand to the element.
*
* @category Mixin
*
* @see {@link https://lit.dev/docs/composition/mixins/#mixins-in-typescript | Lit Mixins}
*/
export const WithBrandConfig = createMixin<BrandingMixin>(
({
/**
* The superclass constructor to extend.
*/
SuperClass,
/**
* Whether or not to subscribe to the context.
*/
subscribe = true,
}) => {
abstract class BrandingProvider extends SuperClass implements BrandingMixin {
@consume({
context: BrandingContext,
subscribe,
})
public brand!: CurrentBrand;
public get brandingTitle(): string {
return this.brand.brandingTitle ?? DefaultBrand.brandingTitle;
}
public get brandingLogo(): string {
return this.brand.brandingLogo ?? DefaultBrand.brandingLogo;
}
public get brandingFavicon(): string {
return this.brand.brandingFavicon ?? DefaultBrand.brandingFavicon;
}
public get brandingFooterLinks(): FooterLink[] {
return this.brand.uiFooterLinks ?? DefaultBrand.uiFooterLinks;
}
}
return BrandingProvider;
},
);