UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

50 lines (46 loc) 2.22 kB
/*! * KoliBri - The accessible HTML-Standard */ 'use strict'; var common = require('./common-DPb6NWR4.js'); const READABLE_CHARS = /[a-zA-Z0-9äöüÄÖÜß]/g; const ONLY_NUMBERS = /^\d+$/; function countReadableChars(str) { var _a; return typeof str === 'string' ? ((_a = str.match(READABLE_CHARS)) === null || _a === void 0 ? void 0 : _a.length) || 0 : 0; } function hasEnoughReadableChars(str, min = 1) { return countReadableChars(str) >= min; } function containsOnlyNumbers(str) { return ONLY_NUMBERS.test(str); } function getValidationOptions(options) { var _a; return Object.assign(Object.assign({}, options), { hooks: { afterPatch: (value, state, component, key) => { var _a, _b; if (typeof ((_a = options.hooks) === null || _a === void 0 ? void 0 : _a.afterPatch) === 'function') { (_b = options.hooks) === null || _b === void 0 ? void 0 : _b.afterPatch(value, state, component, key); } if (typeof value === 'string' && hasEnoughReadableChars(value, 3) === false && containsOnlyNumbers(value) === false) { common.a11yHint(`The heading or label ("${value}") is inaccessible. A label should consist of at least three readable characters.`); } if (typeof value === 'string' && value.length > 80) { common.uiUxHint(`A heading or label should not be longer than 80 characters.`); } }, beforePatch: (_a = options.hooks) === null || _a === void 0 ? void 0 : _a.beforePatch, } }); } const LABEL_VALUES = new Set(['string']); const validateLabel = (component, value, options = {}) => { common.watchValidator(component, '_label', (value) => typeof value === 'string', LABEL_VALUES, value, getValidationOptions(options)); }; const validateLabelWithExpertSlot = validateLabel; exports.containsOnlyNumbers = containsOnlyNumbers; exports.hasEnoughReadableChars = hasEnoughReadableChars; exports.validateLabel = validateLabel; exports.validateLabelWithExpertSlot = validateLabelWithExpertSlot; //# sourceMappingURL=label-8vcJJEVI.js.map //# sourceMappingURL=label-8vcJJEVI.js.map