@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
140 lines (132 loc) • 4.24 kB
JavaScript
/**** Libraries ****/
import React, { memo } from 'react';
import { defaultProps } from "./props/defaultProps";
import { propTypes } from "./props/propTypes";
/**** Components ****/
import Label from '@zohodesk/components/es/v1/Label/Label';
import Textarea from '@zohodesk/components/es/v1/Textarea/Textarea';
import ValidationMessage from "../ValidationMessage/ValidationMessage";
import { useUniqueId } from '@zohodesk/components/es/Provider/IdProvider';
import FieldContainer from "../FieldContainer/FieldContainer";
/**** CSS ****/
import style from "../../../../form/fields/Fields.module.css";
const TextareaField = props => {
const {
labelName,
id,
isMandatory,
textBoxSize,
animated,
textBoxVariant,
isReadOnly,
validationMessage,
validationPalette,
maxLength,
value,
errorType,
isDisabled,
title,
placeHolder,
dataId,
dataSelectorId,
validationRuleMessage,
validationRulePalette,
// onKeyDown,
onFocus,
infoText,
borderColor,
fieldSize,
labelPalette,
labelCustomClass,
htmlId,
lockedInfoText,
isLocked,
customProps,
renderLabelProps,
onChange,
onBlur,
getRef
} = props;
const {
LabelProps = {},
TextareaProps = {},
ValidationMessageProps1 = {},
ValidationMessageProps2 = {}
} = customProps;
const getNextId = useUniqueId();
let uniqueId = htmlId ? htmlId : getNextId();
const handleChange = value => {
onChange && onChange(id, value);
};
const handleBlur = value => {
onBlur && onBlur(id, value);
};
const handleGetRef = el => {
getRef && getRef(el, id);
};
return /*#__PURE__*/React.createElement("div", {
className: `${style.container} ${isDisabled ? style.disabled : isReadOnly ? style.readonly : ''}`,
"data-title": isDisabled ? title : null,
"data-selector-id": dataSelectorId
}, labelName && /*#__PURE__*/React.createElement(FieldContainer, {
infoText: infoText,
isLocked: isLocked,
lockedInfoText: lockedInfoText,
renderProps: renderLabelProps
}, /*#__PURE__*/React.createElement(Label, {
text: labelName,
id: id,
size: fieldSize === 'small' ? 'small' : 'medium',
palette: isMandatory ? 'mandatory' : isDisabled ? 'primary' : labelPalette,
customClass: `${style.fieldLabel} ${labelCustomClass} ${isMandatory ? style.labelMandatory : ''}`,
htmlFor: uniqueId,
dataId: isDisabled ? `${dataId}_label_disabled` : isMandatory ? `${dataId}_label_mandatory` : `${dataId}_label`,
...LabelProps
})), /*#__PURE__*/React.createElement("div", {
className: `${style.fieldContainer} ${labelName ? style[`fieldMargin_${fieldSize}`] : ''}`
}, /*#__PURE__*/React.createElement(Textarea, {
onChange: handleChange,
animated: animated,
size: fieldSize === 'medium' ? textBoxSize : 'xmedium',
variant: textBoxVariant,
isReadOnly: isReadOnly,
isDisabled: isDisabled,
getRef: handleGetRef,
maxLength: maxLength,
text: value,
placeHolder: placeHolder,
dataId: `property(${dataId})`,
onFocus: onFocus,
onBlur: handleBlur,
borderColor: borderColor,
needEffect: isReadOnly || isDisabled ? false : true,
resize: "vertical" // onKeyDown={onKeyDown}
,
htmlId: uniqueId,
...TextareaProps,
a11y: {
ariaLabelledby: labelName
}
}), validationMessage && /*#__PURE__*/React.createElement(ValidationMessage, {
text: validationMessage,
palette: validationPalette,
type: errorType,
htmlFor: uniqueId,
dataId: `${dataId}_ValidationMessage`,
...ValidationMessageProps1
}), validationRuleMessage && /*#__PURE__*/React.createElement(ValidationMessage, {
text: validationRuleMessage,
palette: validationRulePalette,
type: errorType,
htmlFor: uniqueId,
dataId: `${dataId}_ValidationRuleMessage`,
...ValidationMessageProps2
})));
};
TextareaField.propTypes = propTypes;
TextareaField.defaultProps = defaultProps;
const MemoizedTextareaField = /*#__PURE__*/memo(TextareaField);
MemoizedTextareaField.propTypes = propTypes;
MemoizedTextareaField.defaultProps = defaultProps;
MemoizedTextareaField.displayName = 'TextareaField';
export default TextareaField;