@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
193 lines (183 loc) • 6.22 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 Select from '@zohodesk/components/es/Select/Select';
import ValidationMessage from "../ValidationMessage/ValidationMessage";
import { getUniqueId } from '@zohodesk/components/es/Provider/IdProvider';
import FieldContainer from "../FieldContainer/FieldContainer";
/**** props ****/
/** CSS */
import style from "../Fields.module.css";
export default class SelectField extends PureComponent {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleGetRef = this.handleGetRef.bind(this); // this.handleLabelClick = this.handleLabelClick.bind(this);
this.getNextId = getUniqueId(this);
}
handleChange(selctedId, selectedValue) {
let {
id: fieldId,
onChange,
selectedValue: propValue
} = this.props;
onChange && propValue !== selctedId && onChange(fieldId, selctedId, selectedValue);
}
handleGetRef(el) {
let {
getRef,
id
} = this.props;
this.selectBox = el;
getRef && getRef(el, id);
} // handleLabelClick() {
// let { isFocusOnLabelClick } = this.props;
// if (isFocusOnLabelClick && this.selectBox && this.selectBox.focus) {
// this.selectBox.focus();
// }
// }
render() {
let {
labelName,
id,
isMandatory,
options,
selectedValue,
needSearch,
emptyMessage,
animationStyle,
textBoxSize,
textBoxVariant,
searchBoxSize,
searchBoxPlaceHolder,
validationMessage,
validationPalette,
isReadOnly,
valueField,
textField,
excludeOptions,
errorType,
isDisabled,
title,
dataId,
dataSelectorId,
fieldClass,
validationRuleMessage,
validationRulePalette,
onKeyDown,
infoText,
isLocked,
lockedInfoText,
borderColor,
fieldSize,
isNextOptions,
getNextOptions,
popupGroup,
onSearch,
labelPalette,
labelCustomClass,
htmlId,
needLocalSearch,
isDefaultSelectValue,
placeHolder,
children,
onFocus,
iconOnHover,
customProps,
renderLabelProps
} = this.props;
const {
LabelProps = {},
SelectProps = {},
ValidationMessageProps1 = {},
ValidationMessageProps2 = {}
} = customProps;
let uniqueId = htmlId ? htmlId : this.getNextId();
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
},
htmlFor: uniqueId,
size: fieldSize === 'small' ? 'small' : 'medium',
testId: isDisabled ? `${dataId}_label_disabled` : isMandatory ? `${dataId}_label_mandatory` : `${dataId}_label`,
customId: isDisabled ? `${dataId}_label_disabled` : isMandatory ? `${dataId}_label_mandatory` : `${dataId}_label`,
tagAttributes: {
label: {
id: uniqueId
}
}
}, LabelProps))), /*#__PURE__*/React.createElement("div", {
className: `${style.fieldContainer} ${labelName ? style[`fieldMargin_${fieldSize}`] : ''} ${fieldClass ? fieldClass : ''}`
}, /*#__PURE__*/React.createElement(Select, _extends({
options: options,
selectedValue: selectedValue,
onChange: this.handleChange,
onFocus: onFocus,
getRef: this.handleGetRef,
needSearch: needSearch,
emptyMessage: emptyMessage,
animationStyle: animationStyle,
textBoxSize: fieldSize === 'medium' ? textBoxSize : 'xsmall',
textBoxVariant: textBoxVariant,
searchBoxSize: searchBoxSize,
searchBoxPlaceHolder: searchBoxPlaceHolder,
valueField: valueField,
textField: textField,
excludeOptions: excludeOptions,
dataId: dataId,
onKeyDown: onKeyDown,
borderColor: borderColor,
isDisabled: isDisabled,
isReadOnly: isReadOnly,
isNextOptions: isNextOptions,
getNextOptions: getNextOptions,
popupGroup: popupGroup,
onSearch: onSearch,
htmlId: uniqueId,
needLocalSearch: needLocalSearch,
isDefaultSelectValue: isDefaultSelectValue,
placeHolder: placeHolder,
iconOnHover: iconOnHover,
title: title
}, SelectProps, {
ariaLabelledby: uniqueId
}), children ? children : null)), validationMessage && /*#__PURE__*/React.createElement(ValidationMessage, _extends({
text: validationMessage,
palette: validationPalette,
type: errorType,
htmlFor: uniqueId,
dataId: `${dataId}_ValidationMessage`
}, ValidationMessageProps1)), validationRuleMessage && /*#__PURE__*/React.createElement(ValidationMessage, _extends({
text: validationRuleMessage,
palette: validationRulePalette,
type: errorType,
htmlFor: uniqueId,
dataId: `${dataId}_ValidationRuleMessage`
}, ValidationMessageProps2)));
}
}
SelectField.propTypes = propTypes;
SelectField.defaultProps = defaultProps; // if (__DOCS__) {
// SelectField.docs = {
// componentGroup: 'Form Fields',
// folderName: 'General'
// };
// }