@razorpay/blade
Version:
The Design System that powers Razorpay
97 lines (94 loc) • 4.72 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import 'react';
import { getActionListContainerRole } from '../ActionList/getA11yRoles.js';
import '../Link/BaseLink/index.js';
import { useDropdown } from './useDropdown.js';
import { dropdownComponentIds } from './dropdownComponentIds.js';
import '../../utils/assignWithoutSideEffects/index.js';
import '../../utils/makeAnalyticsAttribute/index.js';
import { jsx } from 'react/jsx-runtime';
import BaseLink from '../Link/BaseLink/BaseLink.js';
import { makeAnalyticsAttribute } from '../../utils/makeAnalyticsAttribute/makeAnalyticsAttribute.js';
import { assignWithoutSideEffects } from '../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
var _excluded = ["children", "icon", "iconPosition", "onClick", "onBlur", "onKeyDown", "isDisabled", "href", "target", "rel", "accessibilityLabel", "size", "testID", "hitSlop", "htmlTitle"];
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 _DropdownLink = function _DropdownLink(_ref) {
var children = _ref.children,
icon = _ref.icon,
_ref$iconPosition = _ref.iconPosition,
iconPosition = _ref$iconPosition === void 0 ? 'left' : _ref$iconPosition,
_onClick = _ref.onClick,
_onBlur = _ref.onBlur,
_onKeyDown = _ref.onKeyDown,
isDisabled = _ref.isDisabled,
href = _ref.href,
target = _ref.target,
rel = _ref.rel,
accessibilityLabel = _ref.accessibilityLabel,
_ref$size = _ref.size,
size = _ref$size === void 0 ? 'medium' : _ref$size,
testID = _ref.testID,
hitSlop = _ref.hitSlop,
htmlTitle = _ref.htmlTitle,
props = _objectWithoutProperties(_ref, _excluded);
var _useDropdown = useDropdown(),
onTriggerClick = _useDropdown.onTriggerClick,
onTriggerKeydown = _useDropdown.onTriggerKeydown,
dropdownBaseId = _useDropdown.dropdownBaseId,
isOpen = _useDropdown.isOpen,
activeIndex = _useDropdown.activeIndex,
hasFooterAction = _useDropdown.hasFooterAction,
triggererRef = _useDropdown.triggererRef;
return (
/*#__PURE__*/
// Using BaseButton here to avoid exporting onBlur and onKeyDown from Button
// If in future we decide to export onBlur and onKeyDown on Button, this can be replaced with Button
jsx(BaseLink, _objectSpread(_objectSpread(_objectSpread(_objectSpread({
variant: "button"
}, icon ? {
icon: icon,
children: children
} : {
children: children
}), {}, {
iconPosition: iconPosition,
size: size,
testID: testID,
hitSlop: hitSlop,
htmlTitle: htmlTitle,
isDisabled: isDisabled
}, props), makeAnalyticsAttribute(props)), {}, {
ref: triggererRef,
accessibilityProps: {
label: accessibilityLabel,
hasPopup: getActionListContainerRole(hasFooterAction, 'DropdownButton'),
expanded: isOpen,
controls: "".concat(dropdownBaseId, "-actionlist"),
activeDescendant: activeIndex >= 0 ? "".concat(dropdownBaseId, "-").concat(activeIndex) : undefined
},
onClick: function onClick(e) {
onTriggerClick();
// Setting it for web fails it on native typecheck and vice versa
_onClick === null || _onClick === void 0 ? void 0 : _onClick(e);
},
onBlur: function onBlur(e) {
// Setting it for web fails it on native typecheck and vice versa
_onBlur === null || _onBlur === void 0 ? void 0 : _onBlur(e);
},
onKeyDown: function onKeyDown(e) {
onTriggerKeydown === null || onTriggerKeydown === void 0 ? void 0 : onTriggerKeydown({
event: e
});
// Setting it for web fails it on native typecheck and vice versa
_onKeyDown === null || _onKeyDown === void 0 ? void 0 : _onKeyDown(e);
}
}))
);
};
var DropdownLink = /*#__PURE__*/assignWithoutSideEffects(_DropdownLink, {
componentId: dropdownComponentIds.triggers.DropdownLink
});
export { DropdownLink };
//# sourceMappingURL=DropdownLink.js.map