wix-style-react
Version:
228 lines (196 loc) • 8.4 kB
JavaScript
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";
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 PropTypes from 'prop-types';
import Text from '../Text';
import { classes, st } from './HorizontalTimeline.st.css';
import { classes as iconsClasses, st as iconSt } from './HorizontalTimelineIcons.st.css';
import { dataHooks } from './constants';
import StatusCompleteFilled from 'wix-ui-icons-common/StatusCompleteFilled';
import StatusAlertFilled from 'wix-ui-icons-common/StatusAlertFilled';
var HorizontalTimeline = /*#__PURE__*/function (_React$PureComponent) {
_inherits(HorizontalTimeline, _React$PureComponent);
var _super = _createSuper(HorizontalTimeline);
function HorizontalTimeline() {
var _this;
_classCallCheck(this, HorizontalTimeline);
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), "_renderLine", function (_ref) {
var skin = _ref.skin,
line = _ref.line;
return /*#__PURE__*/React.createElement("div", {
className: st(classes.line, {
skin: skin,
line: line
})
});
});
_defineProperty(_assertThisInitialized(_this), "_renderLabel", function (_ref2) {
var label = _ref2.label,
index = _ref2.index,
labelEllipsis = _ref2.labelEllipsis;
var alignLabel = _this.props.alignLabel;
return /*#__PURE__*/React.createElement("div", {
className: st(classes.label, {
alignLabel: alignLabel
})
}, /*#__PURE__*/React.createElement(Text, {
size: "tiny",
ellipsis: labelEllipsis,
dataHook: "".concat(dataHooks.horizontalTimelineLabel, "-").concat(index)
}, label));
});
return _this;
}
_createClass(HorizontalTimeline, [{
key: "render",
value: function render() {
var _this2 = this;
var _this$props = this.props,
items = _this$props.items,
dataHook = _this$props.dataHook,
className = _this$props.className,
skin = _this$props.skin;
return /*#__PURE__*/React.createElement("div", {
className: st(classes.root, {
skin: skin
}, className),
"data-hook": dataHook,
"data-skin": skin
}, items.map(function (_ref3, index) {
var label = _ref3.label,
_ref3$width = _ref3.width,
width = _ref3$width === void 0 ? 'auto' : _ref3$width,
deprecatedSkin = _ref3.skin,
_ref3$icon = _ref3.icon,
icon = _ref3$icon === void 0 ? /*#__PURE__*/React.createElement(HorizontalTimeline.DefaultIcon, null) : _ref3$icon,
_ref3$line = _ref3.line,
line = _ref3$line === void 0 ? 'dashed' : _ref3$line,
_ref3$labelEllipsis = _ref3.labelEllipsis,
labelEllipsis = _ref3$labelEllipsis === void 0 ? true : _ref3$labelEllipsis;
var nextItemSkin = items[index + 1] && items[index + 1].skin || 'light';
var nextItemLine = items[index + 1] && items[index + 1].line || 'dashed';
return /*#__PURE__*/React.createElement("div", {
className: classes.column,
key: index,
style: {
width: width
}
}, /*#__PURE__*/React.createElement("div", {
className: st(classes.item)
}, /*#__PURE__*/React.createElement("div", {
className: classes.lineIconLine
}, _this2._renderLine({
skin: deprecatedSkin,
line: line
}), /*#__PURE__*/React.createElement("div", {
className: classes.icon
}, icon), _this2._renderLine({
skin: nextItemSkin,
line: nextItemLine
})), _this2._renderLabel({
label: label,
index: index,
labelEllipsis: labelEllipsis
})));
}));
}
}]);
return HorizontalTimeline;
}(React.PureComponent);
_defineProperty(HorizontalTimeline, "displayName", 'HorizontalTimeline');
_defineProperty(HorizontalTimeline, "DefaultIcon", function (_ref4) {
var _ref4$skin = _ref4.skin,
skin = _ref4$skin === void 0 ? 'dark' : _ref4$skin;
return /*#__PURE__*/React.createElement("div", {
className: iconSt(iconsClasses.upcomingIcon, {
skin: skin
})
});
});
_defineProperty(HorizontalTimeline, "ActiveIcon", function (_ref5) {
var _ref5$skin = _ref5.skin,
skin = _ref5$skin === void 0 ? 'dark' : _ref5$skin;
return /*#__PURE__*/React.createElement("div", {
className: iconSt(iconsClasses.activeIcon, {
skin: skin
})
});
});
_defineProperty(HorizontalTimeline, "BoundaryIcon", function (_ref6) {
var _ref6$skin = _ref6.skin,
skin = _ref6$skin === void 0 ? 'dark' : _ref6$skin;
return /*#__PURE__*/React.createElement("div", {
className: iconSt(iconsClasses.boundaryIcon, {
skin: skin
})
});
});
_defineProperty(HorizontalTimeline, "DestructiveIcon", function () {
return /*#__PURE__*/React.createElement(StatusAlertFilled, {
className: iconsClasses.errorIcon
});
});
_defineProperty(HorizontalTimeline, "CompleteIcon", function (_ref7) {
var _ref7$skin = _ref7.skin,
skin = _ref7$skin === void 0 ? 'dark' : _ref7$skin;
var className = iconSt(iconsClasses.completeIcon, {
skin: skin
});
var standardSkin = /*#__PURE__*/React.createElement("div", {
className: className
});
var darkSkin = /*#__PURE__*/React.createElement(StatusCompleteFilled, {
className: className
});
return skin === 'standard' ? standardSkin : darkSkin;
});
_defineProperty(HorizontalTimeline, "defaultProps", {
skin: 'dark',
alignLabel: 'center',
items: []
});
HorizontalTimeline.propTypes = {
/** Controls the style of the component.*/
skin: PropTypes.oneOf(['dark', 'standard']),
/** Aligns the labels of items. */
alignLabel: PropTypes.oneOf(['center', 'start']),
/** Applied as data-hook HTML attribute that can be used in the tests */
dataHook: PropTypes.string,
/** A css class to be applied to the component's root element */
className: PropTypes.string,
/**
* Timeline items
* * `skin` - Controls line and text color (deprecated).
* * `line ` - Affects the line type, can be one of: 'filled' | 'dashed'.
* * `label` - Text displayed below the icon.
* * `icon ` - An icon representing a timeline item.
* * `width ` - The width of the timeline item, can be percentage or pixels.
* * `labelEllipsis ` - Set ellipsis for item's label .
*/
items: PropTypes.arrayOf(PropTypes.shape({
/** item's skin (deprecated)*/
skin: PropTypes.oneOf(['dark', 'light']),
/** item's line type */
line: PropTypes.oneOf(['filled', 'dashed']),
/** item's text */
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
/** item's icon */
icon: PropTypes.node,
/** custom width for item */
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/** Ellipsis for item's label */
labelEllipsis: PropTypes.bool
}))
};
export default HorizontalTimeline;