Mask.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  3. import _typeof from "@babel/runtime/helpers/esm/typeof";
  4. import React from 'react';
  5. import classNames from 'classnames';
  6. import Portal from '@rc-component/portal';
  7. import useId from "rc-util/es/hooks/useId";
  8. var COVER_PROPS = {
  9. fill: 'transparent',
  10. pointerEvents: 'auto'
  11. };
  12. var Mask = function Mask(props) {
  13. var prefixCls = props.prefixCls,
  14. rootClassName = props.rootClassName,
  15. pos = props.pos,
  16. showMask = props.showMask,
  17. _props$style = props.style,
  18. style = _props$style === void 0 ? {} : _props$style,
  19. _props$fill = props.fill,
  20. fill = _props$fill === void 0 ? "rgba(0,0,0,0.5)" : _props$fill,
  21. open = props.open,
  22. animated = props.animated,
  23. zIndex = props.zIndex,
  24. disabledInteraction = props.disabledInteraction;
  25. var id = useId();
  26. var maskId = "".concat(prefixCls, "-mask-").concat(id);
  27. var mergedAnimated = _typeof(animated) === 'object' ? animated === null || animated === void 0 ? void 0 : animated.placeholder : animated;
  28. var isSafari = typeof navigator !== 'undefined' && /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  29. var maskRectSize = isSafari ? {
  30. width: '100%',
  31. height: '100%'
  32. } : {
  33. width: '100vw',
  34. height: '100vh'
  35. };
  36. return /*#__PURE__*/React.createElement(Portal, {
  37. open: open,
  38. autoLock: true
  39. }, /*#__PURE__*/React.createElement("div", {
  40. className: classNames("".concat(prefixCls, "-mask"), rootClassName),
  41. style: _objectSpread({
  42. position: 'fixed',
  43. left: 0,
  44. right: 0,
  45. top: 0,
  46. bottom: 0,
  47. zIndex: zIndex,
  48. pointerEvents: pos && !disabledInteraction ? 'none' : 'auto'
  49. }, style)
  50. }, showMask ? /*#__PURE__*/React.createElement("svg", {
  51. style: {
  52. width: '100%',
  53. height: '100%'
  54. }
  55. }, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("mask", {
  56. id: maskId
  57. }, /*#__PURE__*/React.createElement("rect", _extends({
  58. x: "0",
  59. y: "0"
  60. }, maskRectSize, {
  61. fill: "white"
  62. })), pos && /*#__PURE__*/React.createElement("rect", {
  63. x: pos.left,
  64. y: pos.top,
  65. rx: pos.radius,
  66. width: pos.width,
  67. height: pos.height,
  68. fill: "black",
  69. className: mergedAnimated ? "".concat(prefixCls, "-placeholder-animated") : ''
  70. }))), /*#__PURE__*/React.createElement("rect", {
  71. x: "0",
  72. y: "0",
  73. width: "100%",
  74. height: "100%",
  75. fill: fill,
  76. mask: "url(#".concat(maskId, ")")
  77. }), pos && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("rect", _extends({}, COVER_PROPS, {
  78. x: "0",
  79. y: "0",
  80. width: "100%",
  81. height: pos.top
  82. })), /*#__PURE__*/React.createElement("rect", _extends({}, COVER_PROPS, {
  83. x: "0",
  84. y: "0",
  85. width: pos.left,
  86. height: "100%"
  87. })), /*#__PURE__*/React.createElement("rect", _extends({}, COVER_PROPS, {
  88. x: "0",
  89. y: pos.top + pos.height,
  90. width: "100%",
  91. height: "calc(100vh - ".concat(pos.top + pos.height, "px)")
  92. })), /*#__PURE__*/React.createElement("rect", _extends({}, COVER_PROPS, {
  93. x: pos.left + pos.width,
  94. y: "0",
  95. width: "calc(100vw - ".concat(pos.left + pos.width, "px)"),
  96. height: "100%"
  97. })))) : null));
  98. };
  99. export default Mask;