design-react-kit
Version:
Componenti React per Bootstrap 5
65 lines • 2.92 kB
JavaScript
import React from 'react';
import { InputContainer } from './InputContainer';
import { getClasses, getFormControlClass, getValidationTextControlClass, useFocus } from './utils';
export const TextArea = ({ id, className, cssModule, innerRef, label, validationText, infoText, placeholder, normalized, value, wrapperClassName: originalWrapperClass, valid, testId, ...attributes }) => {
const { toggleFocusLabel, toggleBlurLabel, isFocused } = useFocus({
onFocus: attributes.onFocus,
onBlur: attributes.onBlur
});
const validationTextControlClass = getValidationTextControlClass({ valid }, cssModule);
const extraAttributes = {};
//Chiamo questa funzione per impostare classNames a 'form-control'
const formControlClass = getFormControlClass({}, cssModule);
// associate the input field with the help text
const infoId = id ? `${id}Description` : undefined;
if (id) {
extraAttributes['aria-describedby'] = infoId;
}
// Styling
const { activeClass, extraLabelClass, validationTextClass, inputClasses, wrapperClass } = getClasses(className, 'textarea', {
valid,
placeholder,
value,
label,
validationText,
normalized: Boolean(normalized),
formControlClass,
validationTextControlClass,
isFocused,
originalWrapperClass
}, cssModule);
// set of attributes always shared by the Input components
const sharedAttributes = {
id,
onFocus: toggleFocusLabel,
onBlur: toggleBlurLabel,
value,
ref: innerRef
};
// set of attributes always shared by the wrapper component
const containerProps = {
id,
infoId,
infoText,
activeClass,
extraLabelClass,
label,
validationTextClass,
validationText,
wrapperClass
};
if (placeholder) {
return (React.createElement(InputContainer, { ...containerProps },
React.createElement("textarea", { ...attributes, ...extraAttributes, ...sharedAttributes, className: inputClasses, placeholder: placeholder, "data-testid": testId })));
}
if (normalized) {
return (React.createElement(InputContainer, { ...containerProps },
React.createElement("textarea", { ...attributes, ...extraAttributes, ...sharedAttributes, className: inputClasses, readOnly: true, "data-testid": testId })));
}
if (label || validationText) {
return (React.createElement(InputContainer, { ...containerProps },
React.createElement("textarea", { ...attributes, ...extraAttributes, ...sharedAttributes, className: inputClasses, "data-testid": testId })));
}
return (React.createElement("textarea", { ...attributes, ...extraAttributes, className: inputClasses, ...sharedAttributes, ref: innerRef, "data-testid": testId }));
};
//# sourceMappingURL=TextArea.js.map