@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 3.06 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
;const index=require("./index-8b802221.js"),getRenderStates=require("./getRenderStates-8e102335.js"),label=require("./label-21c38949.js"),validateInputSelectOptions=t=>{if("object"==typeof t&&null!==t){if("string"==typeof t.label&&t.label.length>0)return t.disabled=!0===t.disabled,t.label=`${t.label}`.trim(),!1===label.hasEnoughReadableChars(t.label,3)&&!1===label.containsOnlyNumbers(t.label)&&index.a11yHint(`A differing Aria-Label (${t.label}) is not accessible. A differing Aria-Label should consist of at least three readable characters.`),!Array.isArray(t.options)||void 0===t.options.find((t=>!1===validateInputSelectOptions(t)));if("number"==typeof t.label)return!0}return!1},validateOptions=(t,e,i={})=>{index.watchJsonArrayString(t,"_options",(t=>"object"==typeof t&&null!==t&&"string"==typeof t.label&&t.label.length>0),e,void 0,i)},validateOptionsWithOptgroup=(t,e,i={})=>{index.watchJsonArrayString(t,"_options",validateInputSelectOptions,e,void 0,i)},validateRequired=(t,e)=>{index.watchBoolean(t,"_required",e)},orientationOptions=["horizontal","vertical"],fillKeyOptionMap=(t,e,i="")=>{e.forEach(((e,o)=>{const n=`${i}-${o}`;"object"==typeof e&&null!==e&&"string"==typeof e.label&&e.label.length>0&&(Array.isArray(e.options)?fillKeyOptionMap(t,e.options,n):t.set(n,e))}))};class InputCheckboxRadioController extends getRenderStates.InputController{constructor(t,e,i){super(t,e,i),this.component=t}validateRequired(t){validateRequired(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateRequired(this.component._required)}}class InputRadioController extends InputCheckboxRadioController{constructor(t,e,i){super(t,e,i),this.keyOptionMap=new Map,this.getOptionByKey=t=>this.keyOptionMap.get(t),this.afterPatchOptions=(t,e,i,o)=>{"_value"===o&&this.setFormAssociatedValue(t)},this.beforePatchOptions=(t,e)=>{const i=e.has("_options")?e.get("_options"):this.component.state._options;Array.isArray(i)&&i.length>0&&(this.keyOptionMap.clear(),fillKeyOptionMap(this.keyOptionMap,i))},this.component=t}validateOrientation(t){index.watchValidator(this.component,"_orientation",(t=>"string"==typeof t&&orientationOptions.includes(t)),new Set([`Orientation {${orientationOptions.join(", ")}`]),t,{defaultValue:"vertical"})}validateOptions(t){validateOptions(this.component,t,{hooks:{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions}})}validateValue(t){t=Array.isArray(t)?t[0]:t,index.setState(this.component,"_value",t,{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions})}componentWillLoad(){super.componentWillLoad(),this.validateOrientation(this.component._orientation),this.validateOptions(this.component._options),this.validateValue(this.component._value)}}exports.InputCheckboxRadioController=InputCheckboxRadioController,exports.InputRadioController=InputRadioController,exports.fillKeyOptionMap=fillKeyOptionMap,exports.validateOptions=validateOptions,exports.validateOptionsWithOptgroup=validateOptionsWithOptgroup;