signal-template-forms
Version:
A powerful, type-safe Angular forms library built with signals, providing reactive form management with excellent developer experience and performance.
82 lines (81 loc) • 3.11 kB
TypeScript
import { InjectionToken, Provider } from '@angular/core';
import { type SignalFormConfig, type SignalFormContainer } from '../models/signal-form.model';
import * as i0 from "@angular/core";
export type ThemeMode = 'light' | 'dark' | 'auto';
export interface SignalFormsThemeConfig {
darkMode?: boolean;
defaultTheme?: ThemeMode;
}
export declare const SIGNAL_FORMS_THEME_CONFIG: InjectionToken<SignalFormsThemeConfig>;
/**
* Provider function for Signal Forms theme configuration
* @param config - Theme configuration options
* @returns Provider array for Angular DI
*/
export declare function provideSignalFormsTheme(config?: SignalFormsThemeConfig): Provider[];
/**
* Theme Service for Signal Forms
*
* Provides centralized theme management for the form system.
* Manages global theme state and applies theme classes to the HTML element.
*
* This service is a singleton that coordinates theme across all forms in the app.
* When any form requests a theme check, it determines the root form's theme
* and applies the appropriate class to the HTML element.
*/
export declare class SignalFormThemeService {
private document;
private config;
private _theme;
private _isDarkMode;
/**
* Current theme mode setting for the service
*/
readonly theme: import("@angular/core").Signal<ThemeMode>;
/**
* Whether dark mode is currently active based on system preference
*/
readonly isDarkMode: import("@angular/core").Signal<boolean>;
constructor(document: Document, config: SignalFormsThemeConfig | null);
/**
* Set the global theme mode
* @param theme - 'light', 'dark', or 'auto'
*/
setTheme(theme: ThemeMode): void;
/**
* Toggle between light and dark theme
*/
toggleTheme(): void;
/**
* Check theme for any form configuration and trigger HTML class updates
* This method determines the effective theme but doesn't return it for binding
* Instead, it triggers side effects to update the global HTML classes
*
* @param formOrConfig - Form container or form config
*/
checkTheme<TModel>(formOrConfig: SignalFormContainer<TModel> | SignalFormConfig<TModel>): void;
/**
* Apply global dark mode based on service theme setting
* Used when darkMode is enabled in provider config
*/
private updateGlobalDarkMode;
/**
* Get the effective theme for any form configuration
* Recursively finds the root form and uses its theme setting
*
* @param formOrConfig - Form container or form config
* @returns 'light' or 'dark'
*/
private getEffectiveTheme;
/**
* Get the effective theme from the service (resolves 'auto' to 'light' or 'dark')
*/
private getServiceEffectiveTheme;
/**
* Update HTML classes based on effective theme
* @param effectiveTheme - The theme to apply
*/
private updateHtmlClasses;
static ɵfac: i0.ɵɵFactoryDeclaration<SignalFormThemeService, [null, { optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<SignalFormThemeService>;
}