@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
171 lines (162 loc) • 5.35 kB
JavaScript
/**** Libraries ****/
import React, { PureComponent } from 'react';
import { defaultProps } from "./props/defaultProps";
import { propTypes } from "./props/propTypes";
/**** Components ****/
import Label from '@zohodesk/components/lib/Label/Label';
import Textarea from '@zohodesk/components/lib/Textarea/Textarea';
import ValidationMessage from "../ValidationMessage/ValidationMessage";
import { getUniqueId } from '@zohodesk/components/lib/Provider/IdProvider';
import FieldContainer from "../FieldContainer/FieldContainer";
/**** CSS ****/
import style from "../Fields.module.css";
export default class TextareaField extends PureComponent {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleBlur = this.handleBlur.bind(this);
this.handleGetRef = this.handleGetRef.bind(this); // this.handleLabelClick = this.handleLabelClick.bind(this);
this.getNextId = getUniqueId(this);
}
handleChange(value) {
let {
id,
onChange
} = this.props;
onChange && onChange(id, value);
}
handleBlur(value) {
let {
id,
onBlur
} = this.props;
onBlur && onBlur(id, value);
}
handleGetRef(el) {
let {
getRef,
id
} = this.props;
this.textarea = el;
getRef && getRef(el, id);
} // handleLabelClick() {
// let { isFocusOnLabelClick } = this.props;
// if (isFocusOnLabelClick && this.textarea && this.textarea.focus) {
// this.textarea.focus();
// }
// }
render() {
let {
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,
renderRightPlaceholderNode,
rightPlaceholderCustomClass
} = this.props;
const {
LabelProps = {},
TextareaProps = {},
ValidationMessageProps1 = {},
ValidationMessageProps2 = {}
} = customProps;
let uniqueId = htmlId ? htmlId : this.getNextId();
let textAreaContent = /*#__PURE__*/React.createElement(Textarea, {
onChange: this.handleChange,
animated: animated,
size: fieldSize === 'medium' ? textBoxSize : 'xmedium',
variant: textBoxVariant,
isReadOnly: isReadOnly,
isDisabled: isDisabled,
getRef: this.handleGetRef,
maxLength: maxLength,
text: value,
placeHolder: placeHolder,
dataId: `property(${dataId})`,
onFocus: onFocus,
onBlur: this.handleBlur,
borderColor: borderColor,
needEffect: isReadOnly || isDisabled ? false : true,
resize: "vertical" // onKeyDown={onKeyDown}
,
htmlId: uniqueId,
...TextareaProps,
a11y: {
ariaLabelledby: labelName
}
});
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}`] : ''}`
}, !renderRightPlaceholderNode ? textAreaContent : /*#__PURE__*/React.createElement("div", {
className: style.hasChildren
}, textAreaContent, /*#__PURE__*/React.createElement("div", {
className: `${style.rightPlaceholder} ${rightPlaceholderCustomClass}`
}, renderRightPlaceholderNode)), 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; // if (__DOCS__) {
// TextareaField.docs = {
// componentGroup: 'Form Fields',
// folderName: 'General'
// };
// }