@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
183 lines (173 loc) • 5.8 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
/**** Libraries ****/
import React, { PureComponent } from 'react';
import { defaultProps } from "./props/defaultProps";
import { propTypes } from "./props/propTypes";
/**** Components ****/
import Label from '@zohodesk/components/es/v1/Label/Label';
import ValidationMessage from "../ValidationMessage/ValidationMessage";
import TextEditorWrapper from "../TextEditorWrapper/TextEditorWrapper";
import FieldContainer from "../FieldContainer/FieldContainer";
/** Css */
import style from "../Fields.module.css";
export default class TextEditorField extends PureComponent {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleGetRef = this.handleGetRef.bind(this);
this.handleLabelClick = this.handleLabelClick.bind(this);
this.renderEnd = this.renderEnd.bind(this);
}
handleChange(value) {
let {
id,
onChange
} = this.props;
onChange && onChange(id, value);
}
handleGetRef(el) {
let {
getRef,
id
} = this.props;
this.textEditor = el;
getRef && getRef(el, id);
}
handleLabelClick() {
let {
isFocusOnLabelClick,
isDisabled,
isReadOnly
} = this.props;
if (isFocusOnLabelClick && !isDisabled && !isReadOnly && this.textEditor && this.textEditor.focus) {
this.textEditor.focus();
}
}
renderEnd() {
let {
children
} = this.props;
return children ? children : null;
}
render() {
let {
labelName,
id,
isMandatory,
value,
validationMessage,
validationPalette,
isReadOnly,
onAttachmentUpload,
needEditor,
dataId,
dataSelectorId,
isDisabled,
fieldSize,
textBoxSize,
textBoxVariant,
labelPalette,
labelCustomClass,
infoText,
isLocked,
lockedInfoText,
errorType,
EDITORURL,
editorMode,
isCustomScroll,
initCallback,
loadingComponent,
handleAlertMessage,
editorCallback,
editorBlurCallback,
editorOptions,
onFocus,
isEditorDefaultOpen,
changeEditorContent,
shouldEditorUpdateContent,
setInlineAttachmentInProgress,
handleEditorDropUpload,
ImgLazyLoad,
needInlineAttachment,
i18nKeys,
className,
ePhiData,
customProps
} = this.props;
const {
LabelProps = {},
TextEditorWrapperProps = {},
ValidationMessageProps = {}
} = customProps;
return /*#__PURE__*/React.createElement("div", {
className: `${style.container} ${isDisabled ? style.disabled : isReadOnly ? style.readonly : ''} ${className || ''}`,
"data-selector-id": dataSelectorId
}, labelName && /*#__PURE__*/React.createElement(FieldContainer, {
infoText: infoText,
isLocked: isLocked,
lockedInfoText: lockedInfoText,
ePhiData: ePhiData,
dataId: dataId,
renderProps: {
end: this.renderEnd
}
}, /*#__PURE__*/React.createElement(Label, _extends({
text: labelName,
size: fieldSize === 'small' ? 'small' : 'medium',
htmlFor: !isReadOnly && !isDisabled ? id : undefined,
isRequired: isMandatory,
isDisabled: isDisabled,
isReadOnly: isReadOnly,
palette: labelPalette,
onClick: this.handleLabelClick,
customClass: {
label: labelCustomClass
},
customId: isDisabled ? `${dataId}_label_disabled` : isMandatory ? `${dataId}_label_mandatory` : `${dataId}_label`,
testId: 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(TextEditorWrapper, _extends({
needEditor: needEditor,
onChange: this.handleChange,
id: id,
value: value,
isReadOnly: isReadOnly,
getRef: this.handleGetRef,
onAttachmentUpload: onAttachmentUpload,
dataId: dataId,
isDisabled: isDisabled,
textBoxSize: fieldSize === 'medium' ? textBoxSize : 'xsmall',
textBoxVariant: textBoxVariant,
EDITORURL: EDITORURL,
editorMode: editorMode,
isCustomScroll: isCustomScroll,
initCallback: initCallback,
loadingComponent: loadingComponent,
handleAlertMessage: handleAlertMessage,
editorCallback: editorCallback,
i18nKeys: i18nKeys,
ImgLazyLoad: ImgLazyLoad,
editorOptions: editorOptions,
editorBlurCallback: editorBlurCallback,
onFocus: onFocus,
isEditorDefaultOpen: isEditorDefaultOpen,
changeEditorContent: changeEditorContent,
shouldEditorUpdateContent: shouldEditorUpdateContent,
setInlineAttachmentInProgress: setInlineAttachmentInProgress,
handleEditorDropUpload: handleEditorDropUpload,
needInlineAttachment: needInlineAttachment
}, TextEditorWrapperProps))), validationMessage && /*#__PURE__*/React.createElement(ValidationMessage, _extends({
text: validationMessage,
palette: validationPalette,
type: errorType,
dataId: `${dataId}_ValidationMessage`
}, ValidationMessageProps)));
}
}
TextEditorField.propTypes = propTypes;
TextEditorField.defaultProps = defaultProps; // if (__DOCS__) {
// TextEditorField.docs = {
// componentGroup: 'Fields'
// };
// }