wix-style-react
Version:
151 lines (132 loc) • 6.63 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(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; } }
import React from 'react';
import omit from 'omit';
import PropTypes from 'prop-types';
import Input from '../Input/Input';
import { st, classes } from './NoBorderInput.st.css';
import Text from '../Text';
import dataHooks from './dataHooks';
import { FontUpgradeContext } from '../FontUpgrade/context';
import deprecationLog from '../utils/deprecationLog';
var NoBorderInput = /*#__PURE__*/function (_React$Component) {
_inherits(NoBorderInput, _React$Component);
var _super = _createSuper(NoBorderInput);
function NoBorderInput(props) {
var _this;
_classCallCheck(this, NoBorderInput);
_this = _super.call(this, props);
_this.state = {
focus: !!props.autoFocus
};
deprecationLog('<NoBorderInput/> is deprecated and will be removed next version. Please use <Input border="bottomLine"/> instead');
return _this;
}
_createClass(NoBorderInput, [{
key: "render",
value: function render() {
var _this2 = this;
var _this$props = this.props,
id = _this$props.id,
size = _this$props.size,
dataHook = _this$props.dataHook,
label = _this$props.label,
disabled = _this$props.disabled,
_onFocus = _this$props.onFocus,
_onBlur = _this$props.onBlur,
status = _this$props.status,
statusMessage = _this$props.statusMessage,
className = _this$props.className,
value = _this$props.value;
var rejectedProps = ['prefix', 'className', 'statusMessage', 'roundInput', 'noLeftBorderRadius', 'noRightBorderRadius'];
var wsrInputProps = omit(rejectedProps, this.props);
var hasValue = Boolean(value && value.length || this.wsrInput && this.wsrInput.input && !!this.wsrInput.input.value);
var renderStatusLine = function renderStatusLine() {
return !disabled && status && statusMessage && /*#__PURE__*/React.createElement(Text, {
dataHook: dataHooks.statusMessage,
className: classes.statusMessage,
size: "tiny",
weight: "thin",
skin: "error"
}, statusMessage);
};
return /*#__PURE__*/React.createElement(FontUpgradeContext.Consumer, null, function (_ref) {
var isMadefor = _ref.active;
return /*#__PURE__*/React.createElement("div", {
className: st(classes.root, {
isMadefor: isMadefor,
size: size,
focus: _this2.state.focus,
hasValue: hasValue,
noLabel: !label,
status: status,
disabled: disabled
}, className),
"data-hook": dataHook,
"data-status": status
}, /*#__PURE__*/React.createElement(Text, {
tagName: "label",
dataHook: dataHooks.label,
className: classes.label,
htmlFor: id,
size: "medium",
weight: isMadefor ? 'thin' : 'normal',
light: true,
secondary: true,
ellipsis: true,
showTooltip: false,
skin: disabled ? 'disabled' : 'standard'
}, label), /*#__PURE__*/React.createElement(Input, _extends({}, wsrInputProps, {
ref: function ref(wsrInput) {
return _this2.wsrInput = wsrInput;
},
onFocus: function onFocus(e) {
_this2.setState({
focus: true
});
if (typeof _onFocus === 'function') {
_onFocus(e);
}
},
onBlur: function onBlur(e) {
_this2.setState({
focus: false
});
if (typeof _onBlur === 'function') {
_onBlur(e);
}
}
})), /*#__PURE__*/React.createElement("div", {
className: classes.border
}), renderStatusLine());
});
}
}]);
return NoBorderInput;
}(React.Component);
_defineProperty(NoBorderInput, "StatusError", Input.StatusError);
NoBorderInput.displayName = 'NoBorderInput';
NoBorderInput.defaultProps = {
autoSelect: true,
size: 'medium',
statusMessage: '',
textOverflow: 'clip',
maxLength: 524288
};
NoBorderInput.propTypes = _objectSpread(_objectSpread({
/** The label displayed above the input when focused and as the input text when there is none */
label: PropTypes.string
}, Input.propTypes), {}, {
/** Input status - use to display an status indication for the user. for example: 'error' */
status: PropTypes.oneOf([NoBorderInput.StatusError])
});
export default NoBorderInput;