@razorpay/blade
Version:
The Design System that powers Razorpay
101 lines (98 loc) • 5.12 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default from 'react';
import { ComponentIds } from './componentIds.js';
import { useBottomSheetContext } from './BottomSheetContext.js';
import { useIsomorphicLayoutEffect } from '../../utils/useIsomorphicLayoutEffect.js';
import '../Box/BaseBox/index.js';
import { componentIds } from '../ActionList/componentIds.js';
import '../../utils/assignWithoutSideEffects/index.js';
import '../../utils/metaAttribute/index.js';
import '../../utils/isValidAllowedChildren/index.js';
import '../../utils/makeAnalyticsAttribute/index.js';
import { jsx } from 'react/jsx-runtime';
import { isValidAllowedChildren } from '../../utils/isValidAllowedChildren/isValidAllowedChildren.js';
import { BaseBox } from '../Box/BaseBox/BaseBox.web.js';
import { metaAttribute } from '../../utils/metaAttribute/metaAttribute.web.js';
import { MetaConstants } from '../../utils/metaAttribute/metaConstants.js';
import { makeAnalyticsAttribute } from '../../utils/makeAnalyticsAttribute/makeAnalyticsAttribute.js';
import { assignWithoutSideEffects } from '../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
var _excluded = ["children", "padding", "overflow"];
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 bodyStyles = {
WebkitTapHighlightColor: 'revert',
WebkitTouchCallout: 'revert',
WebkitUserSelect: 'auto',
overscrollBehavior: 'contain',
WebkitOverflowScrolling: 'touch',
userSelect: 'auto',
touchAction: 'none'
};
var _BottomSheetBody = function _BottomSheetBody(_ref) {
var children = _ref.children,
_ref$padding = _ref.padding,
padding = _ref$padding === void 0 ? 'spacing.5' : _ref$padding,
_ref$overflow = _ref.overflow,
overflow = _ref$overflow === void 0 ? 'auto' : _ref$overflow,
dataAnalyticsProps = _objectWithoutProperties(_ref, _excluded);
var _useBottomSheetContex = useBottomSheetContext(),
scrollRef = _useBottomSheetContex.scrollRef,
setContentHeight = _useBottomSheetContex.setContentHeight,
setHasBodyPadding = _useBottomSheetContex.setHasBodyPadding,
isOpen = _useBottomSheetContex.isOpen,
bind = _useBottomSheetContex.bind;
var contentRef = React__default.useRef(null);
var _React$useState = React__default.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
bottomSheetHasActionList = _React$useState2[0],
setBottomSheetHasActionList = _React$useState2[1];
useIsomorphicLayoutEffect(function () {
if (!contentRef.current) return;
setContentHeight(contentRef.current.getBoundingClientRect().height);
}, [contentRef, isOpen, children]);
React__default.useEffect(function () {
setBottomSheetHasActionList(false);
React__default.Children.forEach(children, function (child) {
if (isValidAllowedChildren(child, componentIds.ActionList)) {
setBottomSheetHasActionList(true);
}
});
}, [children]);
React__default.useEffect(function () {
if (padding === 'spacing.0') {
setHasBodyPadding(false);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [padding]);
return /*#__PURE__*/jsx(BaseBox, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, metaAttribute({
testID: 'bottomsheet-body',
name: MetaConstants.BottomSheetBody
})), makeAnalyticsAttribute(dataAnalyticsProps)), {}, {
ref: scrollRef,
flexGrow: 1,
flexShrink: 1,
style: bodyStyles,
overflow: overflow
// Passing isContentDragging to bind()
// Inside the useDrag() hook this will let us know if user is dragging the content or not
}, bind === null || bind === void 0 ? void 0 : bind({
isContentDragging: true
})), {}, {
children: /*#__PURE__*/jsx(BaseBox, {
paddingLeft: bottomSheetHasActionList ? 'spacing.3' : padding,
paddingRight: bottomSheetHasActionList ? 'spacing.3' : padding,
paddingTop: bottomSheetHasActionList ? 'spacing.3' : padding,
paddingBottom: bottomSheetHasActionList ? 'spacing.3' : padding,
ref: contentRef,
overflow: overflow,
children: children
})
}));
};
var BottomSheetBody = /*#__PURE__*/assignWithoutSideEffects(_BottomSheetBody, {
componentId: ComponentIds.BottomSheetBody
});
export { BottomSheetBody };
//# sourceMappingURL=BottomSheetBody.web.js.map