wix-style-react
Version:
177 lines (148 loc) • 6.68 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
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";
var _excluded = ["type", "styleType", "active", "last", "number", "text", "className"];
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 { withFocusable } from "wix-ui-core/dist/es/src/hocs/Focusable/FocusableHOC";
import ChevronRight from 'wix-ui-icons-common/ChevronRight';
import { FontUpgradeContext } from '../../FontUpgrade/context';
import Text from '../../Text';
import StepMarker from './StepMarker';
import { Type, StepType, DataHook } from '../constants';
import { st, classes } from './Step.st.css';
var Step = /*#__PURE__*/function (_React$PureComponent) {
_inherits(Step, _React$PureComponent);
var _super = _createSuper(Step);
function Step() {
var _this;
_classCallCheck(this, Step);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "state", {
isHovered: false,
// Used to update <Text ellipsis> when CSS transition has ended
// (otherwise the logic to show/hide tooltip will not be applied)
transitionSequence: 1
});
_defineProperty(_assertThisInitialized(_this), "_handleMouseEnter", function () {
_this.setState({
isHovered: true
});
});
_defineProperty(_assertThisInitialized(_this), "_handleMouseLeave", function () {
_this.setState({
isHovered: false
});
});
_defineProperty(_assertThisInitialized(_this), "_handleTransitionEnd", function (event) {
var transitionSequence = _this.state.transitionSequence;
if (event.propertyName === 'flex-shrink') {
_this.setState({
transitionSequence: transitionSequence + 1
});
}
});
_defineProperty(_assertThisInitialized(_this), "_handleClick", function () {
_this._isClickable() && _this.props.onClick();
});
_defineProperty(_assertThisInitialized(_this), "_isClickable", function () {
var _this$props = _this.props,
onClick = _this$props.onClick,
type = _this$props.type,
active = _this$props.active;
return type !== StepType.Disabled && !active && !!onClick;
});
_defineProperty(_assertThisInitialized(_this), "_getFocusProps", function () {
var _this$props2 = _this.props,
onClick = _this$props2.onClick,
focusableOnFocus = _this$props2.focusableOnFocus,
focusableOnBlur = _this$props2.focusableOnBlur,
type = _this$props2.type;
if (onClick && type !== StepType.Disabled) {
return {
onFocus: focusableOnFocus,
onBlur: focusableOnBlur,
tabIndex: 0
};
}
return {
tabIndex: -1
};
});
return _this;
}
_createClass(Step, [{
key: "render",
value: function render() {
var _this2 = this;
var _this$props3 = this.props,
type = _this$props3.type,
styleType = _this$props3.styleType,
active = _this$props3.active,
last = _this$props3.last,
number = _this$props3.number,
text = _this$props3.text,
className = _this$props3.className,
otherProps = _objectWithoutProperties(_this$props3, _excluded);
var _this$state = this.state,
isHovered = _this$state.isHovered,
transitionSequence = _this$state.transitionSequence;
var isClickable = this._isClickable();
return /*#__PURE__*/React.createElement(FontUpgradeContext.Consumer, null, function (_ref) {
var isMadefor = _ref.active;
return /*#__PURE__*/React.createElement("button", _extends({
className: st(classes.root, {
isMadefor: isMadefor,
type: type,
styleType: styleType,
selected: active,
hovered: isHovered,
clickable: isClickable
}, className),
"data-hook": DataHook.Step,
"data-type": type,
"data-active": active,
onMouseEnter: _this2._handleMouseEnter,
onMouseLeave: _this2._handleMouseLeave,
onClick: _this2._handleClick,
onTransitionEnd: _this2._handleTransitionEnd
}, _this2._getFocusProps()), /*#__PURE__*/React.createElement("div", {
className: classes.content
}, /*#__PURE__*/React.createElement(StepMarker, {
number: number,
active: active,
type: type,
styleType: styleType,
hovered: isHovered && isClickable,
className: classes.marker
}), /*#__PURE__*/React.createElement(Text, {
key: transitionSequence,
ellipsis: true,
weight: isMadefor ? 'thin' : 'normal',
size: styleType === Type.Text ? 'medium' : 'small',
showTooltip: !active,
dataHook: DataHook.StepText,
className: classes.text
}, text)), !last && /*#__PURE__*/React.createElement(ChevronRight, {
className: classes.arrow
}));
});
}
}]);
return Step;
}(React.PureComponent);
_defineProperty(Step, "displayName", 'Step');
_defineProperty(Step, "defaultProps", {
type: StepType.Normal
});
export default withFocusable(Step);