@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
44 lines (43 loc) • 1.77 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import { validateIcons, watchValidator } from "../../../schema";
import { InputController } from "./controller";
export class InputIconController extends InputController {
constructor(component, name, host) {
super(component, name, host);
this.numberStringRegex = /^\d+(\.\d+)?$/;
this.parseToNumber = (value) => {
if (typeof value === 'number') {
return isNaN(value) ? null : value;
}
if (this.isNumberString(value)) {
return parseFloat(value);
}
return null;
};
this.validateNumber = (propName, value) => {
return watchValidator(this.component, propName, (value) => value === undefined || value === null || typeof value === 'number' || (typeof value === 'string' && this.numberStringRegex.test(value)), new Set(['number', 'NumberString']), value, {
hooks: {
beforePatch: (value, nextState) => {
if (nextState === null || nextState === void 0 ? void 0 : nextState.has(propName)) {
nextState === null || nextState === void 0 ? void 0 : nextState.set(propName, this.parseToNumber(value));
}
},
},
});
};
this.component = component;
}
validateIcons(value) {
validateIcons(this.component, value);
}
isNumberString(value) {
return typeof value === 'string' && this.numberStringRegex.test(value);
}
componentWillLoad() {
super.componentWillLoad();
this.validateIcons(this.component._icons);
}
}
//# sourceMappingURL=controller-icon.js.map