@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
106 lines (105 loc) • 5.43 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, Input } from '@angular/core';
import { LocalizationService } from '@progress/kendo-angular-l10n';
import { getContrastFromTwoRGBAs, getRGBA } from './utils';
import { AA_RATIO, AAA_RATIO } from './constants';
import { checkIcon, xCircleIcon } from '@progress/kendo-svg-icons';
import { ContrastValidationComponent } from './contrast-validation.component';
import { NgIf } from '@angular/common';
import { IconWrapperComponent } from '@progress/kendo-angular-icons';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-l10n";
/**
* @hidden
*/
export class ContrastComponent {
localization;
value;
ratio;
checkIcon = checkIcon;
xCircleIcon = xCircleIcon;
constructor(localization) {
this.localization = localization;
}
get formatedRatio() {
return this.contrastRatio.toFixed(2);
}
get contrastRatioText() {
return `${this.localization.get('contrastRatio')}: ${this.value ? this.formatedRatio : 'n/a'}`;
}
get satisfiesAACondition() {
return this.contrastRatio >= AA_RATIO;
}
get satisfiesAAACondition() {
return this.contrastRatio >= AAA_RATIO;
}
get contrastRatio() {
const contrast = getContrastFromTwoRGBAs(getRGBA(this.value), getRGBA(this.ratio));
return contrast;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ContrastComponent, deps: [{ token: i1.LocalizationService }], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: ContrastComponent, isStandalone: true, selector: "[kendoContrastTool]", inputs: { value: "value", ratio: "ratio" }, ngImport: i0, template: `
<div class="k-contrast-ratio">
<span class="k-contrast-ratio-text">{{contrastRatioText}}</span>
<ng-container *ngIf="value">
<span class="k-contrast-validation k-text-success" *ngIf="satisfiesAACondition">
<kendo-icon-wrapper name="check" [svgIcon]="checkIcon"></kendo-icon-wrapper>
<kendo-icon-wrapper *ngIf="satisfiesAAACondition" name="check" [svgIcon]="checkIcon"></kendo-icon-wrapper>
</span>
<span class="k-contrast-validation k-text-error" *ngIf="!satisfiesAACondition">
<kendo-icon-wrapper name="x" [svgIcon]="xCircleIcon"></kendo-icon-wrapper>
</span>
</ng-container>
</div>
<div kendoContrastValidation
type="AA"
[value]="value"
[pass]="satisfiesAACondition">
</div>
<div kendoContrastValidation
type="AAA"
[value]="value"
[pass]="satisfiesAAACondition">
</div>
`, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: IconWrapperComponent, selector: "kendo-icon-wrapper", inputs: ["name", "svgIcon", "innerCssClass", "customFontClass", "size"], exportAs: ["kendoIconWrapper"] }, { kind: "component", type: ContrastValidationComponent, selector: "[kendoContrastValidation]", inputs: ["type", "pass", "value"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ContrastComponent, decorators: [{
type: Component,
args: [{
// eslint-disable-next-line @angular-eslint/component-selector
selector: '[kendoContrastTool]',
template: `
<div class="k-contrast-ratio">
<span class="k-contrast-ratio-text">{{contrastRatioText}}</span>
<ng-container *ngIf="value">
<span class="k-contrast-validation k-text-success" *ngIf="satisfiesAACondition">
<kendo-icon-wrapper name="check" [svgIcon]="checkIcon"></kendo-icon-wrapper>
<kendo-icon-wrapper *ngIf="satisfiesAAACondition" name="check" [svgIcon]="checkIcon"></kendo-icon-wrapper>
</span>
<span class="k-contrast-validation k-text-error" *ngIf="!satisfiesAACondition">
<kendo-icon-wrapper name="x" [svgIcon]="xCircleIcon"></kendo-icon-wrapper>
</span>
</ng-container>
</div>
<div kendoContrastValidation
type="AA"
[value]="value"
[pass]="satisfiesAACondition">
</div>
<div kendoContrastValidation
type="AAA"
[value]="value"
[pass]="satisfiesAAACondition">
</div>
`,
standalone: true,
imports: [NgIf, IconWrapperComponent, ContrastValidationComponent]
}]
}], ctorParameters: function () { return [{ type: i1.LocalizationService }]; }, propDecorators: { value: [{
type: Input
}], ratio: [{
type: Input
}] } });