-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
MenuItem.tsx
780 lines (678 loc) · 39.4 KB
/
MenuItem.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
import {ExpensiMark} from 'expensify-common';
import type {ImageContentFit} from 'expo-image';
import type {ReactElement, ReactNode} from 'react';
import React, {forwardRef, useContext, useMemo} from 'react';
import type {GestureResponderEvent, StyleProp, TextStyle, ViewStyle} from 'react-native';
import {View} from 'react-native';
import type {AnimatedStyle} from 'react-native-reanimated';
import type {ValueOf} from 'type-fest';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import ControlSelection from '@libs/ControlSelection';
import convertToLTR from '@libs/convertToLTR';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import getButtonState from '@libs/getButtonState';
import type {AvatarSource} from '@libs/UserUtils';
import variables from '@styles/variables';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import type {Icon as IconType} from '@src/types/onyx/OnyxCommon';
import type IconAsset from '@src/types/utils/IconAsset';
import Avatar from './Avatar';
import Badge from './Badge';
import DisplayNames from './DisplayNames';
import type {DisplayNameWithTooltip} from './DisplayNames/types';
import FormHelpMessage from './FormHelpMessage';
import Hoverable from './Hoverable';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import * as defaultWorkspaceAvatars from './Icon/WorkspaceDefaultAvatars';
import {MenuItemGroupContext} from './MenuItemGroup';
import MultipleAvatars from './MultipleAvatars';
import type {PressableRef} from './Pressable/GenericPressable/types';
import PressableWithSecondaryInteraction from './PressableWithSecondaryInteraction';
import RenderHTML from './RenderHTML';
import SelectCircle from './SelectCircle';
import SubscriptAvatar from './SubscriptAvatar';
import Text from './Text';
import EducationalTooltip from './Tooltip/EducationalTooltip';
type IconProps = {
/** Flag to choose between avatar image or an icon */
iconType?: typeof CONST.ICON_TYPE_ICON;
/** Icon to display on the left side of component */
icon: IconAsset | IconType[];
};
type AvatarProps = {
iconType?: typeof CONST.ICON_TYPE_AVATAR | typeof CONST.ICON_TYPE_WORKSPACE;
icon: AvatarSource | IconType[];
};
type NoIcon = {
iconType?: undefined;
icon?: undefined;
};
type MenuItemBaseProps = {
/** Function to fire when component is pressed */
onPress?: (event: GestureResponderEvent | KeyboardEvent) => void | Promise<void>;
/** Whether the menu item should be interactive at all */
interactive?: boolean;
/** Text to be shown as badge near the right end. */
badgeText?: string;
/** Used to apply offline styles to child text components */
style?: StyleProp<ViewStyle>;
/** Outer wrapper styles */
outerWrapperStyle?: StyleProp<ViewStyle>;
/** Any additional styles to apply */
wrapperStyle?: StyleProp<ViewStyle>;
/** Any additional styles to apply on the outer element */
containerStyle?: StyleProp<ViewStyle>;
/** Used to apply styles specifically to the title */
titleStyle?: ViewStyle;
/** Any additional styles to apply on the badge element */
badgeStyle?: ViewStyle;
/** Any additional styles to apply to the label */
labelStyle?: StyleProp<ViewStyle>;
/** Any adjustments to style when menu item is hovered or pressed */
hoverAndPressStyle?: StyleProp<AnimatedStyle<ViewStyle>>;
/** Additional styles to style the description text below the title */
descriptionTextStyle?: StyleProp<TextStyle>;
/** The fill color to pass into the icon. */
iconFill?: string;
/** Secondary icon to display on the left side of component, right of the icon */
secondaryIcon?: IconAsset;
/** The fill color to pass into the secondary icon. */
secondaryIconFill?: string;
/** Whether the secondary icon should have hover style */
isSecondaryIconHoverable?: boolean;
/** Icon Width */
iconWidth?: number;
/** Icon Height */
iconHeight?: number;
/** Any additional styles to pass to the icon container. */
iconStyles?: StyleProp<ViewStyle>;
/** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */
fallbackIcon?: IconAsset;
/** An icon to display under the main item */
furtherDetailsIcon?: IconAsset;
/** Boolean whether to display the title right icon */
shouldShowTitleIcon?: boolean;
/** Icon to display at right side of title */
titleIcon?: IconAsset;
/** Boolean whether to display the right icon */
shouldShowRightIcon?: boolean;
/** Overrides the icon for shouldShowRightIcon */
iconRight?: IconAsset;
/** Should render component on the right */
shouldShowRightComponent?: boolean;
/** Component to be displayed on the right */
rightComponent?: ReactNode;
/** A description text to show under the title */
description?: string;
/** Text to show below menu item. This text is not interactive */
helperText?: string;
/** Any additional styles to pass to helper text. */
helperTextStyle?: StyleProp<TextStyle>;
/** Should the description be shown above the title (instead of the other way around) */
shouldShowDescriptionOnTop?: boolean;
/** Error to display at the bottom of the component */
errorText?: string;
/** Any additional styles to pass to error text. */
errorTextStyle?: StyleProp<ViewStyle>;
/** Hint to display at the bottom of the component */
hintText?: string;
/** Should the error text red dot indicator be shown */
shouldShowRedDotIndicator?: boolean;
/** A boolean flag that gives the icon a green fill if true */
success?: boolean;
/** Whether item is focused or active */
focused?: boolean;
/** Should we disable this menu item? */
disabled?: boolean;
/** Text that appears above the title */
label?: string;
isLabelHoverable?: boolean;
/** Label to be displayed on the right */
rightLabel?: string;
/** Text to display for the item */
title?: string;
/** Component to display as the title */
titleComponent?: ReactElement;
/** Any additional styles to apply to the container for title components */
titleContainerStyle?: StyleProp<ViewStyle>;
/** A right-aligned subtitle for this menu option */
subtitle?: string | number;
/** Should the title show with normal font weight (not bold) */
shouldShowBasicTitle?: boolean;
/** Should we make this selectable with a checkbox */
shouldShowSelectedState?: boolean;
/** Whether this item is selected */
isSelected?: boolean;
/** Prop to identify if we should load avatars vertically instead of diagonally */
shouldStackHorizontally?: boolean;
/** Prop to represent the size of the avatar images to be shown */
avatarSize?: ValueOf<typeof CONST.AVATAR_SIZE>;
/** Avatars to show on the right of the menu item */
floatRightAvatars?: IconType[];
/** Prop to represent the size of the float right avatar images to be shown */
floatRightAvatarSize?: ValueOf<typeof CONST.AVATAR_SIZE>;
/** Whether the secondary right avatar should show as a subscript */
shouldShowSubscriptRightAvatar?: boolean;
/** Affects avatar size */
viewMode?: ValueOf<typeof CONST.OPTION_MODE>;
/** Used to truncate the text with an ellipsis after computing the text layout */
numberOfLinesTitle?: number;
/** Used to truncate the description with an ellipsis after computing the text layout */
numberOfLinesDescription?: number;
/** Whether we should use small avatar subscript sizing the for menu item */
isSmallAvatarSubscriptMenu?: boolean;
/** The type of brick road indicator to show. */
brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS>;
/** Should render the content in HTML format */
shouldRenderAsHTML?: boolean;
/** Whether or not the text should be escaped */
shouldEscapeText?: boolean;
/** Should we grey out the menu item when it is disabled? */
shouldGreyOutWhenDisabled?: boolean;
/** Should we use default cursor for disabled content */
shouldUseDefaultCursorWhenDisabled?: boolean;
/** The action accept for anonymous user or not */
isAnonymousAction?: boolean;
/** Flag to indicate whether or not text selection should be disabled from long-pressing the menu item. */
shouldBlockSelection?: boolean;
/** Whether should render title as HTML or as Text */
shouldParseTitle?: boolean;
/** Should check anonymous user in onPress function */
shouldCheckActionAllowedOnPress?: boolean;
/** Text to display under the main item */
furtherDetails?: string;
/** The function that should be called when this component is LongPressed or right-clicked. */
onSecondaryInteraction?: (event: GestureResponderEvent | MouseEvent) => void;
/** Array of objects that map display names to their corresponding tooltip */
titleWithTooltips?: DisplayNameWithTooltip[] | undefined;
/** Icon should be displayed in its own color */
displayInDefaultIconColor?: boolean;
/** Determines how the icon should be resized to fit its container */
contentFit?: ImageContentFit;
/** Is this in the Pane */
isPaneMenu?: boolean;
/** Adds padding to the left of the text when there is no icon. */
shouldPutLeftPaddingWhenNoIcon?: boolean;
/** Handles what to do when the item is focused */
onFocus?: () => void;
/** Handles what to do when the item loose focus */
onBlur?: () => void;
/** Optional account id if it's user avatar or policy id if it's workspace avatar */
avatarID?: number | string;
/** Whether to show the tooltip */
shouldRenderTooltip?: boolean;
/** Whether to align the tooltip left */
shouldForceRenderingTooltipLeft?: boolean;
/** Additional styles for tooltip wrapper */
tooltipWrapperStyle?: StyleProp<ViewStyle>;
/** Render custom content inside the tooltip. */
renderTooltipContent?: () => ReactNode;
};
type MenuItemProps = (IconProps | AvatarProps | NoIcon) & MenuItemBaseProps;
function MenuItem(
{
interactive = true,
onPress,
badgeText,
style,
wrapperStyle,
outerWrapperStyle,
containerStyle,
titleStyle,
labelStyle,
hoverAndPressStyle,
descriptionTextStyle,
badgeStyle,
viewMode = CONST.OPTION_MODE.DEFAULT,
numberOfLinesTitle = 1,
numberOfLinesDescription = 2,
icon,
iconFill,
secondaryIcon,
secondaryIconFill,
iconType = CONST.ICON_TYPE_ICON,
isSecondaryIconHoverable = false,
iconWidth,
iconHeight,
iconStyles,
fallbackIcon = Expensicons.FallbackAvatar,
shouldShowTitleIcon = false,
titleIcon,
shouldShowRightIcon = false,
iconRight = Expensicons.ArrowRight,
furtherDetailsIcon,
furtherDetails,
description,
helperText,
helperTextStyle,
errorText,
errorTextStyle,
shouldShowRedDotIndicator,
hintText,
success = false,
focused = false,
disabled = false,
title,
titleComponent,
titleContainerStyle,
subtitle,
shouldShowBasicTitle,
label,
isLabelHoverable = true,
rightLabel,
shouldShowSelectedState = false,
isSelected = false,
shouldStackHorizontally = false,
shouldShowDescriptionOnTop = false,
shouldShowRightComponent = false,
rightComponent,
floatRightAvatars = [],
floatRightAvatarSize,
shouldShowSubscriptRightAvatar = false,
avatarSize = CONST.AVATAR_SIZE.DEFAULT,
isSmallAvatarSubscriptMenu = false,
brickRoadIndicator,
shouldRenderAsHTML = false,
shouldEscapeText = undefined,
shouldGreyOutWhenDisabled = true,
shouldUseDefaultCursorWhenDisabled = false,
isAnonymousAction = false,
shouldBlockSelection = false,
shouldParseTitle = false,
shouldCheckActionAllowedOnPress = true,
onSecondaryInteraction,
titleWithTooltips,
displayInDefaultIconColor = false,
contentFit = 'cover',
isPaneMenu = false,
shouldPutLeftPaddingWhenNoIcon = false,
onFocus,
onBlur,
avatarID,
shouldRenderTooltip = false,
shouldForceRenderingTooltipLeft = false,
tooltipWrapperStyle = {},
renderTooltipContent,
}: MenuItemProps,
ref: PressableRef,
) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const combinedStyle = [styles.popoverMenuItem, style];
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {isExecuting, singleExecution, waitForNavigate} = useContext(MenuItemGroupContext) ?? {};
const isDeleted = style && Array.isArray(style) ? style.includes(styles.offlineFeedback.deleted) : false;
const descriptionVerticalMargin = shouldShowDescriptionOnTop ? styles.mb1 : styles.mt1;
const fallbackAvatarSize = viewMode === CONST.OPTION_MODE.COMPACT ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT;
const combinedTitleTextStyle = StyleUtils.combineStyles(
[
styles.flexShrink1,
styles.popoverMenuText,
// eslint-disable-next-line no-nested-ternary
shouldPutLeftPaddingWhenNoIcon || (icon && !Array.isArray(icon)) ? (avatarSize === CONST.AVATAR_SIZE.SMALL ? styles.ml2 : styles.ml3) : {},
shouldShowBasicTitle ? {} : styles.textStrong,
numberOfLinesTitle !== 1 ? styles.preWrap : styles.pre,
interactive && disabled ? {...styles.userSelectNone} : {},
styles.ltr,
isDeleted ? styles.offlineFeedback.deleted : {},
],
titleStyle ?? {},
);
const descriptionTextStyles = StyleUtils.combineStyles<TextStyle>([
styles.textLabelSupporting,
icon && !Array.isArray(icon) ? styles.ml3 : {},
title ? descriptionVerticalMargin : StyleUtils.getFontSizeStyle(variables.fontSizeNormal),
(descriptionTextStyle as TextStyle) || styles.breakWord,
isDeleted ? styles.offlineFeedback.deleted : {},
]);
const html = useMemo(() => {
if (!title || !shouldParseTitle) {
return '';
}
const parser = new ExpensiMark();
return parser.replace(title, {shouldEscapeText});
}, [title, shouldParseTitle, shouldEscapeText]);
const processedTitle = useMemo(() => {
let titleToWrap = '';
if (shouldRenderAsHTML) {
titleToWrap = title ? convertToLTR(title) : '';
}
if (shouldParseTitle) {
titleToWrap = html;
}
return titleToWrap ? `<comment>${titleToWrap}</comment>` : '';
}, [title, shouldRenderAsHTML, shouldParseTitle, html]);
const hasPressableRightComponent = iconRight || (shouldShowRightComponent && rightComponent);
const renderTitleContent = () => {
if (title && titleWithTooltips && Array.isArray(titleWithTooltips) && titleWithTooltips.length > 0) {
return (
<DisplayNames
fullTitle={title}
displayNamesWithTooltips={titleWithTooltips}
tooltipEnabled
numberOfLines={1}
/>
);
}
return title ? convertToLTR(title) : '';
};
const onPressAction = (event: GestureResponderEvent | KeyboardEvent | undefined) => {
if (disabled || !interactive) {
return;
}
if (event?.type === 'click') {
(event.currentTarget as HTMLElement).blur();
}
if (onPress && event) {
if (!singleExecution || !waitForNavigate) {
onPress(event);
return;
}
singleExecution(
waitForNavigate(() => {
onPress(event);
}),
)();
}
};
return (
<View onBlur={onBlur}>
{!!label && !isLabelHoverable && (
<View style={[styles.ph5, labelStyle]}>
<Text style={StyleUtils.combineStyles([styles.sidebarLinkText, styles.optionAlternateText, styles.textLabelSupporting, styles.pre])}>{label}</Text>
</View>
)}
<EducationalTooltip
shouldRender={shouldRenderTooltip}
shouldForceRenderingLeft={shouldForceRenderingTooltipLeft}
renderTooltipContent={renderTooltipContent}
wrapperStyle={tooltipWrapperStyle}
shiftHorizontal={styles.popoverMenuItem.paddingHorizontal}
shiftVertical={styles.popoverMenuItem.paddingVertical / 2}
>
<View>
<Hoverable>
{(isHovered) => (
<PressableWithSecondaryInteraction
onPress={shouldCheckActionAllowedOnPress ? Session.checkIfActionIsAllowed(onPressAction, isAnonymousAction) : onPressAction}
onPressIn={() => shouldBlockSelection && shouldUseNarrowLayout && DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()}
onPressOut={ControlSelection.unblock}
onSecondaryInteraction={onSecondaryInteraction}
wrapperStyle={outerWrapperStyle}
style={({pressed}) =>
[
containerStyle,
combinedStyle,
!interactive && styles.cursorDefault,
StyleUtils.getButtonBackgroundColorStyle(getButtonState(focused || isHovered, pressed, success, disabled, interactive), true),
...(Array.isArray(wrapperStyle) ? wrapperStyle : [wrapperStyle]),
!focused && (isHovered || pressed) && hoverAndPressStyle,
shouldGreyOutWhenDisabled && disabled && styles.buttonOpacityDisabled,
isHovered && interactive && !pressed && styles.hoveredComponentBG,
] as StyleProp<ViewStyle>
}
disabledStyle={shouldUseDefaultCursorWhenDisabled && [styles.cursorDefault]}
disabled={disabled || isExecuting}
ref={ref}
role={CONST.ROLE.MENUITEM}
accessibilityLabel={title ? title.toString() : ''}
accessible
onFocus={onFocus}
>
{({pressed}) => (
<View style={[styles.flex1]}>
<View style={[styles.flexRow]}>
<View style={[styles.flexColumn, styles.flex1]}>
{!!label && isLabelHoverable && (
<View style={[icon ? styles.mb2 : null, labelStyle]}>
<Text style={StyleUtils.combineStyles([styles.sidebarLinkText, styles.optionAlternateText, styles.textLabelSupporting, styles.pre])}>
{label}
</Text>
</View>
)}
<View style={[styles.flexRow, styles.pointerEventsAuto, disabled && !shouldUseDefaultCursorWhenDisabled && styles.cursorDisabled]}>
{!!icon && Array.isArray(icon) && (
<MultipleAvatars
isHovered={isHovered}
isPressed={pressed}
icons={icon as IconType[]}
size={avatarSize}
secondAvatarStyle={[
StyleUtils.getBackgroundAndBorderStyle(theme.sidebar),
pressed && interactive ? StyleUtils.getBackgroundAndBorderStyle(theme.buttonPressedBG) : undefined,
isHovered && !pressed && interactive ? StyleUtils.getBackgroundAndBorderStyle(theme.border) : undefined,
]}
/>
)}
{!icon && shouldPutLeftPaddingWhenNoIcon && (
<View style={[styles.popoverMenuIcon, iconStyles, StyleUtils.getAvatarWidthStyle(avatarSize)]} />
)}
{icon && !Array.isArray(icon) && (
<View style={[styles.popoverMenuIcon, iconStyles, StyleUtils.getAvatarWidthStyle(avatarSize)]}>
{typeof icon !== 'string' && iconType === CONST.ICON_TYPE_ICON && (
<Icon
contentFit={contentFit}
hovered={isHovered}
pressed={pressed}
src={icon}
width={iconWidth}
height={iconHeight}
fill={
displayInDefaultIconColor
? undefined
: iconFill ??
StyleUtils.getIconFillColor(
getButtonState(focused || isHovered, pressed, success, disabled, interactive),
true,
isPaneMenu,
)
}
/>
)}
{icon && iconType === CONST.ICON_TYPE_WORKSPACE && (
<Avatar
imageStyles={[styles.alignSelfCenter]}
size={CONST.AVATAR_SIZE.DEFAULT}
source={icon}
fallbackIcon={fallbackIcon}
name={title}
avatarID={avatarID}
type={CONST.ICON_TYPE_WORKSPACE}
/>
)}
{iconType === CONST.ICON_TYPE_AVATAR && (
<Avatar
imageStyles={[styles.alignSelfCenter]}
source={icon}
avatarID={avatarID}
fallbackIcon={fallbackIcon}
size={avatarSize}
type={CONST.ICON_TYPE_AVATAR}
/>
)}
</View>
)}
{secondaryIcon && (
<View style={[styles.popoverMenuIcon, iconStyles, isSecondaryIconHoverable && StyleUtils.getBackgroundAndBorderStyle(theme.border)]}>
<Icon
contentFit={contentFit}
src={secondaryIcon}
width={iconWidth}
height={iconHeight}
fill={
secondaryIconFill ??
StyleUtils.getIconFillColor(getButtonState(focused || isHovered, pressed, success, disabled, interactive), true)
}
/>
</View>
)}
<View
style={[
styles.justifyContentCenter,
styles.flex1,
StyleUtils.getMenuItemTextContainerStyle(isSmallAvatarSubscriptMenu),
titleContainerStyle,
]}
>
{!!description && shouldShowDescriptionOnTop && (
<Text
style={descriptionTextStyles}
numberOfLines={numberOfLinesDescription}
>
{description}
</Text>
)}
{(!!title || !!shouldShowTitleIcon) && (
<View style={[styles.flexRow, styles.alignItemsCenter]}>
{!!title && (shouldRenderAsHTML || (shouldParseTitle && !!html.length)) && (
<View style={styles.renderHTMLTitle}>
<RenderHTML html={processedTitle} />
</View>
)}
{!shouldRenderAsHTML && !shouldParseTitle && !!title && (
<Text
style={combinedTitleTextStyle}
numberOfLines={numberOfLinesTitle || undefined}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: interactive && disabled}}
>
{renderTitleContent()}
</Text>
)}
{shouldShowTitleIcon && titleIcon && (
<View style={[styles.ml2]}>
<Icon
src={titleIcon}
fill={theme.iconSuccessFill}
/>
</View>
)}
</View>
)}
{!!description && !shouldShowDescriptionOnTop && (
<Text
style={descriptionTextStyles}
numberOfLines={numberOfLinesDescription}
>
{description}
</Text>
)}
{!!furtherDetails && (
<View style={[styles.flexRow, styles.mt1, styles.alignItemsCenter]}>
{!!furtherDetailsIcon && (
<Icon
src={furtherDetailsIcon}
height={variables.iconSizeNormal}
width={variables.iconSizeNormal}
inline
/>
)}
<Text
style={furtherDetailsIcon ? [styles.furtherDetailsText, styles.ph2, styles.pt1] : styles.textLabelSupporting}
numberOfLines={2}
>
{furtherDetails}
</Text>
</View>
)}
{titleComponent}
</View>
</View>
</View>
<View style={[styles.flexRow, styles.menuItemTextContainer, !hasPressableRightComponent && styles.pointerEventsNone]}>
{badgeText && (
<Badge
text={badgeText}
badgeStyles={badgeStyle}
/>
)}
{/* Since subtitle can be of type number, we should allow 0 to be shown */}
{(subtitle === 0 || subtitle) && (
<View style={[styles.justifyContentCenter, styles.mr1]}>
<Text style={[styles.textLabelSupporting, ...(combinedStyle as TextStyle[])]}>{subtitle}</Text>
</View>
)}
{floatRightAvatars?.length > 0 && (
<View style={[styles.alignItemsCenter, styles.justifyContentCenter, brickRoadIndicator ? styles.mr2 : styles.mrn2]}>
{shouldShowSubscriptRightAvatar ? (
<SubscriptAvatar
backgroundColor={isHovered ? theme.activeComponentBG : theme.componentBG}
mainAvatar={floatRightAvatars[0]}
secondaryAvatar={floatRightAvatars[1]}
size={floatRightAvatarSize ?? fallbackAvatarSize}
/>
) : (
<MultipleAvatars
isHovered={isHovered}
isPressed={pressed}
icons={floatRightAvatars}
size={floatRightAvatarSize ?? fallbackAvatarSize}
fallbackIcon={defaultWorkspaceAvatars.WorkspaceBuilding}
shouldStackHorizontally={shouldStackHorizontally}
isFocusMode
/>
)}
</View>
)}
{!!brickRoadIndicator && (
<View style={[styles.alignItemsCenter, styles.justifyContentCenter, styles.ml1]}>
<Icon
src={Expensicons.DotIndicator}
fill={brickRoadIndicator === 'error' ? theme.danger : theme.success}
/>
</View>
)}
{!title && !!rightLabel && !errorText && (
<View style={styles.justifyContentCenter}>
<Text style={styles.rightLabelMenuItem}>{rightLabel}</Text>
</View>
)}
{shouldShowRightIcon && (
<View
style={[styles.popoverMenuIcon, styles.pointerEventsAuto, disabled && !shouldUseDefaultCursorWhenDisabled && styles.cursorDisabled]}
>
<Icon
src={iconRight}
fill={StyleUtils.getIconFillColor(getButtonState(focused || isHovered, pressed, success, disabled, interactive))}
/>
</View>
)}
{shouldShowRightComponent && rightComponent}
{shouldShowSelectedState && <SelectCircle isChecked={isSelected} />}
</View>
</View>
{!!errorText && (
<FormHelpMessage
isError
shouldShowRedDotIndicator={!!shouldShowRedDotIndicator}
message={errorText}
style={[styles.menuItemError, errorTextStyle]}
/>
)}
{!!hintText && (
<FormHelpMessage
isError={false}
shouldShowRedDotIndicator={false}
message={hintText}
style={styles.menuItemError}
/>
)}
</View>
)}
</PressableWithSecondaryInteraction>
)}
</Hoverable>
{!!helperText && <Text style={[styles.mutedNormalTextLabel, styles.ph5, styles.pb5, helperTextStyle]}>{helperText}</Text>}
</View>
</EducationalTooltip>
</View>
);
}
MenuItem.displayName = 'MenuItem';
export type {AvatarProps, IconProps, MenuItemBaseProps, MenuItemProps, NoIcon};
export default forwardRef(MenuItem);