@razorpay/blade
Version:
The Design System that powers Razorpay
132 lines (127 loc) • 6.57 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import React__default from 'react';
import { getActionListContainerRole, getActionListItemWrapperRole } from './getA11yRoles.js';
import { getActionListProperties } from './actionListUtils.js';
import { ActionListVirtualizedBox, ActionListBox } from './ActionListBox.web.js';
import { componentIds } from './componentIds.js';
import { ActionListNoResults } from './ActionListNoResults.js';
import { useDropdown } from '../Dropdown/useDropdown.js';
import { useBottomSheetContext } from '../BottomSheet/BottomSheetContext.js';
import '../../utils/makeAccessible/index.js';
import '../../utils/assignWithoutSideEffects/index.js';
import '../Box/BaseBox/index.js';
import '../../utils/metaAttribute/index.js';
import { dropdownComponentIds } from '../Dropdown/dropdownComponentIds.js';
import '../../utils/makeAnalyticsAttribute/index.js';
import { jsx } from 'react/jsx-runtime';
import { makeAnalyticsAttribute } from '../../utils/makeAnalyticsAttribute/makeAnalyticsAttribute.js';
import { BaseBox } from '../Box/BaseBox/BaseBox.web.js';
import { makeAccessible } from '../../utils/makeAccessible/makeAccessible.web.js';
import { metaAttribute } from '../../utils/metaAttribute/metaAttribute.web.js';
import { MetaConstants } from '../../utils/metaAttribute/metaConstants.js';
import { assignWithoutSideEffects } from '../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
var _excluded = ["children", "testID", "isVirtualized"];
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 _ActionList = function _ActionList(_ref) {
var children = _ref.children,
testID = _ref.testID,
isVirtualized = _ref.isVirtualized,
rest = _objectWithoutProperties(_ref, _excluded);
var _useDropdown = useDropdown(),
setOptions = _useDropdown.setOptions,
actionListItemRef = _useDropdown.actionListItemRef,
selectionType = _useDropdown.selectionType,
dropdownBaseId = _useDropdown.dropdownBaseId,
dropdownTriggerer = _useDropdown.dropdownTriggerer,
hasFooterAction = _useDropdown.hasFooterAction,
filteredValues = _useDropdown.filteredValues;
var ActionListBox$1 = isVirtualized ? ActionListVirtualizedBox : ActionListBox;
var _useBottomSheetContex = useBottomSheetContext(),
isInBottomSheet = _useBottomSheetContex.isInBottomSheet;
var _React$useMemo = React__default.useMemo(function () {
return getActionListProperties(children);
}, [children]),
sectionData = _React$useMemo.sectionData,
childrenWithId = _React$useMemo.childrenWithId,
actionListOptions = _React$useMemo.actionListOptions;
React__default.useEffect(function () {
setOptions(actionListOptions);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [actionListOptions]);
if (filteredValues.length <= 0 && dropdownTriggerer === dropdownComponentIds.triggers.AutoComplete) {
return /*#__PURE__*/jsx(ActionListNoResults, {});
}
var actionListContainerRole = getActionListContainerRole(hasFooterAction, dropdownTriggerer);
var actionListItemWrapperRole = getActionListItemWrapperRole(hasFooterAction, dropdownTriggerer);
var isMultiSelectable = selectionType === 'multiple';
// If we are inside BottomSheet, we don't render The StyledActionList wrapper
// This is to ensure:
// 1. We don't render the box wrapper styles which includes shadows, padding, border etc
// 2. to ensure GorhomBottomSheetSectionList works as expected, if we add extra wrappers GorhomBottomSheet won't render the content inside
// NOTE: That this also means inside BottomSheet, ActionList won't render any ActionListHeader or Footer.
return isInBottomSheet ? /*#__PURE__*/jsx(ActionListBox$1, _objectSpread({
isInBottomSheet: isInBottomSheet,
actionListItemWrapperRole: actionListItemWrapperRole,
childrenWithId: childrenWithId,
sectionData: sectionData,
isMultiSelectable: isMultiSelectable,
ref: actionListItemRef
}, makeAnalyticsAttribute(rest))) : /*#__PURE__*/jsx(BaseBox, _objectSpread(_objectSpread(_objectSpread(_objectSpread({
id: "".concat(dropdownBaseId, "-actionlist")
}, makeAccessible({
role: actionListContainerRole,
multiSelectable: actionListContainerRole === 'listbox' ? isMultiSelectable : undefined,
labelledBy: "".concat(dropdownBaseId, "-label")
})), metaAttribute({
name: MetaConstants.ActionList,
testID: testID
})), makeAnalyticsAttribute(rest)), {}, {
children: /*#__PURE__*/jsx(ActionListBox$1, {
isInBottomSheet: isInBottomSheet,
actionListItemWrapperRole: actionListItemWrapperRole,
childrenWithId: childrenWithId,
sectionData: sectionData,
isMultiSelectable: isMultiSelectable,
ref: actionListItemRef
})
}));
};
/**
* ### ActionList
*
* List of multiple actionable items. Can be used as menu items inside `Dropdown`,
* `BottomSheet` and as selectable items when combined with `SelectInput`
*
* #### Usage
*
* ```jsx
* <Dropdown>
* <SelectInput label="Select Action" />
* <DropdownOverlay>
* <DropdownHeader title="Header Title" />
* <ActionList>
* <ActionListItem
* title="Home"
* value="home"
* leading={<ActionListItemIcon icon={HomeIcon} />}
* />
* <ActionListItem
* title="Pricing"
* value="pricing"
* leading={<ActionListItemAsset src="https://flagcdn.com/w20/in.png" alt="India Flag" />}
* />
* </ActionList>
* <DropdownFooter><Button>Apply</Button></DropdownFooter>
* </DropdownOverlay>
* </Dropdown>
* ```
*
*/
var ActionList = /*#__PURE__*/assignWithoutSideEffects( /*#__PURE__*/React__default.memo(_ActionList), {
displayName: componentIds.ActionList,
componentId: componentIds.ActionList
});
export { ActionList };
//# sourceMappingURL=ActionList.js.map