UNPKG

@zohodesk/dot

Version:

In this Library, we Provide Some Basic Components to Build Your Application

160 lines (153 loc) 4.93 kB
/**** Libraries ****/ import React, { memo } 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/v1/Select/Select'; import ValidationMessage from "../ValidationMessage/ValidationMessage"; import { useUniqueId } from '@zohodesk/components/es/Provider/IdProvider'; import FieldContainer from "../FieldContainer/FieldContainer"; /** CSS */ import style from "../../../../form/fields/Fields.module.css"; const SelectField = props => { const { labelName, 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, id, onChange, getRef } = props; const { LabelProps = {}, SelectProps = {}, ValidationMessageProps1 = {}, ValidationMessageProps2 = {} } = customProps; const getNextId = useUniqueId(); let uniqueId = htmlId ? htmlId : getNextId(); const handleChange = (selectedId, selectedVal) => { onChange && selectedValue !== selectedId && onChange(id, selectedId, selectedVal); }; const handleGetRef = el => { getRef && getRef(el, id); }; 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: handleChange, onFocus: onFocus, getRef: 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, ...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; const MemoizedSelectField = /*#__PURE__*/memo(SelectField); MemoizedSelectField.propTypes = propTypes; MemoizedSelectField.defaultProps = defaultProps; MemoizedSelectField.displayName = 'SelectField'; export default MemoizedSelectField;