@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
97 lines (96 loc) • 3.89 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 { Directive, ElementRef, HostBinding, Input, Renderer2 } from '@angular/core';
import { getStylingClasses } from '../common/utils';
import * as i0 from "@angular/core";
const DEFAULT_SIZE = 'medium';
const DEFAULT_ROUNDED = 'medium';
/**
* Renders the [Kendo UI CheckBox]({% slug overview_checkbox %}) input component.
* Apply this directive to `input type="checkbox"` HTML elements.
*
* @example
* ```html
* <input type="checkbox" kendoCheckBox />
* ```
*/
export class CheckBoxDirective {
renderer;
hostElement;
kendoClass = true;
get isDisabled() {
return this.hostElement.nativeElement.disabled;
}
/**
* Sets the `size` property to specify the width and height of the CheckBox
* ([see example]({% slug appearance_checkboxdirective %}#toc-size)).
*
* @default 'medium'
*/
set size(size) {
const newSize = size ? size : DEFAULT_SIZE;
this.handleClasses(newSize, 'size');
this._size = newSize;
}
get size() {
return this._size;
}
/**
* Sets the `rounded` property to specify the border radius of the CheckBox
* ([see example](slug:appearance_checkboxdirective#toc-roundness)).
*
* @default 'medium'
*
*/
set rounded(rounded) {
const newRounded = rounded ? rounded : DEFAULT_ROUNDED;
this.handleClasses(newRounded, 'rounded');
this._rounded = newRounded;
}
get rounded() {
return this._rounded;
}
_size = 'medium';
_rounded = 'medium';
constructor(renderer, hostElement) {
this.renderer = renderer;
this.hostElement = hostElement;
}
ngAfterViewInit() {
const stylingInputs = ['size', 'rounded'];
stylingInputs.forEach(input => {
this.handleClasses(this[input], input);
});
}
handleClasses(value, input) {
const elem = this.hostElement.nativeElement;
const classes = getStylingClasses('checkbox', input, this[input], value);
if (classes.toRemove) {
this.renderer.removeClass(elem, classes.toRemove);
}
if (classes.toAdd) {
this.renderer.addClass(elem, classes.toAdd);
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CheckBoxDirective, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: CheckBoxDirective, isStandalone: true, selector: "input[kendoCheckBox]", inputs: { size: "size", rounded: "rounded" }, host: { properties: { "class.k-checkbox": "this.kendoClass", "class.k-disabled": "this.isDisabled" } }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CheckBoxDirective, decorators: [{
type: Directive,
args: [{
selector: 'input[kendoCheckBox]',
standalone: true
}]
}], ctorParameters: function () { return [{ type: i0.Renderer2 }, { type: i0.ElementRef }]; }, propDecorators: { kendoClass: [{
type: HostBinding,
args: ['class.k-checkbox']
}], isDisabled: [{
type: HostBinding,
args: ['class.k-disabled']
}], size: [{
type: Input
}], rounded: [{
type: Input
}] } });