@cfpb/cfpb-design-system
Version:
CFPB's UI framework
3 lines (2 loc) • 9.88 kB
JavaScript
(()=>{var ue=Object.defineProperty;var se=Object.getOwnPropertySymbols;var Le=Object.prototype.hasOwnProperty,Ie=Object.prototype.propertyIsEnumerable;var ne=(e,t,a)=>t in e?ue(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,X=(e,t)=>{for(var a in t||(t={}))Le.call(t,a)&&ne(e,a,t[a]);if(se)for(var a of se(t))Ie.call(t,a)&&ne(e,a,t[a]);return e};var z=(e,t)=>{for(var a in t)ue(e,a,{get:t[a],enumerable:!0})};var U={};z(U,{default:()=>Ae});var Ae={};var q={};z(q,{default:()=>Me});var Me={};var Y={};z(Y,{default:()=>Te});var Te={};var J={};z(J,{default:()=>Ce});var Ce={};var V={};z(V,{default:()=>Be});var Be={};var W={};z(W,{default:()=>Re});var Re={};var $={};z($,{default:()=>Ke});var Ke={};var G={};z(G,{default:()=>Ue});var Ue={};var Z={};z(Z,{default:()=>Ye});var Ye={};var Q={};z(Q,{default:()=>Ve});var Ve={};var M="data-js-hook";var fe="state_";function ee(){let e={};function t(f,o){return{}.hasOwnProperty.call(e,f)?e[f].push(o):e[f]=[o],this}function a(f,o){if(!{}.hasOwnProperty.call(e,f))return this;let n=e[f].indexOf(o);return n!==-1&&e[f].splice(n,1),this}function b(f,o){if(!{}.hasOwnProperty.call(e,f))return this;o=o||{};let n=e[f];for(let s=0,u=n.length;s<u;s++)n[s].call(this,o);return this}return this.addEventListener=t,this.removeEventListener=a,this.dispatchEvent=b,this.getRegisteredEvents=()=>e,this}function T(e,t){if(!e)return!1;let a=e.getAttribute(M);return a?(a=a.split(" "),a.indexOf(t)>-1):!1}function be(e,t){if(T(e,t))return t;if(t.indexOf(" ")!==-1){let b=M+" values cannot contain spaces!";throw new Error(b)}let a=e.getAttribute(M);return a!==null&&(t=a+" "+t),e.setAttribute(M,t),t}var te=fe+"atomic_init";function We(e,t){if(!e||!e.classList){let a=e+' is not valid. Check that element is a DOM node with class "'+t+'"';throw new Error(a)}return e}function $e(e,t){let a=e.classList.contains(t)?e:e.querySelector("."+t);if(!a){let b=t+" not found on or in passed DOM node.";throw new Error(b)}return a}function ae(e,t){return We(e,t),$e(e,t)}function N(e){return T(e,te)?!1:(be(e,te),!0)}function re(e,t,a,b={}){let o=(a||document).querySelectorAll(e),n=[],s,u;for(let g=0,m=o.length;g<m;g++)u=o[g],T(u,te)===!1&&(s=new t(u),s.init(b),n.push(s));return n}function oe(){return!!new RegExp(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i).test(navigator.userAgent)}var Ge;function Ze(e){return e.replace(/[-\\^$*+?.()|[\]{}]/g,"\\$&")}function Qe(e,t){return RegExp(Ze(t.trim()),"i").test(e)}function et(e,t,a){let b=e,f=t,o=(a==null?void 0:a.maxSelections)||5,n=[],s=[],u=[],g=[],m=-1;function y(l){return f+"-"+l.value.trim().replace(/\s+/g,"-").toLowerCase()}function v(){return s.length>=o}function h(l){let p,x=[],E=!1;for(let L=0,A=l.length;L<A;L++)p=l[L],E=v()?!1:p.defaultSelected,x.push({id:y(p),value:p.value,text:p.text,checked:E}),E&&s.push(L);return x}function S(){return n=h(b),this}function k(l){return n[l].checked=!n[l].checked,s.length<o&&n[l].checked?(s.push(l),s.sort(),!0):(n[l].checked=!1,s=s.filter(function(p){return p!==l}),!1)}function B(l,p,x,E){return Qe(p.text,E)&&l.push(x),l}function D(l){return Object.prototype.toString.call(l)!=="[object String]"&&(l=""),g=u,n.length>0&&(u=n.reduce(function(p,x,E){return B(p,x,E,l)},[])),m=-1,u}function P(l){return n[l]}function R(l){let p=u.length,x=p===0?n.length:p;l<0?m=-1:l>=x?m=x-1:m=l}function H(){return m}return this.init=S,this.toggleOption=k,this.getSelectedIndices=function(){return s},this.isAtMaxSelections=v,this.filterIndices=D,this.clearFilter=function(){return u=g=[],Ge},this.getFilterIndices=function(){return u},this.getLastFilterIndices=function(){return g},this.getIndex=H,this.setIndex=R,this.resetIndex=function(){return m=-1,m},this.getOption=P,this}var pe=et;function j(e,t,a){let b=document.createElement(e);return Object.keys(a).forEach(f=>{let o=a[f];f in b?b[f]=o:b.setAttribute(f,o)}),t&&t.appendChild(b),b}var he='<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="cf-icon-svg cf-icon-svg--error" viewBox="0 0 12 19"><path d="M11.383 13.644A1.03 1.03 0 0 1 9.928 15.1L6 11.172 2.072 15.1a1.03 1.03 0 1 1-1.455-1.456l3.928-3.928L.617 5.79a1.03 1.03 0 1 1 1.455-1.456L6 8.261l3.928-3.928a1.03 1.03 0 0 1 1.455 1.456L7.455 9.716z"/></svg>';var it=he,_="o-multiselect",dt="a-checkbox",ct="a-text-input",ge="prev",C="next",ie="Enter",lt=" ",ve="Escape",st="ArrowUp",me="ArrowDown",xe="Tab",we={renderTags:!0,maxSelections:5};function F(e){e.classList.add(_);let t=ae(e,_),a=!1,b,f,o,n,s,u,g,m,y,v,h,S=[],k;function B(){h.classList.remove("u-no-results"),h.classList.add("u-filtered");let i=o.getLastFilterIndices();for(let r=0,d=i.length;r<d;r++)S[i[r]].classList.remove("u-filter-match");i=o.getFilterIndices();for(let r=0,d=i.length;r<d;r++)S[i[r]].classList.add("u-filter-match")}function D(){h.classList.remove("u-filtered","u-no-results");for(let i=0,r=h.children.length;i<r;i++)h.children[i].classList.remove("u-filter-match");o.clearFilter()}function P(){h.classList.add("u-no-results"),h.classList.remove("u-filtered")}function R(i){return i.length>0?(B(),!0):(P(),!1)}function H(i){D(),o.resetIndex();let r=o.filterIndices(i);R(r)}function l(){return u.classList.add("u-active"),v.classList.remove("u-invisible"),v.setAttribute("aria-hidden",!1),k.dispatchEvent("expandbegin",{target:k}),k}function p(){return u.classList.remove("u-active"),v.classList.add("u-invisible"),v.setAttribute("aria-hidden",!0),o.resetIndex(),k.dispatchEvent("collapsebegin",{target:k}),k}function x(i){i===C?o.setIndex(o.getIndex()+1):i===ge&&o.setIndex(o.getIndex()-1);let r=o.getIndex();if(r>-1){let d=r,c=o.getFilterIndices();c.length>0&&(d=c[r]);let O=o.getOption(d).value,ze=h.querySelector('[data-option="'+O+'"]').querySelector("input");a=!0,ze.focus()}else a=!1,y.focus()}function E(){y.value="",D()}function L(i){let r=i.target;r.tagName==="BUTTON"&&(i.preventDefault(),r.removeEventListener("click",L),r.querySelector("label").click())}function A(i){if(i.key===lt||i.key===ie){let r=i.target.querySelector("label");h.querySelector("#"+r.getAttribute("for")).click()}}function de(i){return b+"-"+i.value.trim().replace(/[^\w]/g,"-").toLowerCase()}function ce(i,r){let d=de(r),c=j("li",null,{"data-option":r.value}),w=j("button",c,{type:"button",class:"a-tag-filter",innerHTML:"<label for="+d+">"+r.text+it+"</label>"});i.appendChild(c),w.addEventListener("click",L),w.addEventListener("keydown",A)}function le(i){let r=o.getOption(i)||o.getOption(o.getIndex());if(r){if(r.checked){h.classList.contains("u-max-selections")&&h.classList.remove("u-max-selections");let d='[data-option="'+r.value+'"]',c=g.querySelector(d);typeof c!="undefined"&&c&&(g==null||g.removeChild(c))}else s!=null&&s.renderTags&&g&&ce(g,r);o.toggleOption(i),o.isAtMaxSelections()&&h.classList.add("u-max-selections"),k.dispatchEvent("selectionsupdated",{target:k})}o.resetIndex(),a=!1,v.getAttribute("aria-hidden")==="false"&&y.focus()}function ye(i){le(Number(i.target.getAttribute("data-index"))),E()}function ke(){m.addEventListener("mousemove",function(d){let c=d.target;d.offsetX>c.offsetWidth-35?c.style.cursor="pointer":c.style.cursor="auto"}),m.addEventListener("mouseup",function(d){let c=d.target;d.offsetX>c.offsetWidth-35&&v.offsetHeight===140&&y.blur()}),y.addEventListener("input",function(){H(this.value)}),y.addEventListener("focus",function(){v.getAttribute("aria-hidden")==="true"&&l()}),y.addEventListener("blur",function(){!a&&v.getAttribute("aria-hidden")==="false"&&p()}),y.addEventListener("keydown",function(d){let c=d.key;v.getAttribute("aria-hidden")==="true"&&c!==xe&&l(),c===ie?(d.preventDefault(),x(C)):c===ve?(E(),p()):c===me?x(C):c===xe&&!d.shiftKey&&v.getAttribute("aria-hidden")==="false"&&p()}),h.addEventListener("mousedown",function(){a=!0}),h.addEventListener("keydown",function(d){let c=d.key,w=d.target,O=w.checked;if(c===ie){d.preventDefault(),w.checked=!O;let I=new Event("change",{bubbles:!1,cancelable:!0});w.dispatchEvent(I)}else c===ve?(y.focus(),p()):c===st?x(ge):c===me&&x(C)}),v.addEventListener("mousedown",function(d){d.target.tagName==="LABEL"&&(a=!0)});let i=h.querySelectorAll("input");for(let d=0,c=i.length;d<c;d++)i[d].addEventListener("change",ye);let r=g.querySelectorAll("button");for(let d=0,c=r.length;d<c;d++)r[d].addEventListener("click",L),r[d].addEventListener("keydown",A)}function je(){u=document.createElement("div"),u.className=_,g=j("ul",null,{className:"m-tag-group"}),m=j("header",u,{className:_+"__header"}),y=j("input",m,{className:_+"__search "+ct,type:"text",placeholder:f||"Select up to five",id:t.id,autocomplete:"off"}),v=j("fieldset",u,{className:_+"__fieldset u-invisible","aria-hidden":"true"});let i=_+"__options";o.isAtMaxSelections()&&(i+=" u-max-selections"),h=j("ul",v,{className:i});let r,d,c;for(let w=0,O=n.length;w<O;w++){r=n[w],d=de(r),c=o.getOption(w).checked;let I=j("li",h,{"data-option":r.value,"data-cy":"multiselect-option",class:"m-form-field m-form-field--checkbox"});j("input",I,{id:d,type:"checkbox",value:r.value,name:b,class:dt+" "+_+"__checkbox",checked:c,"data-index":w}),j("label",I,{for:d,textContent:r.text,className:_+"__label a-label"}),S.push(I),c&&(s!=null&&s.renderTags)&&ce(g,r)}return u.insertBefore(g,m),t.parentNode.insertBefore(u,t),u.appendChild(t),u}function _e(i=we){if(!N(t))return this;if(oe())return this;if(k=this,b=t.name||t.id,f=t.getAttribute("placeholder"),n=t.options||[],s=X(X({},we),i),n.length>0){o=new pe(n,b,s).init();let r=je();t.parentNode.removeChild(t),t=r,N(t),ke()}return this}function Ee(){return o}this.init=_e,this.expand=l,this.collapse=p;let K=new ee;return this.addEventListener=K.addEventListener,this.removeEventListener=K.removeEventListener,this.dispatchEvent=K.dispatchEvent,this.getModel=Ee,this.updateSelections=le,this.selectionClickHandler=L,this.selectionKeyDownHandler=A,this}F.BASE_CLASS=_;F.init=e=>re(`.${_}`,F,void 0,e);})();
//# sourceMappingURL=index.js.map