@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
193 lines (182 loc) • 5.82 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 TextBoxIcon from '@zohodesk/components/es/TextBoxIcon/TextBoxIcon';
import ValidationMessage from "../ValidationMessage/ValidationMessage";
import { getUniqueId } from '@zohodesk/components/es/Provider/IdProvider';
import FieldContainer from "../FieldContainer/FieldContainer";
/**** CSS ****/
import style from "../Fields.module.css";
export default class CurrencyField extends PureComponent {
constructor(props) {
super(props);
this.state = {
isActive: false
};
this.handleChange = this.handleChange.bind(this);
this.handleGetRef = this.handleGetRef.bind(this);
this.getNextId = getUniqueId(this);
this.onFocus = this.onFocus.bind(this);
this.onBlur = this.onBlur.bind(this);
}
handleChange(value) {
let {
id,
onChange
} = this.props;
onChange && onChange(id, value);
}
handleGetRef(el) {
let {
getRef,
id
} = this.props;
this.textBox = el;
getRef && getRef(el, id);
}
onFocus() {
let {
onFocus
} = this.props;
this.setState({
isActive: true
});
onFocus && onFocus();
}
onBlur() {
let {
onBlur
} = this.props;
this.setState({
isActive: false
});
onBlur && onBlur();
}
render() {
let {
labelName,
id,
textBoxSize,
textBoxVariant,
textBoxType,
isMandatory,
validationMessage,
validationPalette,
maxLength,
isReadOnly,
value,
errorType,
isDisabled,
title,
dataId,
validationRuleMessage,
validationRulePalette,
onKeyDown,
placeHolder,
infoText,
borderColor,
fieldSize,
labelPalette,
labelCustomClass,
htmlId,
dataSelectorId,
lockedInfoText,
isLocked,
needReadOnlyStyle,
isClickable,
userCurrencyType,
customProps,
formatCurrency,
renderLabelProps
} = this.props;
const {
LabelProps = {},
TextBoxIconProps = {},
ValidationMessageProps1 = {},
ValidationMessageProps2 = {}
} = customProps;
let {
isActive
} = this.state;
let formatValue = value;
if (!isActive) {
formatValue = formatCurrency(value, userCurrencyType);
} else {
formatValue = value;
}
let uniqueId = htmlId ? htmlId : this.getNextId();
const isFocusable = !needReadOnlyStyle || !isReadOnly && needReadOnlyStyle;
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, _extends({
text: labelName,
isRequired: isMandatory,
isDisabled: isDisabled,
isReadOnly: isReadOnly,
palette: labelPalette,
customClass: {
label: labelCustomClass
},
size: fieldSize === 'small' ? 'small' : 'medium',
htmlFor: uniqueId,
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(TextBoxIcon, _extends({
htmlId: uniqueId,
id: id,
type: textBoxType,
variant: textBoxVariant,
size: fieldSize === 'medium' ? textBoxSize : 'xsmall',
maxLength: maxLength,
isReadOnly: isReadOnly,
inputRef: this.handleGetRef,
value: formatValue,
onChange: this.handleChange,
dataId: dataId,
onBlur: this.onBlur,
onFocus: isFocusable && this.onFocus,
onKeyDown: onKeyDown,
placeHolder: placeHolder,
borderColor: borderColor,
isDisabled: isDisabled,
needEffect: isReadOnly || isDisabled ? false : true,
isClickable: isClickable,
needReadOnlyStyle: needReadOnlyStyle,
a11y: {
ariaLabelledby: labelName
}
}, TextBoxIconProps)), validationMessage && /*#__PURE__*/React.createElement(ValidationMessage, _extends({
text: validationMessage,
palette: validationPalette,
type: errorType,
dataId: `${dataId}_ValidationMessage`,
htmlFor: uniqueId
}, ValidationMessageProps1)), validationRuleMessage && /*#__PURE__*/React.createElement(ValidationMessage, _extends({
text: validationRuleMessage,
palette: validationRulePalette,
type: errorType,
htmlFor: uniqueId,
dataId: `${dataId}_ValidationRuleMessage`
}, ValidationMessageProps2))));
}
}
CurrencyField.propTypes = propTypes;
CurrencyField.defaultProps = defaultProps; // if (__DOCS__) {
// CurrencyField.docs = {
// componentGroup: 'Form Fields',
// folderName: 'General'
// };
// }