@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
93 lines (92 loc) • 2.98 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 { InjectionToken } from "@angular/core";
/**
* @hidden
*
* Checks if the value is `null` or `undefined`. Falsy values like '', 0, false, NaN, etc. are regarded as present.
*/
export const isPresent = (value) => value !== null && value !== undefined;
/**
* @hidden
*/
export const areSame = (value1, value2) => value1 === value2 || (value1 === null && value2 === undefined) || (value1 === undefined && value2 === null);
/**
* @hidden
*/
export const requiresZoneOnBlur = (ngControl) => ngControl &&
(!ngControl.touched || (ngControl.control && ngControl.control.updateOn === 'blur'));
/**
* @hidden
*
* Fits the contender number into the specified bounds. If the number is NaN or null, the min is returned.
*
* @param contender Represents the number you want to fit into specified bounds.
* @param min The inclusive lower bound number.
* @param max The inclusive upper bound number.
*/
export const fitIntoBounds = (contender, min, max) => {
if (!isPresent(contender) || isNaN(contender)) {
return min;
}
return contender <= min ? min : contender >= max ? max : contender;
};
/**
* @hidden
*/
export const SIZE_MAP = {
small: 'sm',
medium: 'md',
large: 'lg'
};
/**
* @hidden
*/
export const ROUNDED_MAP = {
small: 'sm',
medium: 'md',
large: 'lg',
full: 'full'
};
/**
* @hidden
*/
export const isNone = (style) => style === 'none';
/**
* @hidden
*
* Returns the styling classes to be added and removed
*/
export const getStylingClasses = (componentType, stylingOption, previousValue, newValue) => {
switch (stylingOption) {
case 'size':
return {
toRemove: `k-${componentType}-${SIZE_MAP[previousValue]}`,
toAdd: newValue !== 'none' ? `k-${componentType}-${SIZE_MAP[newValue]}` : ''
};
case 'rounded':
return {
toRemove: `k-rounded-${ROUNDED_MAP[previousValue]}`,
toAdd: newValue !== 'none' ? `k-rounded-${ROUNDED_MAP[newValue]}` : ''
};
case 'fillMode':
return {
toRemove: `k-${componentType}-${previousValue}`,
toAdd: newValue !== 'none' ? `k-${componentType}-${newValue}` : ''
};
default:
break;
}
};
/**
* @hidden
*
* Used to differentiate between the Radio and CheckBox components in their base class.
*/
export const COMPONENT_TYPE = new InjectionToken('TYPE_TOKEN');
/**
* @hidden
*/
export const replaceMessagePlaceholder = (message, name, value) => message.replace(new RegExp(`{\\s*${name}\\s*}`, 'g'), value);