import { PktElementWithSlot } from '@/base-elements/element-with-slot' import { html, nothing } from 'lit' import { unsafeHTML } from 'lit/directives/unsafe-html.js' import { classMap } from 'lit/directives/class-map.js' import { customElement, property, state } from 'lit/decorators.js' import { uuidish } from 'shared-utils/utils' import specs from 'componentSpecs/input-wrapper.json' import '@/components/icon' import { slotContent } from '@/directives/slot-content' export class PktHelptext extends PktElementWithSlot { @property({ type: String, reflect: true }) forId: string = uuidish() @property({ type: String }) helptext: string = '' @property({ type: String }) helptextDropdown: string = '' @property({ type: String }) helptextDropdownButton: string = specs.props.helptextDropdownButton.default @state() isHelpTextOpen: boolean = false render() { const toggleDropdown = () => { const isOpen = !this.isHelpTextOpen this.isHelpTextOpen = isOpen this.dispatchEvent( new CustomEvent('toggleHelpText', { bubbles: true, detail: { isOpen }, }), ) } const helptextClasses = classMap({ 'pkt-inputwrapper__helptext-container': true, 'pkt-inputwrapper__has-helptext': this.helptext || this.helptextDropdown || this.hasSlotContent(), }) const helptextDropdown = () => { if (this.helptextDropdown) { return html`
${unsafeHTML(this.helptextDropdown)}
` } else { return nothing } } const helptextElement = () => { return html`
${slotContent(this)}
${this.helptext && unsafeHTML(this.helptext)}
${helptextDropdown()}
` } return html`${helptextElement()}` } } try { customElement('pkt-helptext')(PktHelptext) } catch (e) { console.warn('Forsøker å definere , men den er allerede definert') }