@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
208 lines (184 loc) • 9.57 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/es/v1/Label/Label"));
var _MultiSelect = _interopRequireDefault(require("@zohodesk/components/es/v1/MultiSelect/MultiSelect"));
var _ValidationMessage = _interopRequireDefault(require("../ValidationMessage/ValidationMessage"));
var _IdProvider = require("@zohodesk/components/es/Provider/IdProvider");
var _FieldContainer = _interopRequireDefault(require("../FieldContainer/FieldContainer"));
var _FieldsModule = _interopRequireDefault(require("../../../../form/fields/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 MultiSelectField(props) {
var labelName = props.labelName,
id = props.id,
isMandatory = props.isMandatory,
options = props.options,
selectedOptions = props.selectedOptions,
needSelectAll = props.needSelectAll,
selectAllText = props.selectAllText,
isAnimate = props.isAnimate,
emptyMessage = props.emptyMessage,
size = props.size,
variant = props.variant,
textBoxSize = props.textBoxSize,
animationStyle = props.animationStyle,
validationMessage = props.validationMessage,
validationPalette = props.validationPalette,
isReadOnly = props.isReadOnly,
errorType = props.errorType,
isDisabled = props.isDisabled,
title = props.title,
dataId = props.dataId,
dataSelectorId = props.dataSelectorId,
validationRuleMessage = props.validationRuleMessage,
validationRulePalette = props.validationRulePalette,
onKeyDown = props.onKeyDown,
infoText = props.infoText,
borderColor = props.borderColor,
placeHolder = props.placeHolder,
fieldSize = props.fieldSize,
valueField = props.valueField,
textField = props.textField,
isNextOptions = props.isNextOptions,
isSearching = props.isSearching,
popupGroup = props.popupGroup,
labelPalette = props.labelPalette,
palette = props.palette,
lockedInfoText = props.lockedInfoText,
isLocked = props.isLocked,
htmlId = props.htmlId,
children = props.children,
customChildrenClass = props.customChildrenClass,
onFocus = props.onFocus,
customProps = props.customProps,
i18nKeys = props.i18nKeys,
renderLabelProps = props.renderLabelProps,
onChange = props.onChange,
onDropBoxOpen = props.onDropBoxOpen,
onSearch = props.onSearch,
getNextOptions = props.getNextOptions,
getRef = props.getRef;
var _customProps$LabelPro = customProps.LabelProps,
LabelProps = _customProps$LabelPro === void 0 ? {} : _customProps$LabelPro,
_customProps$MultiSel = customProps.MultiSelectProps,
MultiSelectProps = _customProps$MultiSel === void 0 ? {} : _customProps$MultiSel,
_customProps$Validati = customProps.ValidationMessageProps1,
ValidationMessageProps1 = _customProps$Validati === void 0 ? {} : _customProps$Validati,
_customProps$Validati2 = customProps.ValidationMessageProps2,
ValidationMessageProps2 = _customProps$Validati2 === void 0 ? {} : _customProps$Validati2;
var getNextId = (0, _IdProvider.useUniqueId)();
var multiSelectBox = (0, _react.useRef)(null);
var isDarkPalette = palette === 'dark';
var uniqueId = htmlId ? htmlId : getNextId();
function handleChange(selectedValueIds, selectedValues) {
onChange && onChange(id, selectedValueIds, selectedValues);
}
function handleDropBoxOpen() {
return onDropBoxOpen && onDropBoxOpen(id);
}
function handleSearch(searchStr) {
return onSearch && onSearch(searchStr, {
id: id
});
}
function handleGetNextOptions(searchStr) {
return getNextOptions && getNextOptions(searchStr, {
id: id
});
}
function handleGetRef(el) {
multiSelectBox.current = el;
getRef && getRef(el, id);
} // handleLabelClick() {
// let { isFocusOnLabelClick } = this.props;
// if (
// isFocusOnLabelClick &&
// this.multiSelectBox &&
// this.multiSelectBox.focus
// ) {
// this.multiSelectBox.focus();
// }
// }
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,
renderProps: renderLabelProps
}, /*#__PURE__*/_react["default"].createElement(_Label["default"], _extends({
text: labelName,
id: id,
size: fieldSize === 'small' ? 'small' : 'medium',
palette: isDarkPalette ? 'dark' : isMandatory ? 'mandatory' : isDisabled ? 'primary' : labelPalette // onClick={this.handleLabelClick}
,
customClass: "".concat(_FieldsModule["default"].fieldLabel, " ").concat(isMandatory ? _FieldsModule["default"].labelMandatory : ''),
dataId: isDisabled ? "".concat(dataId, "_label_disabled") : isMandatory ? "".concat(dataId, "_label_mandatory") : "".concat(dataId, "_label"),
htmlFor: uniqueId
}, LabelProps))), /*#__PURE__*/_react["default"].createElement(_MultiSelect["default"], _extends({
options: options,
onChange: handleChange,
selectedOptions: selectedOptions,
getRef: handleGetRef,
isReadOnly: isReadOnly,
needSelectAll: needSelectAll,
selectAllText: selectAllText,
isAnimate: isAnimate,
emptyMessage: emptyMessage,
textBoxSize: textBoxSize,
variant: variant,
size: size,
animationStyle: animationStyle,
dataId: dataId,
onKeyDown: onKeyDown,
borderColor: borderColor,
placeHolder: placeHolder,
isDisabled: isDisabled,
textField: textField,
valueField: valueField,
getNextOptions: handleGetNextOptions,
onSearch: handleSearch,
onDropBoxOpen: handleDropBoxOpen,
popupGroup: popupGroup,
isNextOptions: isNextOptions,
isSearching: isSearching,
palette: palette,
i18nKeys: i18nKeys,
htmlId: uniqueId,
customChildrenClass: customChildrenClass,
onFocus: onFocus
}, MultiSelectProps, {
ariaLabelledby: uniqueId
}), 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,
dataId: "".concat(dataId, "_ValidationRuleMessage"),
htmlFor: uniqueId
}, ValidationMessageProps2)));
}
MultiSelectField.propTypes = _propTypes.propTypes;
MultiSelectField.defaultProps = _defaultProps.defaultProps;
var MemoizedMultiSelectField = /*#__PURE__*/(0, _react.memo)(MultiSelectField);
MemoizedMultiSelectField.propTypes = _propTypes.propTypes;
MemoizedMultiSelectField.defaultProps = _defaultProps.defaultProps;
MemoizedMultiSelectField.displayName = 'MultiSelectField';
var _default = MemoizedMultiSelectField;
exports["default"] = _default;