Skip to content

Commit

Permalink
Merge 468c8b5 into 07f7ef2
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaribo committed Apr 25, 2024
2 parents 07f7ef2 + 468c8b5 commit 8be71b4
Show file tree
Hide file tree
Showing 35 changed files with 3,103 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Button group component now allows resetting the selection state via the `selectedItems` property [#1168](https://github.com/IgniteUI/igniteui-webcomponents/pull/1168)
- Date picker component [#174](https://github.com/IgniteUI/igniteui-webcomponents/issues/174)

### Changed
- Combo, Select and Dropdown components now use the native Popover API [#1082](https://github.com/IgniteUI/igniteui-webcomponents/pull/1082)
Expand Down
2 changes: 2 additions & 0 deletions src/components/common/definitions/defineAllComponents.ts
Expand Up @@ -15,6 +15,7 @@ import IgcCheckboxComponent from '../../checkbox/checkbox.js';
import IgcSwitchComponent from '../../checkbox/switch.js';
import IgcChipComponent from '../../chip/chip.js';
import IgcComboComponent from '../../combo/combo.js';
import IgcDatepickerComponent from '../../date-picker/date-picker.js';
import IgcDateTimeInputComponent from '../../date-time-input/date-time-input.js';
import IgcDialogComponent from '../../dialog/dialog.js';
import IgcDropdownGroupComponent from '../../dropdown/dropdown-group.js';
Expand Down Expand Up @@ -78,6 +79,7 @@ const allComponents: IgniteComponent[] = [
IgcCheckboxComponent,
IgcChipComponent,
IgcComboComponent,
IgcDatepickerComponent,
IgcDropdownComponent,
IgcDropdownGroupComponent,
IgcDropdownHeaderComponent,
Expand Down
1 change: 1 addition & 0 deletions src/components/common/localization/validation-en.ts
Expand Up @@ -8,4 +8,5 @@ export default {
max: 'A value no more than {0} should be entered',
email: 'A valid email address should be entered',
url: 'A valid url address should be entered',
disabledDate: 'The entered value {0} is within the disabled dates range',
} as const;
2 changes: 2 additions & 0 deletions src/components/common/util.ts
Expand Up @@ -8,6 +8,8 @@ export const partNameMap = (partNameInfo: PartNameInfo) => {
.join(' ');
};

export function noop() {}

export const asPercent = (part: number, whole: number) => (part / whole) * 100;

export const clamp = (number: number, min: number, max: number) =>
Expand Down
33 changes: 29 additions & 4 deletions src/components/common/validators.ts
@@ -1,3 +1,4 @@
import { DateTimeUtil } from '../date-time-input/date-util.js';
import validatorMessages from './localization/validation-en.js';
import { asNumber, format, isDefined } from './util.js';

Expand All @@ -10,9 +11,12 @@ export interface Validator<T = any> {
isValid: ValidatorHandler<T>;
}

const emailRegex =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;

export const requiredValidator: Validator<{
required: boolean;
value?: string;
value?: unknown;
}> = {
key: 'valueMissing',
message: validatorMessages.required,
Expand Down Expand Up @@ -103,9 +107,6 @@ export const stepValidator: Validator<{
: true,
};

const emailRegex =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;

export const emailValidator: Validator<{ value: string }> = {
key: 'typeMismatch',
message: validatorMessages.email,
Expand All @@ -117,3 +118,27 @@ export const urlValidator: Validator<{ value: string }> = {
message: validatorMessages.url,
isValid: ({ value }) => URL.canParse(value),
};

export const minDateValidator: Validator<{
value?: Date | null;
min?: Date | null;
}> = {
key: 'rangeUnderflow',
message: ({ min }) => format(validatorMessages.min, `${min}`),
isValid: ({ value, min }) =>
min
? !DateTimeUtil.lessThanMinValue(value ?? new Date(), min, false, true)
: true,
};

export const maxDateValidator: Validator<{
value?: Date | null;
max?: Date | null;
}> = {
key: 'rangeOverflow',
message: ({ max }) => format(validatorMessages.max, `${max}`),
isValid: ({ value, max }) =>
max
? !DateTimeUtil.greaterThanMaxValue(value ?? new Date(), max, false, true)
: true,
};

0 comments on commit 8be71b4

Please sign in to comment.