@zohodesk/components
Version:
In this Package, we Provide Some Basic Components to Build Web App
206 lines (177 loc) • 10.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"] = TextBoxIcon;
var _react = _interopRequireWildcard(require("react"));
var _defaultProps = require("./props/defaultProps");
var _propTypes = require("./props/propTypes");
var _TextBox = _interopRequireDefault(require("../TextBox/TextBox"));
var _Layout = require("../Layout");
var _icons = require("@zohodesk/icons");
var _semanticButtonModule = _interopRequireDefault(require("../../semantic/Button/semanticButton.module.css"));
var _TextBoxIconModule = _interopRequireDefault(require("../../TextBoxIcon/TextBoxIcon.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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/* eslint-disable react/forbid-component-props */
function TextBoxIcon(props) {
var type = props.type,
name = props.name,
id = props.id,
maxLength = props.maxLength,
placeHolder = props.placeHolder,
size = props.size,
onKeyUp = props.onKeyUp,
isReadOnly = props.isReadOnly,
isDisabled = props.isDisabled,
children = props.children,
onKeyDown = props.onKeyDown,
onClick = props.onClick,
value = props.value,
iconRotated = props.iconRotated,
needBorder = props.needBorder,
variant = props.variant,
onClear = props.onClear,
onChange = props.onChange,
title = props.title,
dataId = props.dataId,
dataSelectorId = props.dataSelectorId,
needReadOnlyStyle = props.needReadOnlyStyle,
isClickable = props.isClickable,
needEffect = props.needEffect,
onKeyPress = props.onKeyPress,
borderColor = props.borderColor,
onMouseDown = props.onMouseDown,
showClearIcon = props.showClearIcon,
htmlId = props.htmlId,
i18nKeys = props.i18nKeys,
customClass = props.customClass,
iconOnHover = props.iconOnHover,
isFocus = props.isFocus,
onClearMouseDown = props.onClearMouseDown,
customProps = props.customProps,
inputRef = props.inputRef,
onFocus = props.onFocus,
onBlur = props.onBlur,
needInputFocusOnWrapperClick = props.needInputFocusOnWrapperClick,
isScrollPrevent = props.isScrollPrevent;
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,
_customClass$customTB3 = customClass.customTBoxLine,
customTBoxLine = _customClass$customTB3 === void 0 ? '' : _customClass$customTB3;
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;
var _useState = (0, _react.useState)(false),
_useState2 = _slicedToArray(_useState, 2),
isActive = _useState2[0],
setActive = _useState2[1];
var inputEle = (0, _react.useRef)();
var handleRef = (0, _react.useCallback)(function (ele) {
inputEle.current = ele;
inputRef && inputRef(ele);
}, []);
var handleClear = function handleClear() {
onClear && onClear();
inputEle.current && inputEle.current.focus({
preventScroll: true
});
};
var handleFocus = function handleFocus(e) {
if (!needReadOnlyStyle || !isReadOnly && needReadOnlyStyle) {
setActive(true);
onFocus && onFocus(e);
}
};
var handleBlur = function handleBlur(e) {
setActive(false);
onBlur && onBlur(e);
};
var handleInputFocusOnClick = function handleInputFocusOnClick() {
inputEle.current && inputEle.current.focus({
preventScroll: true
});
};
return /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
alignBox: "row",
isCover: false,
className: "".concat(_TextBoxIconModule["default"].container, " ").concat(isDisabled ? _TextBoxIconModule["default"].disabled : isReadOnly ? needEffect ? _TextBoxIconModule["default"].effect : _TextBoxIconModule["default"].readonly : _TextBoxIconModule["default"].effect, " ").concat(isActive || isFocus ? _TextBoxIconModule["default"].effectFocused : '', " ").concat(customTBoxWrap, " ").concat(iconOnHover && (isReadOnly || isDisabled) ? _TextBoxIconModule["default"].iconOnHoverReadonly : iconOnHover && !(isReadOnly || isDisabled) ? _TextBoxIconModule["default"].iconOnHoverStyle : ''),
dataSelectorId: dataSelectorId,
"data-title": isDisabled ? title : null,
onClick: needInputFocusOnWrapperClick && !isDisabled ? handleInputFocusOnClick : null
}, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
flexible: true
}, /*#__PURE__*/_react["default"].createElement(_TextBox["default"], _extends({}, props, {
dataId: dataId,
size: size,
variant: variant,
type: type,
value: value,
name: name,
id: id,
htmlId: htmlId,
maxLength: maxLength,
placeHolder: placeHolder,
onKeyUp: onKeyUp,
onFocus: handleFocus,
onKeyDown: onKeyDown,
onChange: onChange,
onBlur: handleBlur,
onClick: onClick,
isReadOnly: isReadOnly,
isDisabled: isDisabled,
inputRef: 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 ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: "".concat(_semanticButtonModule["default"].buttonReset, " ").concat(_TextBoxIconModule["default"].icon),
onClick: 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)), needBorder && /*#__PURE__*/_react["default"].createElement("div", {
className: "".concat(_TextBoxIconModule["default"].line, " ").concat(_TextBoxIconModule["default"]["borderColor_".concat(borderColor)], " ").concat(customTBoxLine)
}));
}
TextBoxIcon.defaultProps = _defaultProps.defaultProps;
TextBoxIcon.propTypes = _propTypes.propTypes; // if (__DOCS__) {
// TextBoxIcon.docs = {
// componentGroup: 'Form Elements',
// folderName: 'Style Guide',
// external: true,
// description: ' '
// };
// }