{"version":3,"file":"tabs-BwLxe-Kc.js","sources":["../../../src/js/tabs.ts"],"sourcesContent":["/**\n @source: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tab_role\n optimized for typescript\n */\nconst changeTabs = (e: Event): void => {\n const target: Element = e.currentTarget as Element;\n const parent: ParentNode | null = target.parentNode;\n\n if (!parent) {\n return;\n }\n\n const grandparent: ParentNode | null = parent.parentNode;\n\n if (!grandparent) {\n return;\n }\n\n // Remove all current selected tabs\n parent\n .querySelectorAll('[aria-selected=\"true\"]')\n .forEach((tab: Element): void => {\n tab.setAttribute('aria-selected', 'false');\n tab.classList.remove(\n 'bg-tulp-green',\n 'border-tulp-green',\n 'drop-shadow-button',\n );\n tab.classList.add('text-white', 'border-white');\n });\n\n // Set this tab as selected\n target.setAttribute('aria-selected', 'true');\n target.classList.remove('text-white', 'border-white');\n target.classList.add(\n 'bg-tulp-green',\n 'text-primary',\n 'border-tulp-green',\n 'drop-shadow-button',\n );\n\n // Hide all tab panels\n grandparent\n .querySelectorAll('[role=\"tabpanel\"]')\n .forEach((panel: Element) => {\n panel.setAttribute('hidden', 'true');\n panel.classList.remove('grid');\n panel.classList.add('hidden');\n });\n\n // Show the selected panel\n const selectedPanel = grandparent.parentNode?.querySelector(\n `#${target.getAttribute('aria-controls')}`,\n );\n if (!selectedPanel) {\n return;\n }\n selectedPanel.removeAttribute('hidden');\n\n selectedPanel.classList.remove('hidden');\n selectedPanel.classList.add('grid');\n};\n\nexport const tabsHandler = (): void => {\n const tabs: NodeListOf =\n document.querySelectorAll('[role=\"tab\"]');\n const tabList: Element | null = document.querySelector('[role=\"tablist\"]');\n\n if (!tabs || !tabList) {\n return;\n }\n\n // Add a click event handler to each tab\n tabs.forEach((tab: Element): void => {\n tab.addEventListener('click', changeTabs);\n });\n\n // Enable arrow navigation between tabs in the tab list\n let tabFocus: number = 0;\n\n tabList.addEventListener('keydown', (event: Event): void => {\n const keyBoardEvent: KeyboardEvent = event as KeyboardEvent;\n if (\n keyBoardEvent.key === 'ArrowRight' ||\n keyBoardEvent.key === 'ArrowLeft'\n ) {\n tabs[tabFocus].setAttribute('tabindex', '-1');\n // Move right\n if (keyBoardEvent.key === 'ArrowRight') {\n tabFocus++;\n // If we're at the end, go to the start\n if (tabFocus >= tabs.length) {\n tabFocus = 0;\n }\n // Move left\n } else if (keyBoardEvent.key === 'ArrowLeft') {\n tabFocus--;\n // If we're at the start, move to the end\n if (tabFocus < 0) {\n tabFocus = tabs.length - 1;\n }\n }\n\n tabs[tabFocus].setAttribute('tabindex', '0');\n tabs[tabFocus].focus();\n }\n });\n};\n"],"names":["changeTabs","e","_a","target","parent","grandparent","tab","panel","selectedPanel","tabsHandler","tabs","tabList","tabFocus","event","keyBoardEvent"],"mappings":"AAIA,MAAMA,EAAcC,GAAmB,CAAvC,IAAAC,EACE,MAAMC,EAAkBF,EAAE,cACpBG,EAA4BD,EAAO,WAEzC,GAAI,CAACC,EACH,OAGF,MAAMC,EAAiCD,EAAO,WAE9C,GAAI,CAACC,EACH,OAIFD,EACG,iBAAiB,wBAAwB,EACzC,QAASE,GAAuB,CAC3BA,EAAA,aAAa,gBAAiB,OAAO,EACzCA,EAAI,UAAU,OACZ,gBACA,oBACA,oBACF,EACIA,EAAA,UAAU,IAAI,aAAc,cAAc,CAAA,CAC/C,EAGIH,EAAA,aAAa,gBAAiB,MAAM,EACpCA,EAAA,UAAU,OAAO,aAAc,cAAc,EACpDA,EAAO,UAAU,IACf,gBACA,eACA,oBACA,oBACF,EAGAE,EACG,iBAAiB,mBAAmB,EACpC,QAASE,GAAmB,CACrBA,EAAA,aAAa,SAAU,MAAM,EAC7BA,EAAA,UAAU,OAAO,MAAM,EACvBA,EAAA,UAAU,IAAI,QAAQ,CAAA,CAC7B,EAGG,MAAAC,GAAgBN,EAAAG,EAAY,aAAZ,YAAAH,EAAwB,cAC5C,IAAIC,EAAO,aAAa,eAAe,CAAC,IAErCK,IAGLA,EAAc,gBAAgB,QAAQ,EAExBA,EA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