wix-style-react
Version:
91 lines (73 loc) • 2.4 kB
JavaScript
import infoIconDriverFactory from '../InfoIcon/InfoIcon.driver';
import { dataHooks } from './constants';
import textDriverFactory from '../Text/Text.driver';
var formFieldDriver = function formFieldDriver(_ref) {
var _element = _ref.element;
var byHook = function byHook(hook) {
return _element.querySelector("[data-hook*=\"".concat(hook, "\"]"));
};
var charactersCounter = function charactersCounter() {
return byHook(dataHooks.counter);
};
var labelElement = function labelElement() {
return byHook(dataHooks.label);
};
var labelTextDriver = function labelTextDriver() {
return textDriverFactory({
element: labelElement()
});
};
return {
exists: function exists() {
return !!_element;
},
element: function element() {
return _element;
},
/** get children */
getChildren: function getChildren() {
return byHook(dataHooks.children);
},
/** get label */
getLabel: function getLabel() {
return labelElement();
},
/** returns label size */
getLabelSize: function getLabelSize() {
return labelTextDriver().getSize();
},
/** returns true whether form field is required */
isRequired: function isRequired() {
return !!byHook(dataHooks.asterisk);
},
/** returns the length left */
getLengthLeft: function getLengthLeft() {
var counter = charactersCounter();
return counter ? parseInt(counter.innerHTML, 10) : null;
},
/** returns whether the form field length is exceeded */
isLengthExceeded: function isLengthExceeded() {
var counter = charactersCounter();
if (counter) {
var length = parseInt(counter.innerHTML, 10);
return length < 0;
}
return false;
},
/** returns true whether form field has tooltip */
hasTooltip: function hasTooltip() {
return !!_element.querySelector("[data-hook=\"".concat(dataHooks.infoIcon, "\"]"));
},
/** returns tooltip text of the info content */
getInfoContent: function getInfoContent() {
return infoIconDriverFactory({
element: _element.querySelector("[data-hook=\"".concat(dataHooks.infoIcon, "\"]"))
}).getContent();
},
/** get form field suffix */
getSuffix: function getSuffix() {
return byHook(dataHooks.suffix);
}
};
};
export default formFieldDriver;