Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tooltip and change background color of subscription icon #35795

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/components/SubscriptAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {memo} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import type {ValueOf} from 'type-fest';
import useStyleUtils from '@hooks/useStyleUtils';
Expand Down Expand Up @@ -46,9 +47,21 @@ type SubscriptAvatarProps = {

/** Whether to show the tooltip */
showTooltip?: boolean;

/** Additional style for container of subscription icon */
subscriptionContainerAdditionalStyles?: StyleProp<ViewStyle>;
};

function SubscriptAvatar({mainAvatar, secondaryAvatar, subscriptIcon, size = CONST.AVATAR_SIZE.DEFAULT, backgroundColor, noMargin = false, showTooltip = true}: SubscriptAvatarProps) {
function SubscriptAvatar({
mainAvatar,
secondaryAvatar,
subscriptIcon,
size = CONST.AVATAR_SIZE.DEFAULT,
backgroundColor,
noMargin = false,
showTooltip = true,
subscriptionContainerAdditionalStyles = undefined,
}: SubscriptAvatarProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -113,6 +126,7 @@ function SubscriptAvatar({mainAvatar, secondaryAvatar, subscriptIcon, size = CON
styles.subscriptIcon,
styles.dFlex,
styles.justifyContentCenter,
subscriptionContainerAdditionalStyles,
]}
// Hover on overflowed part of icon will not work on Electron if dragArea is true
// https://stackoverflow.com/questions/56338939/hover-in-css-is-not-working-with-electron
Expand Down
52 changes: 28 additions & 24 deletions src/components/WorkspaceSwitcherButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {Policy} from '@src/types/onyx';
import * as Expensicons from './Icon/Expensicons';
import {PressableWithFeedback} from './Pressable';
import SubscriptAvatar from './SubscriptAvatar';
import Tooltip from './Tooltip';

type WorkspaceSwitcherButtonOnyxProps = {
policy: OnyxEntry<Policy>;
Expand All @@ -38,30 +39,33 @@ function WorkspaceSwitcherButton({activeWorkspaceID, policy}: WorkspaceSwitcherB
}, [policy, activeWorkspaceID]);

return (
<PressableWithFeedback
accessibilityRole={CONST.ROLE.BUTTON}
accessibilityLabel={translate('common.workspaces')}
accessible
onPress={() =>
interceptAnonymousUser(() => {
Navigation.navigate(ROUTES.WORKSPACE_SWITCHER);
})
}
>
{({hovered}) => (
<SubscriptAvatar
mainAvatar={{source, name, type}}
subscriptIcon={{
source: Expensicons.DownArrow,
width: CONST.WORKSPACE_SWITCHER.SUBSCRIPT_ICON_SIZE,
height: CONST.WORKSPACE_SWITCHER.SUBSCRIPT_ICON_SIZE,
fill: hovered ? theme.buttonHoveredBG : theme.icon,
}}
showTooltip={false}
noMargin
/>
)}
</PressableWithFeedback>
<Tooltip text={translate('workspace.switcher.headerTitle')}>
<PressableWithFeedback
accessibilityRole={CONST.ROLE.BUTTON}
accessibilityLabel={translate('common.workspaces')}
accessible
onPress={() =>
interceptAnonymousUser(() => {
Navigation.navigate(ROUTES.WORKSPACE_SWITCHER);
})
}
>
{({hovered}) => (
<SubscriptAvatar
mainAvatar={{source, name, type}}
subscriptIcon={{
source: Expensicons.DownArrow,
width: CONST.WORKSPACE_SWITCHER.SUBSCRIPT_ICON_SIZE,
height: CONST.WORKSPACE_SWITCHER.SUBSCRIPT_ICON_SIZE,
fill: theme.icon,
}}
showTooltip={false}
noMargin
subscriptionContainerAdditionalStyles={hovered && {backgroundColor: theme.buttonHoveredBG}}
/>
)}
</PressableWithFeedback>
</Tooltip>
);
}

Expand Down
Loading