UNPKG

@atlaskit/dropdown-menu

Version:

A dropdown menu displays a list of actions or options to a user.

184 lines • 7.1 kB
/* dropdown-item-new.tsx generated by @compiled/babel-plugin v3.0.4 */ import "./dropdown-item-new.compiled.css"; import * as React from 'react'; import { ax, ix } from "@compiled/react/runtime"; import { forwardRef, Fragment, memo, useContext } from 'react'; import { cx } from '@atlaskit/css'; import CheckMarkIcon from '@atlaskit/icon/core/check-mark'; import ChevronRightIcon from '@atlaskit/icon/core/chevron-right'; import { fg } from '@atlaskit/platform-feature-flags/fg'; import { Anchor } from '@atlaskit/primitives/compiled/anchor'; import { Pressable } from '@atlaskit/primitives/compiled/pressable'; import { Stack } from '@atlaskit/primitives/compiled/stack'; import { Text } from '@atlaskit/primitives/compiled/text'; import KeyboardShortcut from './internal/components/keyboard-shortcut'; import { DropdownTriggerContext } from './internal/context/dropdown-trigger-context'; import { getAriaKeyShortcuts } from './internal/utils/get-aria-keyshortcuts'; const styles = { focusedLink: "_1a3b1r31 _4fprglyw _5goinqa1", root: "_19itglyw _12ji1r31 _1qu2glyw _12y3idpf _4bfu1r31 _1hmsglyw _ajmmnqa1 _19pkidpf _2hwxidpf _otyridpf _18u0idpf _2rko1qi0 _1rjc12x7 _1e0c1txw _2lx2vrvc _gy1pu2gc _4cvr1h6o _1bah1yb4 _16jlkb7n _bfhksm61 _bozgu2gc _y4ti12x7 _y3gnv2br _syazazsu _1bsb1osq _kqswh2mm _nt751v1w _1bg41i6y _49pcnqa1 _1hvwdkaa _f8pjazsu _mizu1v1w _1ah31i6y _ra3xnqa1 _128mdkaa _9oik1r31 _1bnxglyw _jf4cnqa1 _irr31dpa _30l3azsu _1di6fcek", beforeAfterElement: "_1e0c1txw _4cvr1h6o _1bah1h6o _1ul97vkz _1tke7vkz _1o9zidpf", afterElement: "_y4tiv77o", textContainer: "_y4tiutpp", selected: "_bfhk15s3 _syazi7uo _f8pji7uo _irr3ufnl _30l3i7uo _1di6nozp", disabled: "_80om13gf _syaz1gmx _irr3sm61 _30l31gmx _1di6sm61", disabledAndSelected: "_80om13gf _syaz1gmx _bfhk15s3 _irr315s3 _30l31gmx _1di615s3", danger: "_syaz1tmw _f8pj1tmw _30l31tmw", motionUnselected: "_v564hxmd _o7kshxmd _1ggl87vo", motionSelected: "_v5641rrn _o7kshxmd" }; function getTitleColor({ isLink, isDisabled, isSelected, isDanger }) { if (isLink) { return isSelected ? 'color.text' : 'color.text.subtle'; } if (isDisabled) { return 'color.text.disabled'; } if (isSelected) { return 'color.text'; } if (isDanger) { return 'color.text.danger'; } return 'color.text.subtle'; } function getDescriptionColor({ isLink, isDisabled }) { if (isLink || !isDisabled) { return 'color.text.subtlest'; } return 'color.text.disabled'; } const NewDropdownItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({ title, description, elemBefore, elemAfter, shouldTitleWrap, shouldDescriptionWrap, isSelected, isDisabled: isDisabledProp, hasNestedMenu: hasNestedMenuProp, shortcut, appearance, shouldHideSelectionIndicator, href, onClick, onBlur, onFocus, onMouseEnter, onMouseLeave, target, rel, testId, id, role = 'menuitem', interactionName, 'aria-checked': ariaChecked, 'aria-keyshortcuts': explicitAriaKeyShortcuts, 'aria-haspopup': ariaHasPopup, 'aria-expanded': ariaExpanded }, ref) => { const isDropdownTrigger = useContext(DropdownTriggerContext); const hasNestedMenu = hasNestedMenuProp !== null && hasNestedMenuProp !== void 0 ? hasNestedMenuProp : isDropdownTrigger; const isLink = !!href; const isDisabled = !isLink && isDisabledProp; const isDanger = appearance === 'danger'; const titleMaxLines = shouldTitleWrap ? undefined : 1; const descMaxLines = shouldDescriptionWrap ? undefined : 1; const titleColor = getTitleColor({ isLink, isDisabled, isSelected, isDanger }); const descColor = getDescriptionColor({ isLink, isDisabled }); const ariaKeyShortcuts = isDisabled ? undefined : explicitAriaKeyShortcuts !== null && explicitAriaKeyShortcuts !== void 0 ? explicitAriaKeyShortcuts : getAriaKeyShortcuts(shortcut); const menuItem = /*#__PURE__*/React.createElement(Fragment, null, elemBefore && /*#__PURE__*/React.createElement("span", { "data-testid": testId && `${testId}--elem-before`, className: ax([styles.beforeAfterElement]) }, elemBefore), /*#__PURE__*/React.createElement(Stack, { grow: "fill", space: "space.025", xcss: styles.textContainer }, /*#__PURE__*/React.createElement(Text, { weight: "medium", color: titleColor, maxLines: titleMaxLines, testId: testId && `${testId}--title` }, title), description && /*#__PURE__*/React.createElement(Text, { size: "small", color: descColor, maxLines: descMaxLines, testId: testId && `${testId}--description` }, description)), shortcut && /*#__PURE__*/React.createElement(KeyboardShortcut, { shortcut: shortcut, isAriaHidden: !!ariaKeyShortcuts }), elemAfter && /*#__PURE__*/React.createElement("span", { "data-testid": testId && `${testId}--elem-after`, className: ax([styles.beforeAfterElement]) }, elemAfter), hasNestedMenu && /*#__PURE__*/React.createElement("span", { "data-testid": testId && `${testId}--chevron`, className: ax([styles.beforeAfterElement, styles.afterElement]) }, /*#__PURE__*/React.createElement(ChevronRightIcon, { size: "small", label: "" })), isSelected && !shouldHideSelectionIndicator && !hasNestedMenu && !isDropdownTrigger && !ariaHasPopup && /*#__PURE__*/React.createElement("span", { "data-testid": testId && `${testId}--selected`, className: ax([styles.beforeAfterElement, styles.afterElement]) }, /*#__PURE__*/React.createElement(CheckMarkIcon, { label: "" }))); if (href) { return /*#__PURE__*/React.createElement(Anchor, { href: href, target: target, rel: rel, onClick: onClick, onBlur: onBlur, onFocus: onFocus, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, xcss: cx(styles.root, fg('ads_prevent_underline_for_anchor') && styles.focusedLink, isSelected && styles.selected, isDanger && styles.danger), testId: testId, role: role, id: id, ref: ref, interactionName: interactionName, "aria-current": isSelected && role === 'menuitem' && !ariaHasPopup ? 'page' : undefined, "aria-checked": ariaChecked, "aria-haspopup": ariaHasPopup, "aria-expanded": ariaExpanded, "aria-keyshortcuts": ariaKeyShortcuts }, menuItem); } return /*#__PURE__*/React.createElement(Pressable, { onClick: onClick, onBlur: onBlur, onFocus: onFocus, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, isDisabled: isDisabled, xcss: cx(styles.root, isSelected && styles.selected, isDisabled && styles.disabled, isSelected && isDisabled && styles.disabledAndSelected, isDanger && styles.danger, !isDisabled && isSelected && styles.motionSelected, !isDisabled && !isSelected && styles.motionUnselected), testId: testId, role: role, "aria-checked": ariaChecked, "aria-haspopup": ariaHasPopup, "aria-expanded": ariaExpanded, "aria-keyshortcuts": ariaKeyShortcuts, id: id, ref: ref, interactionName: interactionName }, menuItem); })); export default NewDropdownItem;