@zohodesk/components
Version:
Dot UI is a customizable React component library built to deliver a clean, accessible, and developer-friendly UI experience. It offers a growing set of reusable components designed to align with modern design systems and streamline application development
257 lines (225 loc) • 12.9 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 = _interopRequireDefault(require("react"));
var _defaultProps = require("./props/defaultProps");
var _propTypes = require("./props/propTypes");
var _TextBox = _interopRequireDefault(require("../TextBox/TextBox"));
var _Layout = require("../Layout");
var _InputFieldLine = _interopRequireDefault(require("../shared/InputFieldLine/InputFieldLine"));
var _icons = require("@zohodesk/icons");
var _semanticButtonModule = _interopRequireDefault(require("../semantic/Button/semanticButton.module.css"));
var _TextBoxIconModule = _interopRequireDefault(require("./TextBoxIcon.module.css"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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); }
/* eslint-disable react/forbid-component-props */
var TextBoxIcon = /*#__PURE__*/function (_React$Component) {
_inherits(TextBoxIcon, _React$Component);
var _super = _createSuper(TextBoxIcon);
function TextBoxIcon(props) {
var _this;
_classCallCheck(this, TextBoxIcon);
_this = _super.call(this, props);
_this.state = {
isActive: false
};
_this.handleFocus = _this.handleFocus.bind(_assertThisInitialized(_this));
_this.handleBlur = _this.handleBlur.bind(_assertThisInitialized(_this));
_this.handleRef = _this.handleRef.bind(_assertThisInitialized(_this));
_this.handleClear = _this.handleClear.bind(_assertThisInitialized(_this));
_this.handleInputFocusOnClick = _this.handleInputFocusOnClick.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(TextBoxIcon, [{
key: "handleRef",
value: function handleRef(ele) {
var inputRef = this.props.inputRef;
this.inputEle = ele;
inputRef && inputRef(ele);
}
}, {
key: "handleClear",
value: function handleClear() {
var onClear = this.props.onClear;
onClear && onClear();
this.inputEle && this.inputEle.focus({
preventScroll: true
});
}
}, {
key: "handleFocus",
value: function handleFocus(e) {
var _this$props = this.props,
onFocus = _this$props.onFocus,
needReadOnlyStyle = _this$props.needReadOnlyStyle,
isReadOnly = _this$props.isReadOnly;
if (!needReadOnlyStyle || !isReadOnly && needReadOnlyStyle) {
this.setState({
isActive: true
});
onFocus && onFocus(e);
}
}
}, {
key: "handleBlur",
value: function handleBlur(e) {
var onBlur = this.props.onBlur;
this.setState({
isActive: false
});
onBlur && onBlur(e);
}
}, {
key: "handleInputFocusOnClick",
value: function handleInputFocusOnClick() {
this.inputEle && this.inputEle.focus({
preventScroll: true
});
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
type = _this$props2.type,
name = _this$props2.name,
id = _this$props2.id,
maxLength = _this$props2.maxLength,
placeHolder = _this$props2.placeHolder,
size = _this$props2.size,
onKeyUp = _this$props2.onKeyUp,
isReadOnly = _this$props2.isReadOnly,
isDisabled = _this$props2.isDisabled,
children = _this$props2.children,
onKeyDown = _this$props2.onKeyDown,
onClick = _this$props2.onClick,
value = _this$props2.value,
iconRotated = _this$props2.iconRotated,
needBorder = _this$props2.needBorder,
variant = _this$props2.variant,
onClear = _this$props2.onClear,
onChange = _this$props2.onChange,
title = _this$props2.title,
dataId = _this$props2.dataId,
dataSelectorId = _this$props2.dataSelectorId,
needReadOnlyStyle = _this$props2.needReadOnlyStyle,
isClickable = _this$props2.isClickable,
needEffect = _this$props2.needEffect,
onKeyPress = _this$props2.onKeyPress,
borderColor = _this$props2.borderColor,
onMouseDown = _this$props2.onMouseDown,
showClearIcon = _this$props2.showClearIcon,
htmlId = _this$props2.htmlId,
i18nKeys = _this$props2.i18nKeys,
customClass = _this$props2.customClass,
iconOnHover = _this$props2.iconOnHover,
isFocus = _this$props2.isFocus,
onClearMouseDown = _this$props2.onClearMouseDown,
isScrollPrevent = _this$props2.isScrollPrevent,
customProps = _this$props2.customProps,
needInputFocusOnWrapperClick = _this$props2.needInputFocusOnWrapperClick,
renderRightPlaceholderNode = _this$props2.renderRightPlaceholderNode,
renderCustomClearComponent = _this$props2.renderCustomClearComponent;
var isActive = this.state.isActive;
var _customClass$customTB = customClass.customTBoxWrap,
customTBoxWrap = _customClass$customTB === void 0 ? '' : _customClass$customTB,
_customClass$customTe = customClass.customTextBox,
customTextBox = _customClass$customTe === void 0 ? '' : _customClass$customTe,
_customClass$customTB2 = customClass.customTBoxIcon,
customTBoxIcon = _customClass$customTB2 === void 0 ? '' : _customClass$customTB2;
var _i18nKeys$clearText = i18nKeys.clearText,
clearText = _i18nKeys$clearText === void 0 ? 'Clear' : _i18nKeys$clearText;
var _customProps$TextBoxP = customProps.TextBoxProps,
TextBoxProps = _customProps$TextBoxP === void 0 ? {} : _customProps$TextBoxP;
return /*#__PURE__*/_react["default"].createElement(_InputFieldLine["default"], {
isActive: isActive || isFocus,
border: needBorder ? 'bottom' : 'none',
borderColor: borderColor,
hasEffect: needEffect,
isDisabled: isDisabled,
isReadOnly: isReadOnly && needReadOnlyStyle,
customClass: " ".concat(_TextBoxIconModule["default"].container, " ").concat(iconOnHover && (isReadOnly || isDisabled) ? _TextBoxIconModule["default"].iconOnHoverReadonly : iconOnHover && !(isReadOnly || isDisabled) ? _TextBoxIconModule["default"].iconOnHoverStyle : '', " ").concat(customTBoxWrap, " "),
title: isDisabled ? title : null,
onClick: needInputFocusOnWrapperClick && !isDisabled ? this.handleInputFocusOnClick : null,
customProps: {
dataSelectorId: dataSelectorId
}
}, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
flexible: true
}, /*#__PURE__*/_react["default"].createElement(_TextBox["default"], _extends({}, this.props, {
dataId: dataId,
size: size,
variant: variant,
type: type,
value: value,
name: name,
id: id,
htmlId: htmlId,
maxLength: maxLength,
placeHolder: placeHolder,
onKeyUp: onKeyUp,
onFocus: this.handleFocus,
onKeyDown: onKeyDown,
onChange: onChange,
onBlur: this.handleBlur,
onClick: onClick,
isReadOnly: isReadOnly,
isDisabled: isDisabled,
inputRef: this.handleRef,
needReadOnlyStyle: needReadOnlyStyle,
isClickable: isClickable,
onKeyPress: onKeyPress,
onMouseDown: onMouseDown,
needBorder: false,
isScrollPrevent: isScrollPrevent,
customClass: customTextBox,
customProps: TextBoxProps
}))), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: "".concat(_TextBoxIconModule["default"].iconContainer, " ").concat(customTBoxIcon)
}, /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
alignBox: "row"
}, value && onClear && value.length > 1 && !isDisabled && !isReadOnly || showClearIcon ? typeof renderCustomClearComponent == 'function' ? renderCustomClearComponent({
clearText: clearText,
handleClear: this.handleClear
}) : /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: "".concat(_semanticButtonModule["default"].buttonReset, " ").concat(_TextBoxIconModule["default"].icon),
onClick: this.handleClear,
dataId: "".concat(dataId, "_ClearIcon"),
"data-title": clearText,
tagName: "button"
}, /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
align: "both",
"aria-hidden": true,
onMouseDown: onClearMouseDown
}, /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
name: "ZD-delete",
size: "14"
}))) : null, children ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: "".concat(_TextBoxIconModule["default"].icon, " ").concat(iconRotated ? _TextBoxIconModule["default"].rotated : '')
}, children) : null, renderRightPlaceholderNode ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, null, renderRightPlaceholderNode) : null)));
}
}]);
return TextBoxIcon;
}(_react["default"].Component);
exports["default"] = TextBoxIcon;
TextBoxIcon.defaultProps = _defaultProps.defaultProps;
TextBoxIcon.propTypes = _propTypes.propTypes; // if (__DOCS__) {
// TextBoxIcon.docs = {
// componentGroup: 'Form Elements',
// folderName: 'Style Guide',
// external: true,
// description: ' '
// };
// }