UNPKG

@progress/kendo-angular-inputs

Version:

Kendo UI for Angular Inputs Package - Everything you need to build professional form functionality (Checkbox, ColorGradient, ColorPalette, ColorPicker, FlatColorPicker, FormField, MaskedTextBox, NumericTextBox, RadioButton, RangeSlider, Slider, Switch, Te

171 lines (170 loc) 7.39 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { NgClass, NgIf, NgStyle } from '@angular/common'; import { Component, HostBinding, Input, ElementRef, Renderer2, ChangeDetectorRef, } from '@angular/core'; import { FormService } from '../common/formservice.service'; import { filter } from 'rxjs/operators'; import { calculateColSpan, calculateColumns, calculateGutters, DEFAULT_FORMFIELDSET_GUTTERS, generateColSpanClass, generateColumnClass, generateGuttersStyling } from '../form/utils'; import { Subscription } from 'rxjs'; import { validatePackage } from '@progress/kendo-licensing'; import { packageMetadata } from '../package-metadata'; import * as i0 from "@angular/core"; import * as i1 from "../common/formservice.service"; /** * Represents the Kendo UI FormFieldSet component for Angular. * * @remarks * Supported children components are: {@link FormFieldComponent} and {@link FormSeparatorComponent}. */ export class FormFieldSetComponent { elementRef; renderer; formService; cdr; formFieldSetClass = true; /** * Defines the legend for the fieldset. */ legend; /** * Defines the number of columns of the fieldset. * Can be a number or an array of responsive breakpoints. */ cols; /** * Defines the gutters for the fieldset. * You can specify gutters for rows and columns. */ gutters = { ...DEFAULT_FORMFIELDSET_GUTTERS }; /** * Defines the colspan for the fieldset related to the parent Form component columns. * Can be a number or an array of responsive breakpoints. */ colSpan; /** * @hidden */ columnsClass = ''; /** * @hidden */ guttersStyle = ''; _formColumnsNumber; _colSpanClass = null; _formWidth = null; _formGutters = { ...DEFAULT_FORMFIELDSET_GUTTERS }; _previousColSpan = null; _previousCols = null; _previousGutters; subs = new Subscription(); constructor(elementRef, renderer, formService, cdr) { this.elementRef = elementRef; this.renderer = renderer; this.formService = formService; this.cdr = cdr; validatePackage(packageMetadata); } ngOnInit() { this.subs.add(this.formService.formWidth.pipe(filter((width) => width !== null)).subscribe((width) => { this._formWidth = width; this.applyColumns(); this.applyGutters(); this.updateColSpanClass(); })); } ngOnChanges(changes) { if (changes['colSpan']) { this.updateColSpanClass(); } if (changes['cols']) { this.applyColumns(); } if (changes['gutters']) { this.applyGutters(); } } ngOnDestroy() { this.subs.unsubscribe(); } applyColumns() { const containerWidth = this._formWidth; const newColumnsNumber = calculateColumns(this.cols, containerWidth); if (newColumnsNumber !== this._previousCols) { this._formColumnsNumber = newColumnsNumber; this.updateColumnClasses(); this._previousCols = newColumnsNumber; } } applyGutters() { const containerWidth = this._formWidth; const newGutters = calculateGutters(this.gutters, containerWidth); if (newGutters && (newGutters.cols !== this._previousGutters?.cols || newGutters.rows !== this._previousGutters?.rows)) { this._formGutters = newGutters; this.updateGutterClasses(); this._previousGutters = newGutters; } } updateColumnClasses() { this.columnsClass = generateColumnClass(this._formColumnsNumber); this.cdr.detectChanges(); } updateGutterClasses() { this.guttersStyle = generateGuttersStyling(this._formGutters, { ...DEFAULT_FORMFIELDSET_GUTTERS }); this.cdr.detectChanges(); } updateColSpanClass() { const hostElement = this.elementRef.nativeElement; const newColSpan = calculateColSpan(this.colSpan, this._formWidth); if (newColSpan !== this._previousColSpan) { const newClass = generateColSpanClass(newColSpan); if (this._colSpanClass) { this.renderer.removeClass(hostElement, this._colSpanClass); } if (newClass) { this.renderer.addClass(hostElement, newClass); } this._colSpanClass = newClass; this._previousColSpan = newColSpan; this.cdr.detectChanges(); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FormFieldSetComponent, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i1.FormService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: FormFieldSetComponent, isStandalone: true, selector: "fieldset[kendoFormFieldSet]", inputs: { legend: "legend", cols: "cols", gutters: "gutters", colSpan: "colSpan" }, host: { properties: { "class.k-form-fieldset": "this.formFieldSetClass" } }, exportAs: ["kendoFormFieldSet"], usesOnChanges: true, ngImport: i0, template: ` <legend *ngIf="legend" class="k-form-legend"> {{ legend }} </legend> <div class="k-form-layout k-d-grid" [ngClass]="[columnsClass]" [ngStyle]="{'gap': guttersStyle}"> <ng-content></ng-content> </div> `, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FormFieldSetComponent, decorators: [{ type: Component, args: [{ exportAs: 'kendoFormFieldSet', selector: 'fieldset[kendoFormFieldSet]', template: ` <legend *ngIf="legend" class="k-form-legend"> {{ legend }} </legend> <div class="k-form-layout k-d-grid" [ngClass]="[columnsClass]" [ngStyle]="{'gap': guttersStyle}"> <ng-content></ng-content> </div> `, standalone: true, imports: [NgIf, NgClass, NgStyle], }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i1.FormService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { formFieldSetClass: [{ type: HostBinding, args: ['class.k-form-fieldset'] }], legend: [{ type: Input }], cols: [{ type: Input }], gutters: [{ type: Input }], colSpan: [{ type: Input }] } });