UNPKG

wix-style-react

Version:
107 lines (92 loc) 4.96 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; 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"; 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 { FontUpgradeContext } from '../FontUpgrade/context'; import Text from '../Text'; import { classes, st, vars } from './TimelineItem.st.css'; import { dataHooks } from './constants'; import { isString } from '../utils/StringUtils'; /** A timeline item is a display of a timeline event */ var TimelineItem = /*#__PURE__*/function (_React$PureComponent) { _inherits(TimelineItem, _React$PureComponent); var _super = _createSuper(TimelineItem); function TimelineItem() { _classCallCheck(this, TimelineItem); return _super.apply(this, arguments); } _createClass(TimelineItem, [{ key: "render", value: function render() { var _this$props = this.props, idx = _this$props.idx, item = _this$props.item, dataHook = _this$props.dataHook, gap = _this$props.gap; return /*#__PURE__*/React.createElement("li", { className: classes.event, "data-hook": dataHook }, /*#__PURE__*/React.createElement(FontUpgradeContext.Consumer, null, function (_ref) { var isMadefor = _ref.active; return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { className: classes.prefix }, item.customPrefix ? /*#__PURE__*/React.createElement("div", { "data-hook": "".concat(dataHooks.timelineBulletIndicator, "-").concat(idx) }, item.customPrefix) : /*#__PURE__*/React.createElement("div", { "data-hook": "".concat(dataHooks.timelineDefaultPrefix, "-").concat(idx), className: classes.defaultIndicator }), /*#__PURE__*/React.createElement("div", { className: classes.line })), /*#__PURE__*/React.createElement("div", { className: st(classes.label, { withSuffix: !!item.suffix }), style: _defineProperty({}, vars.marginBottom, gap) }, isString(item.label) ? /*#__PURE__*/React.createElement(Text, { dataHook: "".concat(dataHooks.timelineLabel, "-").concat(idx), weight: isMadefor ? 'thin' : 'normal', size: "small", className: classes.labelText }, item.label) : item.label, item.labelAction ? /*#__PURE__*/React.createElement("div", { className: classes.labelAction, "data-hook": "".concat(dataHooks.timelineLabelAction, "-").concat(idx) }, item.labelAction) : null), item.suffix ? /*#__PURE__*/React.createElement("div", { className: classes.suffix, "data-hook": "".concat(dataHooks.timelineSuffix, "-").concat(idx) }, isString(item.suffix) ? /*#__PURE__*/React.createElement(Text, { dataHook: "".concat(dataHooks.timelineTextSuffix, "-").concat(idx), weight: isMadefor ? 'thin' : 'normal', light: true, secondary: true, size: "small" }, item.suffix) : item.suffix) : null); })); } }]); return TimelineItem; }(React.PureComponent); TimelineItem.displayName = 'TimelineItem'; TimelineItem.propTypes = { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: PropTypes.string, /** timeline event item index*/ idx: PropTypes.number, /** timeline event item */ item: PropTypes.shape({ /** event text - could be a node or a string */ label: PropTypes.node, /** action element in the end of event text */ labelAction: PropTypes.node, /** TODO: still in development. custom bullet element like icon or avatar */ customPrefix: PropTypes.node, /** suffix text or element placed on the right */ suffix: PropTypes.oneOfType([PropTypes.node, PropTypes.string]) }).isRequired }; export default TimelineItem;