@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
219 lines (184 loc) • 12.8 kB
JavaScript
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _defaultProps = require("./props/defaultProps");
var _propTypes = require("./props/propTypes");
var _Label = _interopRequireDefault(require("@zohodesk/components/lib/Label/Label"));
var _TextBoxIcon = _interopRequireDefault(require("@zohodesk/components/lib/TextBoxIcon/TextBoxIcon"));
var _ValidationMessage = _interopRequireDefault(require("../ValidationMessage/ValidationMessage"));
var _IdProvider = require("@zohodesk/components/lib/Provider/IdProvider");
var _FieldContainer = _interopRequireDefault(require("../FieldContainer/FieldContainer"));
var _FieldsModule = _interopRequireDefault(require("../Fields.module.css"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var TextBoxField = /*#__PURE__*/function (_PureComponent) {
_inherits(TextBoxField, _PureComponent);
var _super = _createSuper(TextBoxField);
function TextBoxField(props) {
var _this;
_classCallCheck(this, TextBoxField);
_this = _super.call(this, props);
_this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this));
_this.handleGetRef = _this.handleGetRef.bind(_assertThisInitialized(_this)); // this.handleLabelClick = this.handleLabelClick.bind(this);
_this.getNextId = (0, _IdProvider.getUniqueId)(_assertThisInitialized(_this));
return _this;
}
_createClass(TextBoxField, [{
key: "handleChange",
value: function handleChange(value) {
var _this$props = this.props,
id = _this$props.id,
onChange = _this$props.onChange;
onChange && onChange(id, value);
}
}, {
key: "handleGetRef",
value: function handleGetRef(el) {
var _this$props2 = this.props,
getRef = _this$props2.getRef,
id = _this$props2.id;
this.textBox = el;
getRef && getRef(el, id);
} // handleLabelClick() {
// // let { isFocusOnLabelClick } = this.props;
// // if (isFocusOnLabelClick && this.textBox && this.textBox.focus) {
// // this.textBox.focus();
// // }
// }
}, {
key: "render",
value: function render() {
var _this$props3 = this.props,
labelName = _this$props3.labelName,
id = _this$props3.id,
textBoxSize = _this$props3.textBoxSize,
textBoxVariant = _this$props3.textBoxVariant,
textBoxType = _this$props3.textBoxType,
isMandatory = _this$props3.isMandatory,
validationMessage = _this$props3.validationMessage,
validationPalette = _this$props3.validationPalette,
maxLength = _this$props3.maxLength,
isReadOnly = _this$props3.isReadOnly,
value = _this$props3.value,
errorType = _this$props3.errorType,
isDisabled = _this$props3.isDisabled,
title = _this$props3.title,
onBlur = _this$props3.onBlur,
dataId = _this$props3.dataId,
dataSelectorId = _this$props3.dataSelectorId,
validationRuleMessage = _this$props3.validationRuleMessage,
validationRulePalette = _this$props3.validationRulePalette,
onKeyDown = _this$props3.onKeyDown,
placeHolder = _this$props3.placeHolder,
infoText = _this$props3.infoText,
borderColor = _this$props3.borderColor,
fieldSize = _this$props3.fieldSize,
labelPalette = _this$props3.labelPalette,
labelCustomClass = _this$props3.labelCustomClass,
htmlId = _this$props3.htmlId,
lockedInfoText = _this$props3.lockedInfoText,
isLocked = _this$props3.isLocked,
needReadOnlyStyle = _this$props3.needReadOnlyStyle,
isClickable = _this$props3.isClickable,
onFocus = _this$props3.onFocus,
ePhiData = _this$props3.ePhiData,
children = _this$props3.children,
customProps = _this$props3.customProps,
renderLabelProps = _this$props3.renderLabelProps;
var _customProps$LabelPro = customProps.LabelProps,
LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro,
_customProps$TextBoxI = customProps.TextBoxIconProps,
TextBoxIconProps = _customProps$TextBoxI === void 0 ? {} : _customProps$TextBoxI,
_customProps$Validati = customProps.ValidationMessageProps1,
ValidationMessageProps1 = _customProps$Validati === void 0 ? {} : _customProps$Validati,
_customProps$Validati2 = customProps.ValidationMessageProps2,
ValidationMessageProps2 = _customProps$Validati2 === void 0 ? {} : _customProps$Validati2;
var uniqueId = htmlId ? htmlId : this.getNextId();
return /*#__PURE__*/_react["default"].createElement("div", {
className: "".concat(_FieldsModule["default"].container, " ").concat(isDisabled ? _FieldsModule["default"].disabled : isReadOnly ? _FieldsModule["default"].readonly : ''),
"data-title": isDisabled ? title : null,
"data-selector-id": dataSelectorId
}, labelName && /*#__PURE__*/_react["default"].createElement(_FieldContainer["default"], {
infoText: infoText,
isLocked: isLocked,
lockedInfoText: lockedInfoText,
ePhiData: ePhiData,
dataId: dataId,
renderProps: renderLabelProps
}, /*#__PURE__*/_react["default"].createElement(_Label["default"], _extends({
text: labelName,
size: fieldSize === 'small' ? 'small' : 'medium',
palette: isMandatory ? 'mandatory' : isDisabled ? 'primary' : labelPalette,
customClass: "".concat(_FieldsModule["default"].fieldLabel, " ").concat(labelCustomClass, " ").concat(isMandatory ? _FieldsModule["default"].labelMandatory : ''),
htmlFor: uniqueId,
dataId: isDisabled ? "".concat(dataId, "_label_disabled") : isMandatory ? "".concat(dataId, "_label_mandatory") : "".concat(dataId, "_label")
}, LabelProps, {
id: labelName
}))), /*#__PURE__*/_react["default"].createElement("div", {
className: "".concat(_FieldsModule["default"].fieldContainer, " ").concat(labelName ? _FieldsModule["default"]["fieldMargin_".concat(fieldSize)] : '')
}, /*#__PURE__*/_react["default"].createElement(_TextBoxIcon["default"], _extends({
htmlId: uniqueId,
id: id,
type: textBoxType,
variant: textBoxVariant,
size: fieldSize === 'medium' ? textBoxSize : 'xsmall',
maxLength: maxLength,
isReadOnly: isReadOnly,
inputRef: this.handleGetRef,
value: value,
onChange: this.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["default"].createElement(_ValidationMessage["default"], _extends({
text: validationMessage,
palette: validationPalette,
type: errorType,
dataId: "".concat(dataId, "_ValidationMessage"),
htmlFor: uniqueId
}, ValidationMessageProps1)), validationRuleMessage && /*#__PURE__*/_react["default"].createElement(_ValidationMessage["default"], _extends({
text: validationRuleMessage,
palette: validationRulePalette,
type: errorType,
htmlFor: uniqueId,
dataId: "".concat(dataId, "_ValidationRuleMessage")
}, ValidationMessageProps2))));
}
}]);
return TextBoxField;
}(_react.PureComponent);
exports["default"] = TextBoxField;
TextBoxField.propTypes = _propTypes.propTypes;
TextBoxField.defaultProps = _defaultProps.defaultProps; // if (__DOCS__) {
// TextBoxField.docs = {
// componentGroup: 'Form Fields',
// folderName: 'General'
// };
// }