organism-react-onboarding
Version:
Create guided tours with react.
105 lines (89 loc) • 3.07 kB
JavaScript
import _extends from "reshow-runtime/es/helpers/extends";
import _objectSpread from "reshow-runtime/es/helpers/objectSpread2";
import _objectWithoutProperties from "reshow-runtime/es/helpers/objectWithoutProperties";
import _classCallCheck from "reshow-runtime/es/helpers/classCallCheck";
import _createClass from "reshow-runtime/es/helpers/createClass";
import _assertThisInitialized from "reshow-runtime/es/helpers/assertThisInitialized";
import _inherits from "reshow-runtime/es/helpers/inherits";
import _createSuper from "reshow-runtime/es/helpers/createSuper";
import _defineProperty from "reshow-runtime/es/helpers/defineProperty";
var _excluded = ["targetEl", "styles", "style", "size"];
import React from "react";
import getOffset from "getoffset";
import { mixClass, reactStyle, Circular } from "react-atomic-molecule";
import { PopupFloatEl } from "organism-react-popup";
var GROUP_KEY = "react-onboarding";
var StepNumber = /*#__PURE__*/function (_PopupFloatEl) {
_inherits(StepNumber, _PopupFloatEl);
var _super = _createSuper(StepNumber);
function StepNumber() {
var _this;
_classCallCheck(this, StepNumber);
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), "calPos", function () {
var _this$props = _this.props,
size = _this$props.size,
targetEl = _this$props.targetEl;
var pos = getOffset(targetEl);
var locSize = size / 2 * 1.75;
var top = pos.top - locSize;
var left = pos.left - locSize;
if (top < 0) {
top = 0;
}
if (left < 0) {
left = 0;
}
var width = size;
var height = size;
var result = {
top: top,
left: left,
width: width,
height: height
};
return result;
});
return _this;
}
_createClass(StepNumber, [{
key: "renderOverlay",
value: function renderOverlay(props) {
var targetEl = props.targetEl,
styles = props.styles,
style = props.style,
size = props.size,
others = _objectWithoutProperties(props, _excluded);
var thisStyles = [reactStyle(_objectSpread(_objectSpread({
lineHeight: size + "px"
}, Styles.container), style), null, false), styles];
var classes = mixClass(props.name, "button");
return /*#__PURE__*/React.createElement(Circular, _extends({}, others, {
className: classes,
styles: thisStyles
}));
}
}]);
return StepNumber;
}(PopupFloatEl);
_defineProperty(StepNumber, "defaultProps", {
name: GROUP_KEY + "-step-number",
group: GROUP_KEY,
size: 25
});
var Styles = {
container: {
position: "absolute",
zIndex: 999999,
backgroundColor: "rgba(255,0,0,.9)",
padding: 0,
border: "3px solid #fff",
boxSizing: "content-box",
fontSize: "1.5rem",
color: "#fff"
}
};
export default StepNumber;