UNPKG

@progress/kendo-angular-typography

Version:
122 lines (121 loc) 4.82 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Directive, Input, ElementRef, Renderer2 } from '@angular/core'; import { typographyFontSizeOptions } from './models/font-size'; import { typographyFontWeightOptions } from './models/font-weight'; import { typographyTextAlignOptions } from './models/text-align'; import { typographyTextTransformOptions } from './models/text-transform'; import { typographyVariantOptions } from './models/variant'; import { isPresent } from './utils'; import { validatePackage } from '@progress/kendo-licensing'; import { packageMetadata } from './package-metadata'; import * as i0 from "@angular/core"; /** * Represents the [Kendo UI Typography directive for Angular]({% slug overview_typography %}). * Use this directive to represent element types in a uniform way by relying on the predefined Kendo theme classes. * * @example * ```html * <div kendoTypography variant="k-h1"></div> * ``` */ export class TypographyDirective { elementWrapper; renderer; element; /** * Specifies the element `variant` class that will be applied. */ variant; /** * Sets the element `font-size` style. */ fontSize; /** * Sets the element `font-weight` style. */ fontWeight; /** * Sets the element `text-align` style. */ textAlign; /** * Sets the element `text-transform` style. */ textTransform; /** * Applies the `theme-color` to the element. */ themeColor; typographyClasses = []; constructor(elementWrapper, renderer, element) { this.elementWrapper = elementWrapper; this.renderer = renderer; this.element = element; validatePackage(packageMetadata); } ngOnChanges() { this.setTypographyClasses(); } variantClass() { return typographyVariantOptions[this.variant]; } themeColorClass() { return isPresent(this.themeColor) ? `k-color-${this.themeColor}` : null; } textAlignClass() { return typographyTextAlignOptions[this.textAlign]; } fontWeightClass() { return typographyFontWeightOptions[this.fontWeight]; } fontSizeClass() { return typographyFontSizeOptions[this.fontSize]; } textTransformClass() { return typographyTextTransformOptions[this.textTransform]; } setTypographyClasses() { const element = this.element.nativeElement; this.typographyClasses.forEach((className) => { this.renderer.removeClass(element, className); }); this.typographyClasses = [ this.variantClass(), this.fontSizeClass(), this.fontWeightClass(), this.textTransformClass(), this.textAlignClass(), this.themeColorClass() ]; this.typographyClasses.forEach((className) => { if (isPresent(className)) { this.renderer.addClass(element, className); } }); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TypographyDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: TypographyDirective, isStandalone: true, selector: "[kendoTypography]", inputs: { variant: "variant", fontSize: "fontSize", fontWeight: "fontWeight", textAlign: "textAlign", textTransform: "textTransform", themeColor: "themeColor" }, exportAs: ["kendoTypography"], usesOnChanges: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TypographyDirective, decorators: [{ type: Directive, args: [{ selector: '[kendoTypography]', exportAs: 'kendoTypography', standalone: true }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ElementRef }]; }, propDecorators: { variant: [{ type: Input }], fontSize: [{ type: Input }], fontWeight: [{ type: Input }], textAlign: [{ type: Input }], textTransform: [{ type: Input }], themeColor: [{ type: Input }] } });