@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 6.15 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
"use strict";const events=require("./events-221fcb43.js"),associated_controller=require("./associated.controller-8d2d4650.js"),prop_validators=require("./prop.validators-888c8338.js"),accessAndShortKey=require("./access-and-short-key-4ee0c067.js"),hideLabel=require("./hide-label-cfe594e0.js"),label=require("./label-477be19d.js"),common=require("./common-1ab929ac.js"),tooltipAlign=require("./tooltip-align-c6cf9049.js"),validateAdjustHeight=(t,e)=>{prop_validators.watchBoolean(t,"_adjustHeight",e)},validateHideError=(t,e,o)=>{prop_validators.watchBoolean(t,"_hideError",e,o)},validateMsg=(t,e)=>{prop_validators.objectObjectHandler(e,(()=>{try{e=prop_validators.parseJson(e)}catch(t){}prop_validators.watchValidator(t,"_msg",(t=>common.isObject(t)&&"string"==typeof(null==t?void 0:t._description)),new Set(["MsgPropType"]),e,{defaultValue:{_description:"",_type:"error"}})}))},validateTouched=(t,e)=>{prop_validators.watchBoolean(t,"_touched",e)},getRenderStates=t=>{var e,o;const i=Boolean("error"===(null===(e=t._msg)||void 0===e?void 0:e._type)&&t._msg._description&&(null===(o=t._msg._description)||void 0===o?void 0:o.length)>0)&&!0===t._touched,n="string"==typeof t._hint&&t._hint.length>0,a=[];return!0===i&&a.push(`${t._id}-error`),!0===n&&a.push(`${t._id}-hint`),{hasError:i,hasHint:n,ariaDescribedBy:a}};class ControlledInputController extends associated_controller.AssociatedInputController{constructor(t,e,o){super(t,e,o),this.component=t}validateAlert(t){prop_validators.watchBoolean(this.component,"_alert",t)}validateTouched(t){validateTouched(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateAlert(this.component._alert),this.validateTouched(this.component._touched)}}class InputController extends ControlledInputController{constructor(t,e,o){super(t,e,o),this.valueChangeListeners=[],this.onFacade={onBlur:this.onBlur.bind(this),onChange:this.onChange.bind(this),onClick:this.onClick.bind(this),onFocus:this.onFocus.bind(this),onInput:this.onInput.bind(this)},this.component=t}validateAccessKey(t){accessAndShortKey.validateAccessKey(this.component,t),accessAndShortKey.validateAccessAndShortKey(t,this.component._shortKey)}validateAdjustHeight(t){validateAdjustHeight(this.component,t)}validateDisabled(t){prop_validators.watchBoolean(this.component,"_disabled",t),!0===t&&prop_validators.a11yHintDisabled()}validateTooltipAlign(t){tooltipAlign.validateTooltipAlign(this.component,t)}validateError(t){"string"==typeof t&&t.length>0?this.validateMsg({_description:t,_type:"error"}):this.validateMsg(void 0)}validateHideError(t){validateHideError(this.component,t,{hooks:{afterPatch:()=>{this.component.state._hideError&&prop_validators.a11yHint("Property hide-error for inputs: Only use when the error message is shown outside of the input component.")}}})}validateHideLabel(t){hideLabel.validateHideLabel(this.component,t,{hooks:{afterPatch:()=>{this.component.state._hideLabel&&prop_validators.a11yHint("Property hide-label for inputs: Only use for exceptions like search inputs that are clearly identifiable by their context.")}}})}validateHint(t){prop_validators.watchString(this.component,"_hint",t)}validateId(t){prop_validators.watchString(this.component,"_id",t,{minLength:1}),""!==t&&void 0!==t||prop_validators.devHint("A unique ID on the input fields is not strictly required, but it might be relevant for E2E tests.")}validateLabel(t){label.validateLabelWithExpertSlot(this.component,t,{required:!0})}validateMsg(t){validateMsg(this.component,t)}validateOn(t){"object"==typeof t&&prop_validators.setState(this.component,"_on",t)}validateShortKey(t){accessAndShortKey.validateShortKey(this.component,t),accessAndShortKey.validateAccessAndShortKey(this.component._accessKey,t)}validateSmartButton(t){prop_validators.objectObjectHandler(t,(()=>{try{t=prop_validators.parseJson(t)}catch(t){}prop_validators.setState(this.component,"_smartButton",t)}))}validateTabIndex(t){accessAndShortKey.validateTabIndex(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateAccessKey(this.component._accessKey),this.validateAdjustHeight(this.component._adjustHeight),this.validateError(this.component._error),this.component._msg&&this.validateMsg(this.component._msg),this.validateDisabled(this.component._disabled),this.validateHideError(this.component._hideError),this.validateHideLabel(this.component._hideLabel),this.validateHint(this.component._hint),this.validateId(this.component._id),this.validateLabel(this.component._label),this.validateShortKey(this.component._shortKey),this.validateSmartButton(this.component._smartButton),this.validateOn(this.component._on),this.validateTabIndex(this.component._tabIndex),accessAndShortKey.validateAccessAndShortKey(this.component._accessKey,this.component._shortKey)}onBlur(t){var e;this.component._touched=!0,events.stopPropagation(t),events.tryToDispatchKoliBriEvent("blur",this.host),"function"==typeof(null===(e=this.component._on)||void 0===e?void 0:e.onBlur)&&this.component._on.onBlur(t)}onChange(t,e){var o;e=null!=e?e:t.target.value,events.tryToDispatchKoliBriEvent("change",this.host,e),"function"==typeof(null===(o=this.component._on)||void 0===o?void 0:o.onChange)&&this.component._on.onChange(t,e),this.valueChangeListeners.forEach((t=>t(e)))}onInput(t,e=!0,o){var i;o=null!=o?o:t.target.value,events.stopPropagation(t),events.tryToDispatchKoliBriEvent("input",this.host,o),e&&this.setFormAssociatedValue(o),"function"==typeof(null===(i=this.component._on)||void 0===i?void 0:i.onInput)&&this.component._on.onInput(t,o)}onClick(t){var e;events.stopPropagation(t),events.tryToDispatchKoliBriEvent("click",this.host),"function"==typeof(null===(e=this.component._on)||void 0===e?void 0:e.onClick)&&this.component._on.onClick(t)}onFocus(t){var e;events.stopPropagation(t),events.tryToDispatchKoliBriEvent("focus",this.host),"function"==typeof(null===(e=this.component._on)||void 0===e?void 0:e.onFocus)&&this.component._on.onFocus(t)}addValueChangeListener(t){this.valueChangeListeners.push(t)}}exports.InputController=InputController,exports.getRenderStates=getRenderStates;