@razorpay/blade
Version:
The Design System that powers Razorpay
99 lines (96 loc) • 4.98 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import 'react';
import { useDropdown } from './useDropdown.js';
import { dropdownComponentIds } from './dropdownComponentIds.js';
import '../Button/BaseButton/index.js';
import { getActionListContainerRole } from '../ActionList/getA11yRoles.js';
import '../../utils/assignWithoutSideEffects/index.js';
import { jsx } from 'react/jsx-runtime';
import BaseButton from '../Button/BaseButton/BaseButton.js';
import { assignWithoutSideEffects } from '../../utils/assignWithoutSideEffects/assignWithoutSideEffects.js';
var _excluded = ["children", "icon", "iconPosition", "isDisabled", "isFullWidth", "isLoading", "onClick", "onBlur", "onKeyDown", "size", "type", "variant", "accessibilityLabel", "testID"];
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 _DropdownButton = function _DropdownButton(_ref) {
var children = _ref.children,
icon = _ref.icon,
_ref$iconPosition = _ref.iconPosition,
iconPosition = _ref$iconPosition === void 0 ? 'left' : _ref$iconPosition,
_ref$isDisabled = _ref.isDisabled,
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
_ref$isFullWidth = _ref.isFullWidth,
isFullWidth = _ref$isFullWidth === void 0 ? false : _ref$isFullWidth,
_ref$isLoading = _ref.isLoading,
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
_onClick = _ref.onClick,
_onBlur = _ref.onBlur,
_onKeyDown = _ref.onKeyDown,
_ref$size = _ref.size,
size = _ref$size === void 0 ? 'medium' : _ref$size,
_ref$type = _ref.type,
type = _ref$type === void 0 ? 'button' : _ref$type,
_ref$variant = _ref.variant,
variant = _ref$variant === void 0 ? 'primary' : _ref$variant,
accessibilityLabel = _ref.accessibilityLabel,
testID = _ref.testID,
rest = _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(BaseButton, _objectSpread(_objectSpread(_objectSpread({}, rest), icon ? {
icon: icon,
children: children
} : {
children: children
}), {}, {
iconPosition: iconPosition,
isDisabled: isDisabled,
isFullWidth: isFullWidth,
isLoading: isLoading,
size: size,
type: type,
variant: variant,
testID: testID,
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) {
// With button trigger, there is no "value" as such. It's just clickable items
// 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 DropdownButton = /*#__PURE__*/assignWithoutSideEffects(_DropdownButton, {
componentId: dropdownComponentIds.triggers.DropdownButton
});
export { DropdownButton };
//# sourceMappingURL=DropdownButton.js.map