import BOOTSTRAP_EXAMPLE from './bootstrap5/index.js'; /** * Type utility that extracts the class keys from a template type configuration. * For example, if a template type has { input: [...], prefix: [...] }, * this will extract "input" | "prefix" as the valid ref names. */ type ExtractClassKeys = T extends Record ? keyof T : never; /** * Type utility that extracts the structure of a single template's classes. * Maps template type names (e.g., "form", "html") to their valid class ref names. * Uses Record to allow additional custom refs beyond the known ones. */ type ExtractTemplateClasses = { [K in keyof T]?: { [refName in ExtractClassKeys]?: string[]; } & { [customRef: string]: string[] | undefined; }; }; /** * The complete type structure for all templates and their class configurations. * This provides autocomplete for known templates, types, and class refs from the * bootstrap5 example, while still allowing custom overrides and extensions. * * Benefits: * - Autocomplete for template names (e.g., "button", "input", "field") * - Autocomplete for template types (e.g., "form", "html") * - Autocomplete for class ref names (e.g., "input", "prefix", "suffix") * - Flexibility to add custom templates, types, and refs */ export type TemplateClasses = { [K in keyof typeof BOOTSTRAP_EXAMPLE]?: ExtractTemplateClasses<(typeof BOOTSTRAP_EXAMPLE)[K]>; } & { [customTemplate: string]: { [templateType: string]: { [refName: string]: string[] | undefined; } | undefined; } | undefined; }; /** * Type for a single template's class configuration. * Preserves the template type -> class refs structure while allowing extensions. */ export type TemplateClassConfig = TName extends keyof typeof BOOTSTRAP_EXAMPLE ? ExtractTemplateClasses<(typeof BOOTSTRAP_EXAMPLE)[TName]> : { [templateType: string]: { [refName: string]: string[] | undefined; } | undefined; }; /** * Helper type for defining custom template classes with full type safety. * Use this when you want to override or extend the default bootstrap5 classes. * * @example * const myClasses: TemplateClasses = { * button: { * form: { * helpBlock: ['my-custom-help'], * tooltipIcon: ['my-tooltip'], * customRef: ['my-new-ref'] // Also allowed * } * }, * myCustomTemplate: { // Also allowed * form: { * customClass: ['custom'] * } * } * }; */ export type { TemplateClasses as StandardTemplateClasses };