|
| 1 | +import { Textarea as NavTextarea } from '@navikt/ds-react'; |
| 2 | +import { TEXTS } from '@navikt/skjemadigitalisering-shared-domain'; |
| 3 | +import BaseComponent from '../../base/BaseComponent'; |
| 4 | +import textAreaBuilder from './TextArea.builder'; |
| 5 | +import textAreaForm from './TextArea.form'; |
| 6 | + |
| 7 | +const { navTextarea: TRANSLATIONS } = TEXTS.grensesnitt; |
| 8 | + |
| 9 | +class TextArea extends BaseComponent { |
| 10 | + static schema() { |
| 11 | + return BaseComponent.schema({ |
| 12 | + label: 'Tekstområde', |
| 13 | + type: 'textarea', |
| 14 | + key: 'textarea', |
| 15 | + fieldSize: 'input--xxl', |
| 16 | + input: true, |
| 17 | + dataGridLabel: true, |
| 18 | + clearOnHide: true, |
| 19 | + autoExpand: true, |
| 20 | + editor: '', |
| 21 | + }); |
| 22 | + } |
| 23 | + |
| 24 | + static editForm() { |
| 25 | + return textAreaForm(); |
| 26 | + } |
| 27 | + |
| 28 | + static get builderInfo() { |
| 29 | + return textAreaBuilder(); |
| 30 | + } |
| 31 | + |
| 32 | + getMinRows() { |
| 33 | + return this.component?.rows; |
| 34 | + } |
| 35 | + |
| 36 | + getMaxRows() { |
| 37 | + return !this.component?.autoExpand ? this.getMinRows() : undefined; |
| 38 | + } |
| 39 | + |
| 40 | + getMaxLength() { |
| 41 | + const maxLength = this.component?.validate?.maxLength; |
| 42 | + return maxLength; |
| 43 | + } |
| 44 | + |
| 45 | + renderReact(element) { |
| 46 | + element.render( |
| 47 | + <> |
| 48 | + <NavTextarea |
| 49 | + id={this.getId()} |
| 50 | + defaultValue={this.getValue()} |
| 51 | + maxLength={this.getMaxLength()} |
| 52 | + minRows={this.getMinRows()} |
| 53 | + maxRows={this.getMaxRows()} |
| 54 | + ref={(ref) => this.setReactInstance(ref)} |
| 55 | + onChange={(event) => this.updateValue(event.currentTarget.value, { modified: true })} |
| 56 | + label={this.getLabel()} |
| 57 | + hideLabel={this.getHideLabel()} |
| 58 | + description={this.getDescription()} |
| 59 | + className={this.getClassName()} |
| 60 | + autoComplete={this.getAutoComplete()} |
| 61 | + readOnly={this.getReadOnly()} |
| 62 | + spellCheck={this.getSpellCheck()} |
| 63 | + error={this.getError()} |
| 64 | + i18n={{ |
| 65 | + counterLeft: this.t(TRANSLATIONS.counterLeft), |
| 66 | + counterTooMuch: this.t(TRANSLATIONS.counterTooMuch), |
| 67 | + }} |
| 68 | + /> |
| 69 | + </>, |
| 70 | + ); |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +export default TextArea; |
0 commit comments