@razorpay/blade
Version:
The Design System that powers Razorpay
153 lines (150 loc) • 6.47 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default from 'react';
import styled, { keyframes, css } from 'styled-components';
import usePresence from 'use-presence';
import '../BladeProvider/index.js';
import { useWindowSize } from '../../utils/useWindowSize.js';
import '../../utils/index.js';
import '../../utils/makeMotionTime/index.web.js';
import '../../utils/metaAttribute/index.js';
import '../../utils/assignWithoutSideEffects/index.js';
import { componentZIndices } from '../../utils/componentZIndices.js';
import { jsx, jsxs } from 'react/jsx-runtime';
import useTheme from '../BladeProvider/useTheme.js';
import { makeMotionTime } from '../../utils/makeMotionTime/makeMotionTime.web.js';
import { metaAttribute } from '../../utils/metaAttribute/metaAttribute.web.js';
import { MetaConstants } from '../../utils/metaAttribute/metaConstants.js';
import { makeSpace } from '../../utils/makeSpace/makeSpace.js';
import { assignWithoutSideEffects } from '../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
var _excluded = ["show", "children"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var scaleIn = /*#__PURE__*/keyframes(["from{fill-opacity:0;}to{fill-opacity:1;}"]);
var fadeOut = /*#__PURE__*/keyframes(["from{fill-opacity:1;}to{fill-opacity:0;}"]);
var pulsingAnimation = /*#__PURE__*/keyframes(["0%{opacity:0.5;}100%{opacity:1;}"]);
var AnimatedFade = /*#__PURE__*/styled.rect.withConfig({
displayName: "TourMaskweb__AnimatedFade",
componentId: "grcs9t-0"
})(function (_ref) {
var animationType = _ref.animationType;
return animationType === null ? '' : css(["", ""], animationType);
});
var StyledPlusing = /*#__PURE__*/styled.rect.withConfig({
displayName: "TourMaskweb__StyledPlusing",
componentId: "grcs9t-1"
})(function (_ref2) {
var animationType = _ref2.animationType;
return animationType === null ? '' : css(["", ""], animationType);
});
var FadeRect = /*#__PURE__*/React__default.memo(function (_ref3) {
var show = _ref3.show,
children = _ref3.children,
rest = _objectWithoutProperties(_ref3, _excluded);
var _useTheme = useTheme(),
theme = _useTheme.theme;
var duration = theme.motion.duration.gentle;
var enter = /*#__PURE__*/css(["animation:", " ", " ", ";animation-fill-mode:forwards;"], scaleIn, makeMotionTime(duration), theme.motion.easing.entrance);
var exit = /*#__PURE__*/css(["animation:", " ", " ", ";animation-fill-mode:forwards;"], fadeOut, makeMotionTime(duration), theme.motion.easing.exit);
var _usePresence = usePresence(Boolean(show), {
transitionDuration: duration,
initialEnter: false
}),
isVisible = _usePresence.isVisible;
return (
/*#__PURE__*/
// @ts-expect-error styled compoennt types are different from react types
jsx(AnimatedFade, _objectSpread(_objectSpread({
animationType: isVisible ? enter : exit
}, rest), {}, {
children: children
}))
);
});
var PulsingRect = /*#__PURE__*/React__default.memo(function (props) {
var pulsing = /*#__PURE__*/css(["animation:", " 2s;animation-iteration-count:infinite;animation-direction:alternate;"], pulsingAnimation);
return (
/*#__PURE__*/
// @ts-expect-error styled compoennt types are different from react types
jsx(StyledPlusing, _objectSpread({
animationType: pulsing
}, props))
);
});
var absoluteFill = {
position: 'fixed',
top: 0,
left: 0,
bottom: 0,
right: 0,
zIndex: componentZIndices.tourMask
};
var _SpotlightPopoverTourMask = function _SpotlightPopoverTourMask(_ref4) {
var padding = _ref4.padding,
size = _ref4.size,
isTransitioning = _ref4.isTransitioning;
var _useTheme2 = useTheme(),
theme = _useTheme2.theme;
var _useWindowSize = useWindowSize(),
windowWidth = _useWindowSize.width,
windowHeight = _useWindowSize.height;
var width = size.width + padding;
var height = size.height + padding;
var x = size.x - (width - size.width) / 2;
var y = size.y - (height - size.height) / 2;
var borderWidth = theme.spacing[1];
var borderRadius = theme.spacing[2];
var isSizeZero = size.width === 0 || size.height === 0;
return /*#__PURE__*/jsxs("svg", _objectSpread(_objectSpread({
style: absoluteFill,
viewBox: "0 0 ".concat(windowWidth, " ").concat(windowHeight),
fill: "none",
stroke: "none"
}, metaAttribute({
name: MetaConstants.TourMask
})), {}, {
children: [/*#__PURE__*/jsx(PulsingRect, {
x: x + borderWidth / 2,
y: y + borderWidth / 2,
width: width - borderWidth,
height: height - borderWidth,
stroke: theme.colors.surface.background.primary.intense,
strokeWidth: makeSpace(borderWidth),
rx: borderRadius - 1,
ry: borderRadius - 1,
fill: "transparent",
opacity: isSizeZero ? 0 : 1
}), /*#__PURE__*/jsxs("mask", {
id: "tour-mask",
x: 0,
y: 0,
height: "100%",
width: "100%",
stroke: "none",
children: [/*#__PURE__*/jsx("rect", {
height: "100%",
width: "100%",
fill: "#fff"
}), !isSizeZero && /*#__PURE__*/jsx(FadeRect, {
show: !isTransitioning,
x: x,
y: y,
width: width,
height: height,
rx: borderRadius,
ry: borderRadius,
fill: "#000"
})]
}), /*#__PURE__*/jsx("rect", {
height: "100%",
width: "100%",
mask: "url(#tour-mask)",
fill: theme.colors.overlay.background.subtle
})]
}));
};
var SpotlightPopoverTourMask = /*#__PURE__*/assignWithoutSideEffects( /*#__PURE__*/React__default.memo(_SpotlightPopoverTourMask), {
displayName: 'TourMask'
});
export { SpotlightPopoverTourMask };
//# sourceMappingURL=TourMask.web.js.map