UNPKG

@atlaskit/dropdown-menu

Version:

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

161 lines (160 loc) • 5.93 kB
/* dropdown-menu-item-new.tsx generated by @compiled/babel-plugin v3.0.2 */ import "./dropdown-menu-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 { NewSpacingContext } from './internal/context/spacing-context'; const styles = { root: "_19itglyw _12ji1r31 _1qu2glyw _12y3idpf _4bfu1r31 _1hmsglyw _ajmmnqa1 _19pkidpf _2hwxidpf _otyridpf _18u0idpf _2rko1qi0 _18zrutpp _1rjcu2gc _1e0c1txw _2lx2vrvc _gy1putpp _4cvr1h6o _1bah1yb4 _16jlkb7n _bfhksm61 _y3gnv2br _syazazsu _1bsb1osq _kqswh2mm _nt751v1w _1bg41i6y _49pcnqa1 _1hvwdkaa _f8pjazsu _mizu1v1w _1ah31i6y _ra3xnqa1 _128mdkaa _9oik1r31 _1bnxglyw _jf4cnqa1 _irr31dpa _30l3azsu _1di6fcek", compact: "_18zru2gc _1rjc12x7 _gy1pu2gc", beforeAfterElement: "_1e0c1txw _4cvr1h6o _1bah1h6o _1ul97vkz _1tke7vkz _1o9zidpf", 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" }; 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 NewDropdownMenuItem = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({ title, description, elemBefore, elemAfter, shouldTitleWrap, shouldDescriptionWrap, isSelected, isDisabled, hasNestedMenu: hasNestedMenuProp, shortcut, appearance, href, onClick, target, rel, testId, id, role = 'menuitem', 'aria-checked': ariaChecked, 'aria-haspopup': ariaHasPopup, 'aria-expanded': ariaExpanded }, ref) => { const isDropdownTrigger = useContext(DropdownTriggerContext); const hasNestedMenu = isDropdownTrigger || hasNestedMenuProp; const spacing = useContext(NewSpacingContext); const isCompact = spacing === 'compact'; const isLink = !!href; 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 }); // Just to force the toggle in atlaspack workbench // @ts-ignore const _nothing = fg('platform-dst-tokens-finesse'); 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, { color: descColor, maxLines: descMaxLines, testId: testId && `${testId}--description` }, description)), shortcut && /*#__PURE__*/React.createElement(KeyboardShortcut, { shortcut: shortcut }), 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]) }, /*#__PURE__*/React.createElement(ChevronRightIcon, { size: "small", label: "" })), isSelected && role === 'menuitem' && !hasNestedMenu && /*#__PURE__*/React.createElement("span", { "data-testid": testId && `${testId}--selected`, className: ax([styles.beforeAfterElement]) }, /*#__PURE__*/React.createElement(CheckMarkIcon, { label: "" }))); if (href) { return /*#__PURE__*/React.createElement(Anchor, { href: href, target: target, rel: rel, onClick: onClick, xcss: cx(styles.root, isCompact && styles.compact, isSelected && styles.selected, isDanger && styles.danger), testId: testId, role: role, id: id, ref: ref, "aria-current": isSelected ? 'page' : undefined }, menuItem); } return /*#__PURE__*/React.createElement(Pressable, { onClick: onClick, isDisabled: isDisabled, xcss: cx(styles.root, isCompact && styles.compact, isSelected && styles.selected, isDisabled && styles.disabled, isSelected && isDisabled && styles.disabledAndSelected, isDanger && styles.danger), testId: testId, role: role, "aria-checked": ariaChecked, "aria-haspopup": ariaHasPopup, "aria-expanded": ariaExpanded, id: id, ref: ref }, menuItem); })); export default NewDropdownMenuItem;