@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
204 lines (190 loc) • 6.17 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 DateWidget from '@zohodesk/components/es/DateTime/DateWidget';
import ValidationMessage from "../ValidationMessage/ValidationMessage";
import { getUniqueId } from '@zohodesk/components/es/Provider/IdProvider';
import FieldContainer from "../FieldContainer/FieldContainer";
/**** CSS ****/
import style from "../Fields.module.css";
export default class DateField 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);
this.openPopup = this.openPopup.bind(this);
}
handleChange(value) {
let {
id,
onChange
} = this.props;
onChange && onChange(id, value);
}
handleGetRef(el) {
let {
getRef,
id
} = this.props;
this.dateField = el;
getRef && getRef(el, id);
}
componentDidMount() {
this.openPopup();
}
openPopup() {
let {
openPopupOnMount
} = this.props;
if (openPopupOnMount) {
setTimeout(() => {
this.dateField && this.dateField.click && this.dateField.click();
this.handleLabelClick();
}, 100);
}
}
componentDidUpdate(prevProps) {
let {
openPopupOnMount: prevOpenPopupOnMount
} = prevProps;
let {
openPopupOnMount
} = this.props;
if (openPopupOnMount !== prevOpenPopupOnMount) {
this.openPopup();
}
}
handleLabelClick() {
let {
isFocusOnLabelClick
} = this.props;
if (isFocusOnLabelClick && this.dateField && this.dateField.focus) {
this.dateField.focus();
}
}
render() {
let {
labelName,
isMandatory,
isDateTime,
validationMessage,
validationPalette,
textBoxSize,
textBoxVariant,
isReadOnly,
value,
errorType,
isDisabled,
title,
popupGroup,
dataId,
dataSelectorId,
validationRuleMessage,
validationRulePalette,
onKeyDown,
infoText,
borderColor,
fieldSize,
datePattern,
isLocked,
lockedInfoText,
lockedValueText,
labelPalette,
labelCustomClass,
htmlId,
timeZone,
i18nKeys,
iconOnHover,
customProps,
renderLabelProps
} = this.props;
const {
LabelProps = {},
DateWidgetProps = {},
ValidationMessageProps1 = {},
ValidationMessageProps2 = {}
} = customProps;
let getAriaId = 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
},
size: fieldSize === 'small' ? 'small' : 'medium',
htmlFor: getAriaId,
testId: isDisabled ? `${dataId}_label_disabled` : isMandatory ? `${dataId}_label_mandatory` : `${dataId}_label`,
customId: isDisabled ? `${dataId}_label_disabled` : isMandatory ? `${dataId}_label_mandatory` : `${dataId}_label`,
onClick: isDisabled || isReadOnly ? null : this.handleLabelClick,
tagAttributes: {
label: {
id: labelName
}
}
}, LabelProps))), /*#__PURE__*/React.createElement("div", {
className: `${style.fieldContainer} ${labelName ? style[`fieldMargin_${fieldSize}`] : ''}`
}, isLocked && lockedValueText ? /*#__PURE__*/React.createElement("div", {
className: style.lockText
}, lockedValueText) : /*#__PURE__*/React.createElement(DateWidget, _extends({
textBoxSize: fieldSize === 'medium' ? textBoxSize : 'xsmall',
textBoxVariant: textBoxVariant,
isDateTime: isDateTime,
onSelect: this.handleChange,
timeZone: timeZone,
getRef: this.handleGetRef,
isReadOnly: isReadOnly,
value: value,
popupGroup: popupGroup,
dataId: `${dataId}(formatted_${labelName})`,
onKeyDown: onKeyDown,
borderColor: borderColor,
isDisabled: isDisabled,
dateFormat: datePattern,
isEditable: true,
htmlId: getAriaId,
i18nKeys: i18nKeys,
iconOnHover: iconOnHover
}, DateWidgetProps, {
a11y: {
ariaLabelledby: labelName
}
})), validationMessage && /*#__PURE__*/React.createElement(ValidationMessage, _extends({
text: validationMessage,
palette: validationPalette,
type: errorType,
htmlFor: getAriaId,
dataId: `${dataId}_ValidationMessage`
}, ValidationMessageProps1)), validationRuleMessage && /*#__PURE__*/React.createElement(ValidationMessage, _extends({
text: validationRuleMessage,
palette: validationRulePalette,
type: errorType,
htmlFor: getAriaId,
dataId: `${dataId}_ValidationRuleMessage`
}, ValidationMessageProps2))));
}
}
DateField.propTypes = propTypes;
DateField.defaultProps = defaultProps; // if (__DOCS__) {
// DateField.docs = {
// componentGroup: 'Form Fields',
// folderName: 'General'
// };
// }