UNPKG

@zohodesk/dot

Version:

In this Library, we Provide Some Basic Components to Build Your Application

144 lines (137 loc) 4.36 kB
/**** 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 TextBoxIcon from '@zohodesk/components/es/v1/TextBoxIcon/TextBoxIcon'; 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 TextBoxField = props => { const { labelName, id, textBoxSize, textBoxVariant, textBoxType, isMandatory, validationMessage, validationPalette, maxLength, isReadOnly, value, errorType, isDisabled, title, onBlur, dataId, dataSelectorId, validationRuleMessage, validationRulePalette, onKeyDown, placeHolder, infoText, borderColor, fieldSize, labelPalette, labelCustomClass, htmlId, lockedInfoText, isLocked, needReadOnlyStyle, isClickable, onFocus, ePhiData, children, customProps, renderLabelProps, onChange, getRef } = props; const { LabelProps = {}, TextBoxIconProps = {}, ValidationMessageProps1 = {}, ValidationMessageProps2 = {} } = customProps; const getNextId = useUniqueId(); let uniqueId = htmlId ? htmlId : getNextId(); const handleChange = value => { onChange && onChange(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, ePhiData: ePhiData, dataId: dataId, renderProps: renderLabelProps }, /*#__PURE__*/React.createElement(Label, { text: labelName, 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, id: labelName })), /*#__PURE__*/React.createElement("div", { className: `${style.fieldContainer} ${labelName ? style[`fieldMargin_${fieldSize}`] : ''}` }, /*#__PURE__*/React.createElement(TextBoxIcon, { htmlId: uniqueId, id: id, type: textBoxType, variant: textBoxVariant, size: fieldSize === 'medium' ? textBoxSize : 'xsmall', maxLength: maxLength, isReadOnly: isReadOnly, inputRef: handleGetRef, value: value, onChange: handleChange, dataId: dataId, onBlur: onBlur, onKeyDown: onKeyDown, placeHolder: placeHolder, borderColor: borderColor, onFocus: onFocus, isDisabled: isDisabled, needEffect: isReadOnly || isDisabled ? false : true, isClickable: isClickable, needReadOnlyStyle: needReadOnlyStyle, ...TextBoxIconProps, a11y: { ariaLabelledby: labelName } }, children ? children : null), validationMessage && /*#__PURE__*/React.createElement(ValidationMessage, { text: validationMessage, palette: validationPalette, type: errorType, dataId: `${dataId}_ValidationMessage`, htmlFor: uniqueId, ...ValidationMessageProps1 }), validationRuleMessage && /*#__PURE__*/React.createElement(ValidationMessage, { text: validationRuleMessage, palette: validationRulePalette, type: errorType, htmlFor: uniqueId, dataId: `${dataId}_ValidationRuleMessage`, ...ValidationMessageProps2 }))); }; TextBoxField.propTypes = propTypes; TextBoxField.defaultProps = defaultProps; const MemoizedTextBoxField = /*#__PURE__*/memo(TextBoxField); MemoizedTextBoxField.propTypes = propTypes; MemoizedTextBoxField.defaultProps = defaultProps; MemoizedTextBoxField.displayName = 'TextBoxField'; export default TextBoxField;