/* * Copyright (c) 2020 - present Cloudogu GmbH * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ import React, { ChangeEvent, FC, FocusEvent, KeyboardEvent } from "react"; import LabelWithHelpIcon from "./LabelWithHelpIcon"; import useAutofocus from "./useAutofocus"; import classNames from "classnames"; import { createFormFieldWrapper, FieldProps, FieldType, isLegacy, isUsingRef } from "./FormFieldTypes"; import { createA11yId } from "../createA11yId"; type BaseProps = { name?: string; label?: string; placeholder?: string; value?: string; autofocus?: boolean; helpText?: string; disabled?: boolean; onSubmit?: () => void; onCancel?: () => void; validationError?: boolean; errorMessage?: string | string[]; informationMessage?: string; defaultValue?: string; readOnly?: boolean; }; /** * @deprecated */ const InnerTextarea: FC> = ({ placeholder, value, autofocus, name, label, helpText, disabled, onSubmit, onCancel, errorMessage, validationError, informationMessage, defaultValue, readOnly, ...props }) => { const ref = useAutofocus(autofocus, props.innerRef); const handleChange = (event: ChangeEvent) => { if (props.onChange) { if (isUsingRef(props)) { props.onChange(event); } else if (isLegacy(props)) { props.onChange(event.target.value, name); } } }; const handleBlur = (event: FocusEvent) => { if (props.onBlur) { if (isUsingRef(props)) { props.onBlur(event); } else if (isLegacy(props)) { props.onBlur(event.target.value, name); } } }; const onKeyDown = (event: KeyboardEvent) => { if (onCancel && event.key === "Escape") { onCancel(); return; } if (onSubmit && event.key === "Enter" && (event.ctrlKey || event.metaKey)) { onSubmit(); } }; const errorView = validationError ? "is-danger" : ""; let helper; if (validationError) { helper =

{errorMessage}

; } else if (informationMessage) { helper =

{informationMessage}

; } const id = createA11yId("textarea"); const helpId = createA11yId("textarea"); return (