UNPKG

@razorpay/blade

Version:

The Design System that powers Razorpay

139 lines (134 loc) 5.95 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties'; import React__default from 'react'; import { BaseMenuItemContext } from '../BaseMenuContext.js'; import { StyledMenuItemContainer } from './StyledMenuItemContainer.web.js'; import { itemFirstRowHeight } from './tokens.js'; import '../../Box/index.js'; import '../../Typography/index.js'; import '../../../utils/makeAccessible/index.js'; import '../../Typography/BaseText/index.js'; import '../../../utils/useTruncationTitle/index.js'; import '../../../utils/index.js'; import { jsx, jsxs } from 'react/jsx-runtime'; import { useTruncationTitle } from '../../../utils/useTruncationTitle/useTruncationTitle.web.js'; import { makeAccessible } from '../../../utils/makeAccessible/makeAccessible.web.js'; import { Box } from '../../Box/Box.js'; import { makeSize } from '../../../utils/makeSize/makeSize.js'; import { BaseText } from '../../Typography/BaseText/BaseText.web.js'; import { getTextProps, Text } from '../../Typography/Text/Text.js'; var _excluded = ["title", "description", "as", "leading", "trailing", "titleSuffix", "isDisabled", "selectionType", "isSelected", "isVisible", "color", "role", "children"]; 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 menuItemTitleColor = { negative: { "default": 'feedback.text.negative.intense', disabled: 'interactive.text.gray.disabled' }, normal: { "default": 'interactive.text.gray.normal', disabled: 'interactive.text.gray.disabled' } }; var menuItemDescriptionColor = { "default": 'interactive.text.gray.muted', disabled: 'interactive.text.gray.disabled' }; // This is the height of item excluding the description to make sure description comes at the bottom and other first row items are center aligned var _BaseMenuItem = function _BaseMenuItem(_ref, ref) { var title = _ref.title, description = _ref.description, as = _ref.as, leading = _ref.leading, trailing = _ref.trailing, titleSuffix = _ref.titleSuffix, isDisabled = _ref.isDisabled, _ref$selectionType = _ref.selectionType, selectionType = _ref$selectionType === void 0 ? 'single' : _ref$selectionType, isSelected = _ref.isSelected, _ref$isVisible = _ref.isVisible, isVisible = _ref$isVisible === void 0 ? true : _ref$isVisible, color = _ref.color, _ref$role = _ref.role, role = _ref$role === void 0 ? 'menuitem' : _ref$role, children = _ref.children, props = _objectWithoutProperties(_ref, _excluded); var _useTruncationTitle = useTruncationTitle({ content: title }), containerRef = _useTruncationTitle.containerRef, textRef = _useTruncationTitle.textRef; return /*#__PURE__*/jsx(BaseMenuItemContext.Provider, { value: { color: color, isDisabled: isDisabled }, children: /*#__PURE__*/jsx(StyledMenuItemContainer, _objectSpread(_objectSpread(_objectSpread({ ref: ref, as: as, type: "button", disabled: isDisabled }, makeAccessible({ role: role, current: role === 'menuitem' || role === 'menuitemcheckbox' ? isSelected : undefined, disabled: isDisabled, selected: isSelected })), {}, { color: color, isVisible: isVisible, isSelected: isSelected, isDisabled: isDisabled, selectionType: selectionType }, props), {}, { children: children ? children : /*#__PURE__*/jsxs(Box, { display: "flex", alignItems: "flex-start", width: "100%", justifyContent: "flex-start", children: [/*#__PURE__*/jsx(Box, { display: "flex", justifyContent: "center", alignItems: "center", height: makeSize(itemFirstRowHeight), children: leading }), /*#__PURE__*/jsxs(Box, { paddingLeft: leading ? 'spacing.3' : 'spacing.0', paddingRight: "spacing.3", display: "flex", flexDirection: "column", children: [/*#__PURE__*/jsxs(Box, { display: "flex", alignItems: "center", flexDirection: "row", height: makeSize(itemFirstRowHeight), ref: containerRef, children: [/*#__PURE__*/jsx(BaseText, _objectSpread(_objectSpread({ as: "p", ref: textRef, truncateAfterLines: 1, wordBreak: "break-all" }, getTextProps({ size: 'medium', color: menuItemTitleColor[color === 'negative' ? 'negative' : 'normal'][isDisabled ? 'disabled' : 'default'], weight: 'regular' })), {}, { children: title })), titleSuffix] }), /*#__PURE__*/jsx(Box, { children: description ? /*#__PURE__*/jsx(Text, { color: menuItemDescriptionColor[isDisabled ? 'disabled' : 'default'], size: "small", children: description }) : null })] }), /*#__PURE__*/jsx(Box, { marginLeft: "auto", children: trailing })] }) })) }); }; var BaseMenuItem = /*#__PURE__*/React__default.forwardRef(_BaseMenuItem); export { BaseMenuItem }; //# sourceMappingURL=BaseMenuItem.js.map