@rc-component/trigger
Version:
base abstract trigger component for react
69 lines (64 loc) • 2.41 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Arrow;
var _classnames = _interopRequireDefault(require("classnames"));
var React = _interopRequireWildcard(require("react"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function Arrow(props) {
const {
prefixCls,
align,
arrow,
arrowPos
} = props;
const {
className,
content
} = arrow || {};
const {
x = 0,
y = 0
} = arrowPos;
const arrowRef = React.useRef();
// Skip if no align
if (!align || !align.points) {
return null;
}
const alignStyle = {
position: 'absolute'
};
// Skip if no need to align
if (align.autoArrow !== false) {
const popupPoints = align.points[0];
const targetPoints = align.points[1];
const popupTB = popupPoints[0];
const popupLR = popupPoints[1];
const targetTB = targetPoints[0];
const targetLR = targetPoints[1];
// Top & Bottom
if (popupTB === targetTB || !['t', 'b'].includes(popupTB)) {
alignStyle.top = y;
} else if (popupTB === 't') {
alignStyle.top = 0;
} else {
alignStyle.bottom = 0;
}
// Left & Right
if (popupLR === targetLR || !['l', 'r'].includes(popupLR)) {
alignStyle.left = x;
} else if (popupLR === 'l') {
alignStyle.left = 0;
} else {
alignStyle.right = 0;
}
}
return /*#__PURE__*/React.createElement("div", {
ref: arrowRef,
className: (0, _classnames.default)(`${prefixCls}-arrow`, className),
style: alignStyle
}, content);
}
;