UNPKG

wix-style-react

Version:
190 lines (148 loc) • 8.33 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireDefault(require("react")); var _StatusAlertSmall = _interopRequireDefault(require("wix-ui-icons-common/StatusAlertSmall")); var _LabelledElement = _interopRequireDefault(require("../LabelledElement")); var _Input = _interopRequireDefault(require("../Input")); var _Text = _interopRequireDefault(require("../Text")); var _propTypes = _interopRequireDefault(require("prop-types")); var _InputWithLabelSt = require("./InputWithLabel.st.css"); var _dataHooks = _interopRequireDefault(require("./dataHooks")); function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } var getSuffixContainer = function getSuffixContainer(suffix) { return suffix.map(function (item, index) { return /*#__PURE__*/_react["default"].createElement("div", { "data-hook": "suffix-container", key: "suffix-container-".concat(index), className: _InputWithLabelSt.classes.groupIcon }, item); }); }; var InputWithLabel = /*#__PURE__*/function (_React$Component) { (0, _inherits2["default"])(InputWithLabel, _React$Component); var _super = _createSuper(InputWithLabel); function InputWithLabel() { (0, _classCallCheck2["default"])(this, InputWithLabel); return _super.apply(this, arguments); } (0, _createClass2["default"])(InputWithLabel, [{ key: "render", value: function render() { var _this$props = this.props, label = _this$props.label, suffix = _this$props.suffix, value = _this$props.value, dataHook = _this$props.dataHook, status = _this$props.status, statusMessage = _this$props.statusMessage, onChange = _this$props.onChange, onFocus = _this$props.onFocus, onBlur = _this$props.onBlur, name = _this$props.name, type = _this$props.type, ariaLabel = _this$props.ariaLabel, autoFocus = _this$props.autoFocus, autocomplete = _this$props.autocomplete, disabled = _this$props.disabled, className = _this$props.className, maxLength = _this$props.maxLength, placeholder = _this$props.placeholder, customInput = _this$props.customInput; return /*#__PURE__*/_react["default"].createElement("div", { "data-hook": dataHook, className: status ? undefined : _InputWithLabelSt.classes.statusMessagePlaceholder }, /*#__PURE__*/_react["default"].createElement(_LabelledElement["default"], { value: value, label: label, dataHook: _dataHooks["default"].labelledElement }, /*#__PURE__*/_react["default"].createElement(_Input["default"], { name: name, type: type, ariaLabel: ariaLabel, autoFocus: autoFocus, autocomplete: autocomplete, disabled: disabled, maxLength: maxLength, placeholder: placeholder, onChange: onChange, onFocus: onFocus, onBlur: onBlur, dataHook: _dataHooks["default"].input, className: className, size: "large", value: value, suffix: suffix ? getSuffixContainer(suffix) : [], status: status, customInput: customInput, hideStatusSuffix: true })), status === _Input["default"].StatusError && statusMessage && /*#__PURE__*/_react["default"].createElement(_Text["default"], { skin: "error", size: "small", weight: "normal", className: _InputWithLabelSt.classes.statusMessage }, /*#__PURE__*/_react["default"].createElement("span", { className: _InputWithLabelSt.classes.statusMessageIcon }, /*#__PURE__*/_react["default"].createElement(_StatusAlertSmall["default"], null)), /*#__PURE__*/_react["default"].createElement("span", { "data-hook": _dataHooks["default"].errorMessage, className: _InputWithLabelSt.classes.errorMessageContent }, statusMessage))); } }]); return InputWithLabel; }(_react["default"].Component); (0, _defineProperty2["default"])(InputWithLabel, "propTypes", { /** Sets a default value for those who want to use this component uncontrolled */ dataHook: _propTypes["default"].string, /** Pass a component you want to show as the suffix of the input, e.g., text string, icon. */ suffix: _propTypes["default"].arrayOf(_propTypes["default"].element), /** Sets the field label */ label: _propTypes["default"].string, /** Sets input value */ value: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]), /** Specifies the status of a field */ status: _propTypes["default"].oneOf(['error', 'warning', 'loading']), /** Defines the message displayed when you hover over the status icon. If not given or empty there will be no tooltip. */ statusMessage: _propTypes["default"].node, /** Defines a standard input onFocus callback */ onFocus: _propTypes["default"].func, /** Defines a standard input onBlur callback */ onBlur: _propTypes["default"].func, /** Defines a standard input onChange callback */ onChange: _propTypes["default"].func, /** Reference element data when a form is submitted */ name: _propTypes["default"].string, /** Specifies the type of `<input/>` element to display. Default is text string. */ type: _propTypes["default"].string, /** Define a string that labels the current element in case where a text label is not visible on the screen */ ariaLabel: _propTypes["default"].string, /** Focus the element on mount (standard React input autoFocus). */ autoFocus: _propTypes["default"].bool, /** Sets the value of native autocomplete attribute (consult the [HTML spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete) for possible values) */ autocomplete: _propTypes["default"].string, /** Specifies whether the input should be disabled or not */ disabled: _propTypes["default"].bool, /** Specifies a CSS class name to be appended to the component’s root element */ className: _propTypes["default"].string, /** Sets the maximum number of characters that can be entered into a field */ maxLength: _propTypes["default"].number, /** Sets a placeholder message to display */ placeholder: _propTypes["default"].string, /** Render a custom input component instead of the default html input tag */ customInput: _propTypes["default"].elementType ? _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].node, _propTypes["default"].elementType]) : _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].node]) }); (0, _defineProperty2["default"])(InputWithLabel, "defaultProps", { statusMessage: '' }); var _default = InputWithLabel; exports["default"] = _default;