Skip to content

Commit

Permalink
Merge pull request #34143 from JKobrynski/migrateThreeDotsMenuToTypeS…
Browse files Browse the repository at this point in the history
…cript
  • Loading branch information
youssef-lr authored Jan 24, 2024
2 parents 26af6d1 + d203ab4 commit e78c54e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 165 deletions.
104 changes: 0 additions & 104 deletions src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/HeaderWithBackButton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type IconAsset from '@src/types/utils/IconAsset';

type ThreeDotsMenuItem = {
/** An icon element displayed on the left side */
icon?: IconAsset;
icon: IconAsset;

/** Text label */
text: string;
Expand Down
1 change: 1 addition & 0 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ function PopoverMenu({
PopoverMenu.displayName = 'PopoverMenu';

export default React.memo(PopoverMenu);
export type {PopoverMenuItem};
12 changes: 0 additions & 12 deletions src/components/ThreeDotsMenu/ThreeDotsMenuItemPropTypes.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import PropTypes from 'prop-types';
import React, {useRef, useState} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import _ from 'underscore';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import sourcePropTypes from '@components/Image/sourcePropTypes';
import type {AnchorAlignment} from '@components/Popover/types';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import PopoverMenu from '@components/PopoverMenu';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import Tooltip from '@components/Tooltip/PopoverAnchorTooltip';
Expand All @@ -13,68 +13,61 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Browser from '@libs/Browser';
import CONST from '@src/CONST';
import ThreeDotsMenuItemPropTypes from './ThreeDotsMenuItemPropTypes';
import type {TranslationPaths} from '@src/languages/types';
import type {AnchorPosition} from '@src/styles';
import type IconAsset from '@src/types/utils/IconAsset';

const propTypes = {
type ThreeDotsMenuProps = {
/** Tooltip for the popup icon */
iconTooltip: PropTypes.string,
iconTooltip?: TranslationPaths;

/** icon for the popup trigger */
icon: PropTypes.oneOfType([PropTypes.string, sourcePropTypes]),
icon?: IconAsset;

/** Any additional styles to pass to the icon container. */
// eslint-disable-next-line react/forbid-prop-types
iconStyles: PropTypes.arrayOf(PropTypes.object),
iconStyles?: StyleProp<ViewStyle>;

/** The fill color to pass into the icon. */
iconFill: PropTypes.string,
iconFill?: string;

/** Function to call on icon press */
onIconPress: PropTypes.func,
onIconPress?: () => void;

/** menuItems that'll show up on toggle of the popup menu */
menuItems: ThreeDotsMenuItemPropTypes.isRequired,
menuItems: PopoverMenuItem[];

/** The anchor position of the menu */
anchorPosition: PropTypes.shape({
top: PropTypes.number,
right: PropTypes.number,
bottom: PropTypes.number,
left: PropTypes.number,
}).isRequired,
anchorPosition: AnchorPosition;

/** The anchor alignment of the menu */
anchorAlignment: PropTypes.shape({
horizontal: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL)),
vertical: PropTypes.oneOf(_.values(CONST.MODAL.ANCHOR_ORIGIN_VERTICAL)),
}),
anchorAlignment?: AnchorAlignment;

/** Whether the popover menu should overlay the current view */
shouldOverlay: PropTypes.bool,
shouldOverlay?: boolean;

/** Whether the menu is disabled */
disabled: PropTypes.bool,
disabled?: boolean;

/** Should we announce the Modal visibility changes? */
shouldSetModalVisibility: PropTypes.bool,
shouldSetModalVisibility?: boolean;
};

const defaultProps = {
iconTooltip: 'common.more',
disabled: false,
iconFill: undefined,
iconStyles: [],
icon: Expensicons.ThreeDots,
onIconPress: () => {},
anchorAlignment: {
function ThreeDotsMenu({
iconTooltip = 'common.more',
icon = Expensicons.ThreeDots,
iconFill,
iconStyles,
onIconPress = () => {},
menuItems,
anchorPosition,
anchorAlignment = {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP, // we assume that popover menu opens below the button, anchor is at TOP
},
shouldOverlay: false,
shouldSetModalVisibility: true,
};

function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, menuItems, anchorPosition, anchorAlignment, shouldOverlay, shouldSetModalVisibility, disabled}) {
shouldOverlay = false,
shouldSetModalVisibility = true,
disabled = false,
}: ThreeDotsMenuProps) {
const theme = useTheme();
const styles = useThemeStyles();
const [isPopupMenuVisible, setPopupMenuVisible] = useState(false);
Expand Down Expand Up @@ -113,13 +106,13 @@ function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, me
e.preventDefault();
}}
ref={buttonRef}
style={[styles.touchableButtonImage, ...iconStyles]}
style={[styles.touchableButtonImage, iconStyles]}
role={CONST.ROLE.BUTTON}
accessibilityLabel={translate(iconTooltip)}
>
<Icon
src={icon}
fill={iconFill || theme.icon}
fill={iconFill ?? theme.icon}
/>
</PressableWithoutFeedback>
</Tooltip>
Expand All @@ -139,10 +132,6 @@ function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, me
);
}

ThreeDotsMenu.propTypes = propTypes;
ThreeDotsMenu.defaultProps = defaultProps;
ThreeDotsMenu.displayName = 'ThreeDotsMenu';

export default ThreeDotsMenu;

export {ThreeDotsMenuItemPropTypes};
8 changes: 4 additions & 4 deletions src/pages/workspace/WorkspacesListRow.tsx
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {ValueOf} from 'type-fest';
import Avatar from '@components/Avatar';
import Icon from '@components/Icon';
import * as Illustrations from '@components/Icon/Illustrations';
import type {MenuItemProps} from '@components/MenuItem';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import Text from '@components/Text';
import ThreeDotsMenu from '@components/ThreeDotsMenu';
import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentUserPersonalDetails';
Expand Down Expand Up @@ -34,7 +34,7 @@ type WorkspacesListRowProps = WithCurrentUserPersonalDetailsProps & {
fallbackWorkspaceIcon?: AvatarSource;

/** Items for the three dots menu */
menuItems: MenuItemProps[];
menuItems: PopoverMenuItem[];

/** Renders the component using big screen layout or small screen layout. When layoutWidth === WorkspaceListRowLayout.NONE,
* component will return null to prevent layout from jumping on initial render and when parent width changes. */
Expand Down Expand Up @@ -111,7 +111,7 @@ function WorkspacesListRow({
{isNarrow && (
<ThreeDotsMenu
menuItems={menuItems}
anchorPosition={{top: 0, right: 0}}
anchorPosition={{horizontal: 0, vertical: 0}}
/>
)}
</View>
Expand Down Expand Up @@ -165,7 +165,7 @@ function WorkspacesListRow({
{isWide && (
<ThreeDotsMenu
menuItems={menuItems}
anchorPosition={{top: 0, right: 0}}
anchorPosition={{horizontal: 0, vertical: 0}}
iconStyles={[styles.mr2]}
/>
)}
Expand Down

0 comments on commit e78c54e

Please sign in to comment.