@govbr-ds/core
Version:
Padrão Digital de Governo
2 lines • 22.1 kB
JavaScript
!function e(t,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define("core",[],o):"object"==typeof exports?exports.core=o():t.core=o()}(self,()=>(()=>{var e=()=>{},t,o=()=>{};(()=>{class e{constructor(e,t,o){this.name=e,this.component=t,this.notFound=o,this.multiple=t.hasAttribute("multiple"),this._setOptionsList(),this._setBehavior()}get selected(){return this._optionSelected("value")}get selectedValue(){return this._optionSelected("inputValue")}_optionSelected(e){let t=[];for(const[o,i]of this.optionsList.entries())if(this.multiple)o>0&&i.selected&&t.push(i[e]);else if(i.selected){t=i[e];break}return t}_removeNotFoundElement(){const e=this.component.querySelector(".br-list");e.querySelector(".br-item.not-found")&&e.removeChild(e.querySelector(".br-item.not-found"))}_addNotFoundElement(){const e=undefined,t=`\n <div class="br-item not-found">\n <div class="container pl-0 pr-0">\n <div class="row">\n <div class="col-auto">\n <img src="${"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGYAAABCCAYAAACl4qNCAAAABHNCSVQICAgIfAhkiAAAGMxJREFUeF7NXQl8FOXZf2bPbLKbbLIJARJChEQSCFc4IqAY/CiIgMZardYD0R9SW/3EVlAkSoAPQaAai1awleKnrVYR0wattVKxthWUI4AYCCEkMeQix26OPWdn+jwzzGaz2WM22YDv78dv1sx7/+e5n/eVgctU4mesH+9WqlZyttaZjEIdxznNsTzn1oDbYVaoY5qAUdWDSnuKc3Xtsh7fcewyTet7Owwz2DPT5z72Y85lfRrHmSB3LIZh6kAdvZ9RGbd0HSr6Vm67cOrlN5/S1/9m92xQKrN5HjI4u2OY22ZLUGg00YxaFc27ORfPslZ1QnwrA0wb73ZdAKX6qzFLbv5b6fCpVjljGQv+mg7ApptLFh+QU9+7zqABE59XNMHpbHuDZ22Twp1UrwlqYv+mYJSPdR7ecmYg/UypPxzt+PM/7nS0mhdxVnueu7t7eH/7U8UZWhil8jgDijcr1m56I1A/xoIPjApQ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aL1o/vM9/clv/pjuw+8pEoErz8RhGma8MCjSfPASJr2u8y15V+2NXV/cMW1V1/669CGPBlAjRXYlh3p4Lm8Jo3beqQhNzSqE2vKPL/NGLTW9OFK3VCJewKSbC48Oc82Xz2786ci/vcM5zNF9MwrB2xIZwtCIgeE0JK3pfBlSUUabT+H/o2KtwXNxlObL93IA6k9H4igPjPcc5NWXjUIbd6LhQv9je0DwVlYUYcnxSKIGKHNDo2gCFZjiYj9WFjLsH2h/UqlCGRHUoVNHHeIXm7zHJ03bWvz1VnMRlKt8rYHzXnF93PJVnmfFoQEzCsz14EwMzDEHT2OsbNXgAyum2Odqs56tsaoOh1tGm1LJdw9pdzkkuRqUfhflro7Hd1e7uRk82KV7hhQ6yntv/MJbSiZpZG9onuOmuemVcxmHgmQoVz59sfHv6qcuEgd9h/gsitjFaPKd5sQAAAABJRU5ErkJggg=="}">\n </div>\n <div class="col">\n <p>Não encontramos o que você está procurando!</p>\n </div>\n </div>\n </div>\n </div>\n `,o=undefined;this.component.querySelector(".br-list").insertAdjacentHTML("beforeend",this.notFound?this.notFound:t)}_setOptionsList(){this.optionsList=[];for(const e of this.component.querySelectorAll(".br-list .br-item"))for(const t of e.querySelectorAll(".br-radio input, .br-checkbox input")){const o={element:e,focus:!1,inputValue:t.value,selected:!1,value:t.nextElementSibling.innerText,visible:!0};this.optionsList.push(o)}}resetOptionsList(){this._unsetSelectionBehavior(),this._setOptionsList(),this._setSelectionBehavior(),this._setAria()}_setBehavior(){this._setSearchIcon(),this._setDropdownBehavior(),this._setKeyboardBehavior(),this._setSelectionBehavior(),this._setFilterBehavior(),this._prepareComponent()}_setDropdownBehavior(){for(const e of this.component.querySelectorAll('.br-input input[type="text"]'))e.addEventListener("focus",()=>{this._resetFocus()}),e.addEventListener("click",()=>{this._openSelect(),this._resetFocus()});for(const e of this.component.querySelectorAll(".br-input .br-button[data-trigger]"))e.addEventListener("click",()=>{for(const e of this.component.querySelectorAll(".br-list"))e.hasAttribute("expanded")?this._closeSelect():this._openSelect()});window.document.addEventListener("click",e=>{this.component.contains(e.target)||this._closeSelect()})}_setKeyboardBehavior(){for(const e of this.component.querySelectorAll('.br-input input[type="text"]'))e.addEventListener("keydown",this._handleKeydownOnInput.bind(this));for(const e of this.component.querySelectorAll(".br-list"))e.addEventListener("keydown",this._handleKeydownOnList.bind(this))}_prepareComponent(){const e=this.component.querySelector(".br-input"),t=this.component.querySelector(".br-input .br-button"),o=this.component.querySelector(".br-list");o.setAttribute("id",`list-${Math.floor(1e4*Math.random())}`),o.setAttribute("role","listbox"),o.setAttribute("tabindex","-1"),o.setAttribute("aria-label","Lista de Opções"),e.setAttribute("role","combobox"),e.setAttribute("aria-expanded",!1),e.setAttribute("aria-controls",`${o.id}`),e.setAttribute("aria-autocomplete","list"),t.setAttribute("aria-controls",`${o.id}`),t.setAttribute("aria-expanded",!1),t.setAttribute("aria-label","Exibir lista"),this.component.querySelectorAll(".br-list .br-item").forEach(e=>{e.setAttribute("role","option")}),this.multiple&&e.setAttribute("aria-multiselectable",!0)}_unsetKeyboardBehavior(){for(const e of this.component.querySelectorAll('.br-input input[type="text"]'))e.removeEventListener("keydown",this._handleKeydownOnInput,!1);for(const e of this.component.querySelectorAll(".br-list"))e.addEventListener("keydown",this._handleKeydownOnList.bind(this))}_handleKeydownOnInput(e){switch(e.key){case"Tab":this._closeSelect(),this._resetFocus();break;case"ArrowDown":e.preventDefault(),this._openSelect(),this._getNextItem().focus();break;case"ArrowUp":e.preventDefault(),this._openSelect(),this._getPreviousItem().focus();break;case"Escape":this._closeSelect();break;case"Enter":this.component.querySelector(".br-list").hasAttribute("expanded")?this._closeSelect():this._openSelect()}}_handleKeydownOnList(e){switch(e.preventDefault(),e.key){case"Tab":this._closeSelect(),this._resetFocus();break;case"Escape":for(const e of this.component.querySelectorAll('.br-input input[type="text"]'))e.focus();this._closeSelect();break;case"Enter":case" ":this._setKeyClickOnOption(e.currentTarget);break;case"ArrowUp":this._getPreviousItem().focus();break;case"ArrowDown":this._getNextItem().focus()}}_setKeyClickOnOption(e){for(const[t,o]of e.querySelectorAll(".br-item").entries())if(this.optionsList[t].focus)for(const e of o.querySelectorAll('.br-radio input[type="radio"], .br-checkbox input[type="checkbox"]'))e.click(),this._sendEvent()}_sendEvent(){const e=new CustomEvent("onChange",{bubbles:!0,detail:this.component});this.component.dispatchEvent(e)}_setDefaultSelected(){this.component.querySelectorAll(".br-list .br-item").forEach(e=>{const t=undefined;(e.classList.contains("selected")||e.querySelector("input").hasAttribute("checked"))&&this._setSelected(this._positionSelected(e),e)})}_positionSelected(e){for(const[t,o]of this.component.querySelectorAll(".br-list .br-item").entries())if(o===e)return t;return 0}_handleClickOnCheck(e,t,o){if(this.multiple)o.currentTarget.hasAttribute("checked")?this._removeSelected(e,t):this._setSelected(e,t);else{for(const[e,t]of this.component.querySelectorAll(".br-list .br-item").entries())this._removeSelected(e,t);this._setSelected(e,t),this._closeSelect()}if(t.hasAttribute("data-all"))for(const e of t.querySelectorAll('.br-checkbox input[type="checkbox"]'))if(e.hasAttribute("checked")){for(const e of this.component.querySelectorAll(".br-list .br-item"))for(const t of e.querySelectorAll('.br-checkbox input[type="checkbox"]'))t.hasAttribute("checked")||t.click();t.querySelectorAll("label")[0].innerText="Deselecionar Todos"}else this._setAttribute(),t.querySelectorAll("label")[0].innerText="Selecionar Todos";this._sendEvent()}_setSelectionBehavior(){this.selectionHandler=[],this._setDefaultSelected();for(const[e,t]of this.component.querySelectorAll(".br-list .br-item").entries())for(const o of t.querySelectorAll('.br-radio input[type="radio"], .br-checkbox input[type="checkbox"]'))this.selectionHandler.push({element:o,handler:this._handleClickOnCheck.bind(this,e,t)}),o.addEventListener("click",this.selectionHandler[e].handler)}_unsetSelectionBehavior(){this.selectionHandler.forEach(e=>{e.element.removeEventListener("click",e.handler,!1)})}_setFilterBehavior(){const e=this.component.querySelector(".br-list");for(const t of this.component.querySelectorAll('.br-input input[type="text"]'))t.addEventListener("input",t=>{if(!e.hasAttribute("expanded")){const{value:e}=t.currentTarget;this._openSelect(),t.currentTarget.value=e}let o=!0;this._filter(t.currentTarget.value);for(const e of this.optionsList)e.visible&&(o=!1);o&&this._filter(t.currentTarget.value)})}_filter(e){let t=!1;for(const[o,i]of this.component.querySelectorAll(".br-list .br-item").entries())this._removeNotFoundElement(),this.optionsList[o]&&(-1===this.optionsList[o].value.toUpperCase().indexOf(e.toUpperCase())?(i.classList.add("d-none"),this.optionsList[o].visible=!1):(i.classList.remove("d-none"),this.optionsList[o].visible=!0,t=!0));!1===t?this._addNotFoundElement():this._removeNotFoundElement()}_setAttribute(){for(const e of this.component.querySelectorAll(".br-list .br-item"))for(const t of e.querySelectorAll('.br-checkbox input[type="checkbox"]'))t.hasAttribute("checked")&&t.click()}_setSelected(e,t){t.classList.add("selected"),t.setAttribute("aria-selected",!0);for(const e of t.querySelectorAll(".br-radio, .br-checkbox"))for(const t of e.querySelectorAll('input[type="radio"], input[type="checkbox"]'))t.setAttribute("checked","");this.optionsList[e].selected=!0,this._setInput()}_removeSelected(e,t){t.classList.remove("selected"),t.removeAttribute("aria-selected");for(const o of t.querySelectorAll(".br-radio, .br-checkbox")){for(const e of o.querySelectorAll('input[type="radio"], input[type="checkbox"'))e.removeAttribute("checked");this.optionsList[e].selected=!1,this._setInput()}}_setInput(){for(const e of this.component.querySelectorAll('.br-input input[type="text"]'))this.multiple?0===this.selected.length?e.value="":this.mountSelectedValues(e):e.value=this.selected}mountSelectedValues(e){this.amountE=this.amountE>0?this.amountE:0;const t=this.amountE,o=this.selected.toString().replaceAll(",",", "),i=document.createElement("span");i.innerHTML=o,document.querySelector("body").insertAdjacentElement("beforeend",i);const s=this.getMaxCharacterCountBeforeOverflow(e);this.amountE=t,e.title=this.selected.toString().replaceAll(",",", ");const n=this.encontrarPosicaoPorTamanho(this.selected,s-6);e.value=n,i.remove()}getPixelSize(e){const t=document.createElement("span");t.style.visibility="hidden",t.style.position="absolute",t.style.left="-9999px",t.style.top="-9999px",t.style.whiteSpace="nowrap",t.textContent=e,document.body.appendChild(t);const o=t.getBoundingClientRect().width;return document.body.removeChild(t),o}encontrarPosicaoPorTamanho(e,t){let o=0,i="",s=0,n=0;for(const r of e){const l=e.indexOf(r);if(o+=1,r.length>=t&&1===e.length)return`${r.substring(0,t)}... `;if(i.length>=t){i+=`${r}, `,i=`${i.substring(0,t)}...`,s=0===s?1:s;let o=l-s;o=0===s?e.length-1:e.length-s,n=o}else{const e=undefined;i+=`${l>0?`, ${r}`:`${r}`}`,s+=1}}return i=n<=0?`${i}`:`${i} + (${n})`,i}getMaxCharacterCountBeforeOverflow(e){const t=window.getComputedStyle(e),o=parseFloat(t.paddingLeft)+parseFloat(t.paddingRight),i=parseFloat(t.borderLeftWidth)+parseFloat(t.borderRightWidth),s=e.clientWidth-o-i,n=this.getAverageCharacterWidth(e);return Math.floor(s/n)}getAverageCharacterWidth(e){const t=document.createElement("span");t.style.visibility="hidden",t.style.position="absolute",t.style.whiteSpace="nowrap",t.textContent="X",document.body.appendChild(t);const o=t.offsetWidth;return document.body.removeChild(t),o}filterArrayByInputSize(e,t){const o=getMaxCharacterCountBeforeOverflow(t),i=undefined;return e.filter(e=>{const i=e.toString();if(getPixelSize(i)<=t.offsetWidth)return!0;{const e=`${i.substring(0,o-3)}...`;return t.value=e,!1}})}_getNextItem(){const e=this.component.querySelectorAll(".br-list .br-item");let t,o;for(t=0;t<this.optionsList.length;t++)if(this.optionsList[t].focus){for(o=t+1;o<this.optionsList.length&&!this.optionsList[o].visible;o++);break}if(t!==this.optionsList.length)return o<this.optionsList.length?(this.optionsList[t].focus=!1,this.optionsList[o].focus=!0,e[o]):e[t];for(let t=0;t<this.optionsList.length;t++)if(this.optionsList[t].visible)return this.optionsList[t].focus=!0,e[t];return""}_getPreviousItem(){const e=this.component.querySelectorAll(".br-list .br-item");let t,o;for(t=0;t<this.optionsList.length;t++)if(this.optionsList[t].focus){for(o=t-1;o>0&&!this.optionsList[o].visible;o--);break}if(t!==this.optionsList.length)return 0===t?e[t]:(this.optionsList[t].focus=!1,this.optionsList[o].focus=!0,e[o]);for(let t=this.optionsList.length-1;t>=0;t--)if(this.optionsList[t].visible)return this.optionsList[t].focus=!0,e[t];return""}_resetInput(){for(const e of this.component.querySelectorAll('.br-input input[type="text"]'))e.value=""}_resetFocus(){for(const e of this.optionsList)e.focus=!1}_resetVisible(){this._removeNotFoundElement();const e=this.component.querySelectorAll(".br-list .br-item");for(const[t,o]of this.optionsList.entries())o.visible=!0,e[t].classList.remove("d-none")}_openSelect(){const e=this.component.querySelector(".br-input"),t=this.component.querySelector(".br-input .br-button");for(const e of this.component.querySelectorAll(".br-list"))e.setAttribute("expanded","");for(const e of this.component.querySelectorAll(".br-input .br-button i"))e.classList.remove("fa-angle-down"),e.classList.add("fa-angle-up");e.setAttribute("aria-expanded",!0),t.setAttribute("aria-expanded",!0),t.setAttribute("aria-label","Ocultar lista"),this._resetInput()}_closeSelect(){const e=this.component.querySelector(".br-input"),t=this.component.querySelector(".br-input .br-button");for(const e of this.component.querySelectorAll(".br-list"))e.removeAttribute("expanded");for(const e of this.component.querySelectorAll(".br-input .br-button i"))e.classList.remove("fa-angle-up"),e.classList.add("fa-angle-down");e.setAttribute("aria-expanded",!1),t.setAttribute("aria-expanded",!1),t.setAttribute("aria-label","Exibir lista"),this._setInput(),this._resetFocus(),this._resetVisible()}_setSearchIcon(){const e=this.component.querySelector(".br-input"),t=this.component.querySelector("[data-trigger]"),o=document.createElement("i");o.classList.add("fas","fa-search"),o.setAttribute("aria-hidden","true");const i=document.createElement("div");i.classList.add("input-icon"),i.appendChild(o);const s=document.createElement("div");s.classList.add("input-group"),s.appendChild(i),s.appendChild(e.querySelector("input")),e.appendChild(s),e.appendChild(t)}_setAria(){const e=this.component.querySelector(".br-input"),t=this.component.querySelector(".br-list");e.setAttribute("role","combobox"),e.setAttribute("aria-expanded",!1),e.setAttribute("aria-controls",`${t.id}`),t.setAttribute("role","listbox")}}var t=null})(),e();var i={};return o(),i})());
//# sourceMappingURL=select.min.js.map