import { html, PropertyValues } from 'lit' import { ifDefined } from 'lit/directives/if-defined.js' import { customElement, property, state } from 'lit/decorators.js' import { Ref, createRef, ref } from 'lit/directives/ref.js' import { classMap } from 'lit/directives/class-map.js' import { live } from 'lit/directives/live.js' import { PktInputElement } from '@/base-elements/input-element' import { slotContent } from '@/directives/slot-content' import '@/components/input-wrapper' import '@/components/icon' import { ElementProps } from '@/types/typeUtils' type Props = ElementProps export class PktTextarea extends PktInputElement { inputRef: Ref = createRef() @property({ type: String, reflect: true }) value: string = '' @property({ type: String }) autocomplete: string = 'off' @property({ type: Number }) rows: number | null = null @state() counterCurrent = 0 attributeChangedCallback(name: string, _old: string | null, value: string | null): void { // Only sync the counter here. if (name === 'value' && this.value !== _old) { this.counterCurrent = value ? value.length : 0 } super.attributeChangedCallback(name, _old, value) } updated(changedProperties: PropertyValues) { super.updated(changedProperties) if (changedProperties.has('value')) { this.counterCurrent = this.value?.length || 0 this.valueChanged(this.value, changedProperties.get('value')) } if (changedProperties.has('id')) { !this.name && this.id && (this.name = this.id) } } render() { const inputClasses = classMap({ 'pkt-input': true, [`pkt-input--${this.inputSize}`]: true, 'pkt-input--fullwidth': this.fullwidth, 'pkt-input--counter-error': this.counter && this.counterMaxLength && this.value.length && this.value.length > this.counterMaxLength, }) const labelledBy = this.ariaLabelledby || `${this.id}-input-label` return html`
${slotContent(this, 'helptext')}
` } } try { customElement('pkt-textarea')(PktTextarea) } catch (e) { console.warn('Forsøker å definere , men den er allerede definert') }