This repository was archived by the owner on Jun 5, 2023. It is now read-only.
Repository navigation
Key concepts
Valentin Gavran edited this page May 23, 2022
·
5 revisions
Each component must provide a settings token so that Anglify users can globally override the default values of the respective component. The advantage is that users no longer have to worry about forgetting to set some properties. For example, if every SnackBar in the project should be positioned on the top right, then you only have to define it once globally.
-
Create Settings Token & Token Interface
⚠️ All properties inside theEntire...settings interface must be required.⚠️ Properties inside the settings interface must not use the BooleanLike type⚠️ The TooltipSettings interface is the entry point for the end user. Partial makes allEntireTooltipSettingsoptional. This allows the user to overwrite only some settings and the rest are taken from the default settings
export interface EntireTooltipSettings = { position: Position; hoverOpenDelay: number; touchOpenDelay: number; hoverCloseDelay: number; // ... } export type TooltipSettings = Partial<EntireTooltipSettings> export const TOOLTIP_SETTINGS = new InjectionToken<TooltipSettings>('Tooltip Settings');
-
Define default component values
export const DEFAULT_TOOLTIP_SETTINGS: EntireTooltipSettings = { position: 'bottom', hoverOpenDelay: 0, touchOpenDelay: 0, hoverCloseDelay: 0, // ... };
-
Create and provide a SettingsProvider in your component or directive
@Directive({ providers: [createSettingsProvider<EntireTooltipSettings>('anglifyTooltipSettings', DEFAULT_TOOLTIP_SETTINGS, TOOLTIP_SETTINGS)], // ... }) export class TooltipDirective { // ... }
-
Inject the provided settings
public constructor(@Self() @Inject('anglifyTooltipSettings') private readonly settings: EntireTooltipSsettings) { // ... }
⚠️ The settings object now contains the default settings merged with the settings, which were overwritten by the user.
-
Initialise the input properties
@Input() public position: Position = this.settings.position;