@progress/kendo-angular-layout
Version:
Kendo UI for Angular Layout Package - a collection of components to create professional application layoyts
153 lines (152 loc) • 6.25 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Component, HostBinding, Input, Renderer2, ElementRef } from '@angular/core';
import { VERTICAL_SUFFIX, ALIGN_PREFIX, JUSTIFY_PREFIX } from './util';
import { L10N_PREFIX, LocalizationService } from '@progress/kendo-angular-l10n';
import { isNumber, isPresent } from '../common/util';
import { validatePackage } from '@progress/kendo-licensing';
import { packageMetadata } from '../package-metadata';
import { isChanged } from '@progress/kendo-angular-common';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-l10n";
/**
* Represents the [Kendo UI StackLayout component for Angular]({% slug overview_stacklayout %}).
*/
export class StackLayoutComponent {
renderer;
element;
localization;
hostClass = true;
get horizontalClass() {
return this.orientation === 'horizontal';
}
get verticalClass() {
return this.orientation === 'vertical';
}
get dir() {
return this.direction;
}
/**
* Specifies the horizontal and vertical alignment of the inner StackLayout elements
* ([see example]({% slug layout_stacklayout %}#toc-alignment)).
*/
set align(align) {
this._align = Object.assign({}, this._align, align);
this.handleAlignClasses();
}
get align() {
return this._align;
}
/**
* Specifies the gap between the inner StackLayout elements. The default value is `0`
* ([see example](slug:layout_stacklayout#toc-gap)).
*/
gap = 0;
/**
* Specifies the orientation of the StackLayout
* ([see example]({% slug layout_stacklayout %}#toc-orientation)).
*
* The possible values are:
* (Default) `horizontal`
* `vertical`
*/
orientation = 'horizontal';
_align = {
horizontal: 'stretch',
vertical: 'stretch'
};
justifyClass;
alignClass;
constructor(renderer, element, localization) {
this.renderer = renderer;
this.element = element;
this.localization = localization;
validatePackage(packageMetadata);
}
ngAfterViewInit() {
this.handleAlignClasses();
this.setGap();
}
ngOnChanges(changes) {
if (isChanged('gap', changes)) {
this.setGap();
}
if (isChanged('orientation', changes)) {
this.handleAlignClasses();
}
}
handleAlignClasses() {
const elem = this.element.nativeElement;
if (isPresent(this.justifyClass)) {
this.renderer.removeClass(elem, this.justifyClass);
}
if (isPresent(this.alignClass)) {
this.renderer.removeClass(elem, this.alignClass);
}
if (this.orientation === 'horizontal') {
this.justifyClass = `${JUSTIFY_PREFIX}-${this.align.horizontal}`;
this.alignClass = `${ALIGN_PREFIX}-${VERTICAL_SUFFIX[this.align.vertical]}`;
}
else {
this.justifyClass = `${JUSTIFY_PREFIX}-${VERTICAL_SUFFIX[this.align.vertical]}`;
this.alignClass = `${ALIGN_PREFIX}-${this.align.horizontal}`;
}
this.renderer.addClass(elem, this.justifyClass);
this.renderer.addClass(elem, this.alignClass);
}
setGap() {
const parsedGap = isNumber(this.gap) ? `${this.gap}px` : this.gap;
this.renderer.setStyle(this.element.nativeElement, 'gap', parsedGap);
}
get direction() {
return this.localization.rtl ? 'rtl' : 'ltr';
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: StackLayoutComponent, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }, { token: i1.LocalizationService }], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: StackLayoutComponent, isStandalone: true, selector: "kendo-stacklayout", inputs: { align: "align", gap: "gap", orientation: "orientation" }, host: { properties: { "class.k-stack-layout": "this.hostClass", "class.k-hstack": "this.horizontalClass", "class.k-vstack": "this.verticalClass", "attr.dir": "this.dir" } }, providers: [
LocalizationService,
{
provide: L10N_PREFIX,
useValue: 'kendo.stacklayout'
}
], exportAs: ["kendoStackLayout"], usesOnChanges: true, ngImport: i0, template: `
<ng-content></ng-content>
`, isInline: true });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: StackLayoutComponent, decorators: [{
type: Component,
args: [{
exportAs: 'kendoStackLayout',
selector: 'kendo-stacklayout',
providers: [
LocalizationService,
{
provide: L10N_PREFIX,
useValue: 'kendo.stacklayout'
}
],
template: `
<ng-content></ng-content>
`,
standalone: true
}]
}], ctorParameters: function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }, { type: i1.LocalizationService }]; }, propDecorators: { hostClass: [{
type: HostBinding,
args: ['class.k-stack-layout']
}], horizontalClass: [{
type: HostBinding,
args: ['class.k-hstack']
}], verticalClass: [{
type: HostBinding,
args: ['class.k-vstack']
}], dir: [{
type: HostBinding,
args: ['attr.dir']
}], align: [{
type: Input
}], gap: [{
type: Input
}], orientation: [{
type: Input
}] } });