{"version":3,"names":["ShowMore","componentDidRender","this","expanded","getHideableElements","forEach","el","removeAttribute","setAccordionHeight","refAccordionDiv","scrollHeight","collapsedHeight","componentDidLoad","setAttribute","isMultipleOfElements","window","addEventListener","render","accessibilityButtonClass","getFirstFocusableHideableElement","h","Host","key","class","ref","onTransitionEnd","_e","onAccordionDivTransitionEnd","fadeBottom","style","maxHeight","refAccessibilityButton1","type","onClick","event","onAccessibilityButtonClick","onFocus","_event","refAccessibilityButton2","display","refAccordionButton","buttonClass","onAccordionButtonClick","toString","showLessText","showMoreText","bold","name","transform","preventDefault","firstFocusableElement","focus","getBoundingClientRect","top","scrollIntoView","height","includes","setTimeout","accordionTop","accordionBottom","Math","max","getVisibleElements","map","bottom","visibleElementsQuantity","Number","split","elementSelector","Array","from","querySelectorAll","querySelector"],"sources":["src/webcomponents/lk-show-more/lk-show-more.tsx"],"sourcesContent":["import { Component, Prop, h, State, Host } from \"@stencil/core\";\n\n\n@Component({\n tag: \"lk-show-more\"\n})\n\nexport class ShowMore {\n\n @Prop({ reflect: true }) showMoreText: string = \"Se mer\";\n @Prop({ reflect: true }) showLessText: string = \"Se mindre\";\n @Prop() buttonClass: string = \"button--secondary\";\n @Prop() fadeBottom: boolean = true;\n @Prop() collapsedHeight: string = \"10em\";\n @State() expanded = false;\n \n refAccordionDiv: HTMLDivElement;\n refAccordionButton: HTMLButtonElement;\n refAccessibilityButton1: HTMLButtonElement;\n refAccessibilityButton2: HTMLButtonElement;\n\n componentDidRender() {\n if (this.expanded) {\n this.getHideableElements().forEach((el: HTMLElement) => el.removeAttribute(\"hidden\"));\n this.setAccordionHeight(this.refAccordionDiv.scrollHeight);\n } else {\n this.setAccordionHeight(this.collapsedHeight);\n }\n }\n\n componentDidLoad() {\n if (this.expanded) {\n this.setAccordionHeight(\"none\");\n } else {\n this.getHideableElements().forEach((el: HTMLElement) => el.setAttribute(\"hidden\", \"true\"));\n }\n if (this.isMultipleOfElements(this.collapsedHeight)) {\n window.addEventListener(\"resize\", () => {\n if (!this.expanded) {\n this.setAccordionHeight(this.collapsedHeight);\n }\n });\n }\n }\n\n render() {\n\n let accessibilityButtonClass = `${this.expanded && this.isMultipleOfElements(this.collapsedHeight) && this.getFirstFocusableHideableElement()\n ? \"visually-hidden\" : \"no-display\"}`;\n\n return (\n \n this.refAccordionDiv = el}\n class=\"show-more__accordion\"\n onTransitionEnd={_e => this.onAccordionDivTransitionEnd()}\n >\n\n \n\n {this.fadeBottom ?\n : null\n }\n\n \n\n
\n this.refAccessibilityButton1 = el}\n class={accessibilityButtonClass}\n type=\"button\"\n onClick={event => { this.onAccessibilityButtonClick(event) }}\n onFocus={_event => { this.refAccessibilityButton2.style.display = \"none\" }}\n aria-label=\"Gå til nytt innhold\"\n />\n\n this.refAccordionButton = el}\n class={`button ${this.buttonClass}`}\n type=\"button\"\n onClick={event => { this.onAccordionButtonClick(event) }}\n aria-expanded={this.expanded.toString()}\n >\n \n {this.expanded ? this.showLessText : this.showMoreText}\n \n\n \n \n\n this.refAccessibilityButton2 = el}\n class={accessibilityButtonClass}\n type=\"button\"\n onClick={event => { this.onAccessibilityButtonClick(event) }}\n onFocus={_event => { this.refAccessibilityButton1.style.display = \"none\" }}\n aria-label=\"Gå til nytt innhold\"\n />\n
\n
\n )\n\n }\n\n onAccordionButtonClick(event) {\n event.preventDefault();\n this.expanded = !this.expanded;\n }\n\n onAccessibilityButtonClick(event) {\n event.preventDefault();\n if (this.expanded) {\n let firstFocusableElement = this.getFirstFocusableHideableElement();\n if (firstFocusableElement)\n firstFocusableElement.focus();\n }\n }\n\n onAccordionDivTransitionEnd() {\n if (this.expanded) {\n this.refAccordionDiv.style.maxHeight = \"none\";\n }\n if (!this.expanded) {\n this.getHideableElements().forEach((el: HTMLElement) => el.setAttribute(\"hidden\", \"true\"));\n if (this.refAccordionButton.getBoundingClientRect().top < 0)\n this.refAccordionButton.scrollIntoView();\n }\n }\n\n isMultipleOfElements(height) {\n return height.toString().includes(\" \");\n }\n\n setAccordionHeight(height) {\n if (this.refAccordionDiv.style.maxHeight == \"none\")\n this.refAccordionDiv.style.maxHeight = this.refAccordionDiv.scrollHeight + \"px\";\n\n setTimeout(() => {\n if (typeof height === \"number\") {\n this.refAccordionDiv.style.maxHeight = height + \"px\";\n } else if (this.isMultipleOfElements(height)) {\n const accordionTop = this.refAccordionDiv.getBoundingClientRect().top;\n const accordionBottom = Math.max(...this.getVisibleElements().map(el => el.getBoundingClientRect().bottom));\n this.refAccordionDiv.style.maxHeight = accordionBottom - accordionTop + \"px\";\n } else {\n this.refAccordionDiv.style.maxHeight = height;\n }\n }, 1)\n }\n\n getVisibleElements(): Array {\n if (this.isMultipleOfElements(this.collapsedHeight)) {\n const visibleElementsQuantity = Number(this.collapsedHeight.split(\" \")[0]);\n const elementSelector = this.collapsedHeight.split(\" \")[1];\n return Array.from(this.refAccordionDiv.querySelectorAll(`${elementSelector}:nth-child(-n+${visibleElementsQuantity})`));\n }\n return [];\n }\n\n getHideableElements(): Array {\n if (this.isMultipleOfElements(this.collapsedHeight)) {\n const visibleElementsQuantity = Number(this.collapsedHeight.split(\" \")[0]);\n const elementSelector = this.collapsedHeight.split(\" \")[1];\n return Array.from(this.refAccordionDiv.querySelectorAll(`${elementSelector}:nth-child(n+${visibleElementsQuantity + 1})`));\n }\n return [];\n }\n\n getFirstFocusableHideableElement(): HTMLElement {\n if (this.isMultipleOfElements(this.collapsedHeight)) {\n const visibleElementsQuantity = Number(this.collapsedHeight.split(\" \")[0]);\n const elementSelector = this.collapsedHeight.split(\" \")[1];\n return this.refAccordionDiv.querySelector(\n `${elementSelector}:nth-child(n+${visibleElementsQuantity + 1}) \n a[href]:not([tabindex='-1']), \n button:not([disabled]):not([tabindex='-1']), \n [tabindex]:not([tabindex='-1'])`\n );\n }\n return null;\n }\n\n}\n\n"],"mappings":"wDAOaA,EAAQ,M,2CAE6B,S,kBACA,Y,iBAClB,oB,gBACA,K,qBACI,O,cACd,K,CAOpB,kBAAAC,GACE,GAAIC,KAAKC,SA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