@razorpay/blade
Version:
The Design System that powers Razorpay
148 lines (144 loc) • 7.11 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default from 'react';
import { useVerifyInsideCard } from './CardContext.js';
import { ComponentIds } from './Card.js';
import '../Button/index.js';
import '../Divider/index.js';
import '../Box/BaseBox/index.js';
import '../Typography/index.js';
import '../../utils/metaAttribute/index.js';
import '../../utils/assignWithoutSideEffects/index.js';
import { useIsMobile } from '../../utils/useIsMobile.js';
import '../../utils/logger/index.js';
import { useVerifyAllowedChildren } from '../../utils/useVerifyAllowedChildren/useVerifyAllowedChildren.js';
import '../../utils/makeAnalyticsAttribute/index.js';
import { jsxs, jsx } from 'react/jsx-runtime';
import { throwBladeError } from '../../utils/logger/logger.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 { Divider } from '../Divider/Divider.js';
import { assignWithoutSideEffects } from '../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
import { Text } from '../Typography/Text/Text.js';
import Button from '../Button/Button/Button.js';
var _excluded = ["children", "testID", "marginTop", "paddingTop", "showDivider"],
_excluded2 = ["title", "subtitle"],
_excluded3 = ["actions"];
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 _CardFooter = function _CardFooter(_ref) {
var _footerChildrensArray, _footerChildrensArray2;
var children = _ref.children,
testID = _ref.testID,
_ref$marginTop = _ref.marginTop,
marginTop = _ref$marginTop === void 0 ? 'spacing.4' : _ref$marginTop,
_ref$paddingTop = _ref.paddingTop,
paddingTop = _ref$paddingTop === void 0 ? 'spacing.4' : _ref$paddingTop,
_ref$showDivider = _ref.showDivider,
showDivider = _ref$showDivider === void 0 ? true : _ref$showDivider,
props = _objectWithoutProperties(_ref, _excluded);
var isMobile = useIsMobile();
useVerifyInsideCard('CardFooter');
useVerifyAllowedChildren({
children: children,
componentName: 'CardFooter',
allowedComponents: [ComponentIds.CardFooterLeading, ComponentIds.CardFooterTrailing]
});
var footerChildrensArray = React__default.Children.toArray(children);
if (false) {
if (! /*#__PURE__*/React__default.isValidElement(footerChildrensArray[0])) {
throwBladeError({
message: "Invalid React Element ".concat(footerChildrensArray),
moduleName: 'CardFooter'
});
}
}
// the reason why we are checking for actions here is, because we want the footerTrailing
// to always be aligned to the right
// if we don't check for action here, and if we do not have footerTrailing and only footerLeading
// then the content of footerLeading will be justified to the end.
var baseBoxJustifyContent = footerChildrensArray.length === 2 || !((_footerChildrensArray = footerChildrensArray[0]) !== null && _footerChildrensArray !== void 0 && (_footerChildrensArray2 = _footerChildrensArray.props) !== null && _footerChildrensArray2 !== void 0 && _footerChildrensArray2.actions) ? 'space-between' : 'flex-end';
return /*#__PURE__*/jsxs(BaseBox, _objectSpread(_objectSpread(_objectSpread({
marginTop: marginTop
}, metaAttribute({
name: MetaConstants.CardFooter,
testID: testID
})), makeAnalyticsAttribute(props)), {}, {
children: [showDivider ? /*#__PURE__*/jsx(Divider, {}) : null, /*#__PURE__*/jsx(BaseBox, {
paddingTop: paddingTop,
display: "flex",
flexDirection: isMobile ? 'column' : 'row',
justifyContent: baseBoxJustifyContent,
alignItems: isMobile ? 'stretch' : 'center',
children: children
})]
}));
};
var CardFooter = /*#__PURE__*/assignWithoutSideEffects(_CardFooter, {
componentId: ComponentIds.CardFooter
});
var _CardFooterLeading = function _CardFooterLeading(_ref2) {
var title = _ref2.title,
subtitle = _ref2.subtitle,
rest = _objectWithoutProperties(_ref2, _excluded2);
useVerifyInsideCard('CardFooterLeading');
return /*#__PURE__*/jsxs(BaseBox, _objectSpread(_objectSpread({
textAlign: 'left'
}, makeAnalyticsAttribute(rest)), {}, {
children: [title && /*#__PURE__*/jsx(Text, {
color: "surface.text.gray.normal",
size: "medium",
weight: "semibold",
children: title
}), subtitle && /*#__PURE__*/jsx(Text, {
color: "surface.text.gray.subtle",
size: "small",
weight: "regular",
children: subtitle
})]
}));
};
var CardFooterLeading = /*#__PURE__*/assignWithoutSideEffects(_CardFooterLeading, {
componentId: ComponentIds.CardFooterLeading
});
var _CardFooterTrailing = function _CardFooterTrailing(_ref3) {
var actions = _ref3.actions,
rest = _objectWithoutProperties(_ref3, _excluded3);
var isMobile = useIsMobile();
useVerifyInsideCard('CardFooterTrailing');
return /*#__PURE__*/jsxs(BaseBox, _objectSpread(_objectSpread({
display: "flex",
flexDirection: "row",
alignSelf: isMobile ? 'auto' : 'center',
marginTop: isMobile ? 'spacing.5' : 'spacing.0',
marginLeft: isMobile ? 'spacing.0' : 'spacing.5'
}, makeAnalyticsAttribute(rest)), {}, {
children: [/*#__PURE__*/jsx(BaseBox, {
flexGrow: 1,
children: actions !== null && actions !== void 0 && actions.secondary ? /*#__PURE__*/jsx(Button, _objectSpread(_objectSpread({
isFullWidth: true,
size: "medium",
variant: "secondary"
}, actions.secondary), {}, {
children: actions.secondary.text
})) : null
}), /*#__PURE__*/jsx(BaseBox, {
marginLeft: "spacing.5"
}), /*#__PURE__*/jsx(BaseBox, {
flexGrow: 1,
children: actions !== null && actions !== void 0 && actions.primary ? /*#__PURE__*/jsx(Button, _objectSpread(_objectSpread({
isFullWidth: true,
size: "medium"
}, actions.primary), {}, {
children: actions.primary.text
})) : null
})]
}));
};
var CardFooterTrailing = /*#__PURE__*/assignWithoutSideEffects(_CardFooterTrailing, {
componentId: ComponentIds.CardFooterTrailing
});
export { CardFooter, CardFooterLeading, CardFooterTrailing };
//# sourceMappingURL=CardFooter.js.map