@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 4.84 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{s as t,t as i}from"./events-29e84d75.js";import{A as s}from"./associated.controller-5bee50ee.js";import{b as e,o,p as h,w as a,c as r,a as n,i as l,j as d,s as u}from"./prop.validators-64749272.js";import{v as c,a as f,b as p,c as v}from"./access-and-short-key-e094398d.js";import{v as m}from"./hide-label-8c202307.js";import{a as y}from"./label-e8ec0e3a.js";import{a as b}from"./common-0f1f2276.js";import{v as g}from"./tooltip-align-5902aa96.js";const _=(t,o)=>{e(t,"_adjustHeight",o)},j=(t,o,n)=>{e(t,"_hideError",o,n)},k=(t,e)=>{o(e,(()=>{try{e=h(e)}catch(t){}a(t,"_msg",(t=>b(t)&&"string"==typeof(null==t?void 0:t._description)),new Set(["MsgPropType"]),e,{defaultValue:{_description:"",_type:"error"}})}))},x=(t,o)=>{e(t,"_touched",o)},A=t=>{var o,e;const n=Boolean("error"===(null===(o=t._msg)||void 0===o?void 0:o._type)&&t._msg._description&&(null===(e=t._msg._description)||void 0===e?void 0:e.length)>0)&&!0===t._touched,i="string"==typeof t._hint&&t._hint.length>0,s=[];return!0===n&&s.push(`${t._id}-error`),!0===i&&s.push(`${t._id}-hint`),{hasError:n,hasHint:i,ariaDescribedBy:s}};class B extends s{constructor(t,o,e){super(t,o,e),this.component=t}validateAlert(t){e(this.component,"_alert",t)}validateTouched(t){x(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateAlert(this.component._alert),this.validateTouched(this.component._touched)}}class E extends B{constructor(t,o,e){super(t,o,e),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){c(this.component,t),f(t,this.component._shortKey)}validateAdjustHeight(t){_(this.component,t)}validateDisabled(t){e(this.component,"_disabled",t),!0===t&&r()}validateTooltipAlign(t){g(this.component,t)}validateError(t){"string"==typeof t&&t.length>0?this.validateMsg({_description:t,_type:"error"}):this.validateMsg(void 0)}validateHideError(t){j(this.component,t,{hooks:{afterPatch:()=>{this.component.state._hideError&&n("Property hide-error for inputs: Only use when the error message is shown outside of the input component.")}}})}validateHideLabel(t){m(this.component,t,{hooks:{afterPatch:()=>{this.component.state._hideLabel&&n("Property hide-label for inputs: Only use for exceptions like search inputs that are clearly identifiable by their context.")}}})}validateHint(t){l(this.component,"_hint",t)}validateId(t){l(this.component,"_id",t,{minLength:1}),""!==t&&void 0!==t||d("A unique ID on the input fields is not strictly required, but it might be relevant for E2E tests.")}validateLabel(t){y(this.component,t,{required:!0})}validateMsg(t){k(this.component,t)}validateOn(t){"object"==typeof t&&u(this.component,"_on",t)}validateShortKey(t){p(this.component,t),f(this.component._accessKey,t)}validateSmartButton(t){o(t,(()=>{try{t=h(t)}catch(t){}u(this.component,"_smartButton",t)}))}validateTabIndex(t){v(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),f(this.component._accessKey,this.component._shortKey)}onBlur(o){var e;this.component._touched=!0,t(o),i("blur",this.host),"function"==typeof(null===(e=this.component._on)||void 0===e?void 0:e.onBlur)&&this.component._on.onBlur(o)}onChange(t,o){var e;o=null!=o?o:t.target.value,i("change",this.host,o),"function"==typeof(null===(e=this.component._on)||void 0===e?void 0:e.onChange)&&this.component._on.onChange(t,o),this.valueChangeListeners.forEach((t=>t(o)))}onInput(o,e=!0,n){var s;n=null!=n?n:o.target.value,t(o),i("input",this.host,n),e&&this.setFormAssociatedValue(n),"function"==typeof(null===(s=this.component._on)||void 0===s?void 0:s.onInput)&&this.component._on.onInput(o,n)}onClick(o){var e;t(o),i("click",this.host),"function"==typeof(null===(e=this.component._on)||void 0===e?void 0:e.onClick)&&this.component._on.onClick(o)}onFocus(o){var e;t(o),i("focus",this.host),"function"==typeof(null===(e=this.component._on)||void 0===e?void 0:e.onFocus)&&this.component._on.onFocus(o)}addValueChangeListener(t){this.valueChangeListeners.push(t)}}export{E as I,A as g};