@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
184 lines (175 loc) • 5.69 kB
JavaScript
/**** Libraries ****/
import React, { PureComponent } from 'react';
import { defaultProps } from "./props/defaultProps";
import { propTypes } from "./props/propTypes";
/**** Components ****/
import Label from '@zohodesk/components/es/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, {
text: labelName,
size: fieldSize === 'small' ? 'small' : 'medium',
palette: isMandatory ? 'mandatory' : isDisabled ? 'primary' : labelPalette,
customClass: `${style.fieldLabel} ${labelCustomClass} ${isMandatory ? style.labelMandatory : ''}`,
htmlFor: uniqueId,
dataId: isDisabled ? `${dataId}_label_disabled` : isMandatory ? `${dataId}_label_mandatory` : `${dataId}_label`,
...LabelProps,
id: uniqueId
})), /*#__PURE__*/React.createElement("div", {
className: `${style.fieldContainer} ${labelName ? style[`fieldMargin_${fieldSize}`] : ''} ${fieldClass ? fieldClass : ''}`
}, /*#__PURE__*/React.createElement(Select, {
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, {
text: validationMessage,
palette: validationPalette,
type: errorType,
htmlFor: uniqueId,
dataId: `${dataId}_ValidationMessage`,
...ValidationMessageProps1
}), validationRuleMessage && /*#__PURE__*/React.createElement(ValidationMessage, {
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'
// };
// }