UNPKG

@public-ui/components

Version:

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

4 lines 5.94 kB
/*! * KoliBri - The accessible HTML-Standard */ import{s as stopPropagation,t as tryToDispatchKoliBriEvent}from"./events-29e84d75.js";import{A as AssociatedInputController}from"./associated.controller-5bee50ee.js";import{b as watchBoolean,o as objectObjectHandler,p as parseJson,w as watchValidator,c as a11yHintDisabled,a as a11yHint,i as watchString,j as devHint,s as setState}from"./prop.validators-64749272.js";import{v as validateAccessKey,a as validateAccessAndShortKey,b as validateShortKey,c as validateTabIndex}from"./access-and-short-key-e094398d.js";import{v as validateHideLabel}from"./hide-label-8c202307.js";import{a as validateLabelWithExpertSlot}from"./label-e8ec0e3a.js";import{a as isObject}from"./common-0f1f2276.js";import{v as validateTooltipAlign}from"./tooltip-align-5902aa96.js";const validateAdjustHeight=(t,e)=>{watchBoolean(t,"_adjustHeight",e)},validateHideError=(t,e,o)=>{watchBoolean(t,"_hideError",e,o)},validateMsg=(t,e)=>{objectObjectHandler(e,(()=>{try{e=parseJson(e)}catch(t){}watchValidator(t,"_msg",(t=>isObject(t)&&"string"==typeof(null==t?void 0:t._description)),new Set(["MsgPropType"]),e,{defaultValue:{_description:"",_type:"error"}})}))},validateTouched=(t,e)=>{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 AssociatedInputController{constructor(t,e,o){super(t,e,o),this.component=t}validateAlert(t){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){validateAccessKey(this.component,t),validateAccessAndShortKey(t,this.component._shortKey)}validateAdjustHeight(t){validateAdjustHeight(this.component,t)}validateDisabled(t){watchBoolean(this.component,"_disabled",t),!0===t&&a11yHintDisabled()}validateTooltipAlign(t){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&&a11yHint("Property hide-error for inputs: Only use when the error message is shown outside of the input component.")}}})}validateHideLabel(t){validateHideLabel(this.component,t,{hooks:{afterPatch:()=>{this.component.state._hideLabel&&a11yHint("Property hide-label for inputs: Only use for exceptions like search inputs that are clearly identifiable by their context.")}}})}validateHint(t){watchString(this.component,"_hint",t)}validateId(t){watchString(this.component,"_id",t,{minLength:1}),""!==t&&void 0!==t||devHint("A unique ID on the input fields is not strictly required, but it might be relevant for E2E tests.")}validateLabel(t){validateLabelWithExpertSlot(this.component,t,{required:!0})}validateMsg(t){validateMsg(this.component,t)}validateOn(t){"object"==typeof t&&setState(this.component,"_on",t)}validateShortKey(t){validateShortKey(this.component,t),validateAccessAndShortKey(this.component._accessKey,t)}validateSmartButton(t){objectObjectHandler(t,(()=>{try{t=parseJson(t)}catch(t){}setState(this.component,"_smartButton",t)}))}validateTabIndex(t){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),validateAccessAndShortKey(this.component._accessKey,this.component._shortKey)}onBlur(t){var e;this.component._touched=!0,stopPropagation(t),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,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,stopPropagation(t),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;stopPropagation(t),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;stopPropagation(t),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)}}export{InputController as I,getRenderStates as g};