Skip to content

Commit

Permalink
Merge pull request #40101 from dragnoir/38471-badge
Browse files Browse the repository at this point in the history
Default badge style
  • Loading branch information
arosiclair authored Apr 23, 2024
2 parents 65bab75 + 3323b34 commit 3a3cef6
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 77 deletions.
19 changes: 12 additions & 7 deletions src/components/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, {useCallback} from 'react';
import type {GestureResponderEvent, PressableStateCallbackType, StyleProp, TextStyle, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -61,15 +60,21 @@ function Badge({
}: BadgeProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const theme = useTheme();
const textColorStyles = success || error ? styles.textWhite : undefined;
const Wrapper = pressable ? PressableWithoutFeedback : View;

const isDeleted = style && Array.isArray(style) ? style.includes(styles.offlineFeedback.deleted) : false;

const iconColor = StyleUtils.getIconColorStyle(success, error);

const wrapperStyles: (state: PressableStateCallbackType) => StyleProp<ViewStyle> = useCallback(
({pressed}) => [styles.badge, styles.ml2, StyleUtils.getBadgeColorStyle(success, error, pressed, environment === CONST.ENVIRONMENT.ADHOC), badgeStyles],
[styles.badge, styles.ml2, StyleUtils, success, error, environment, badgeStyles],
({pressed}) => [
styles.defaultBadge,
styles.alignSelfCenter,
styles.ml2,
StyleUtils.getBadgeColorStyle(success, error, pressed, environment === CONST.ENVIRONMENT.ADHOC),
badgeStyles,
],
[styles.defaultBadge, styles.alignSelfCenter, styles.ml2, StyleUtils, success, error, environment, badgeStyles],
);

return (
Expand All @@ -87,12 +92,12 @@ function Badge({
width={variables.iconSizeExtraSmall}
height={variables.iconSizeExtraSmall}
src={icon}
fill={theme.icon}
fill={iconColor}
/>
</View>
)}
<Text
style={[styles.badgeText, textColorStyles, textStyles, isDeleted ? styles.offlineFeedback.deleted : {}]}
style={[styles.badgeText, styles.textStrong, textStyles, isDeleted ? styles.offlineFeedback.deleted : {}]}
numberOfLines={1}
>
{text}
Expand Down
14 changes: 11 additions & 3 deletions src/components/EnvironmentBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import useEnvironment from '@hooks/useEnvironment';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Environment from '@libs/Environment/Environment';
import CONST from '@src/CONST';
Expand All @@ -15,8 +16,15 @@ const ENVIRONMENT_SHORT_FORM = {

function EnvironmentBadge() {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {environment, isProduction} = useEnvironment();

const adhoc = environment === CONST.ENVIRONMENT.ADHOC;
const success = environment === CONST.ENVIRONMENT.STAGING;
const error = environment !== CONST.ENVIRONMENT.STAGING && environment !== CONST.ENVIRONMENT.ADHOC;

const badgeEnviromentStyle = StyleUtils.getEnvironmentBadgeStyle(success, error, adhoc);

// If we are on production, don't show any badge
if (isProduction) {
return null;
Expand All @@ -26,10 +34,10 @@ function EnvironmentBadge() {

return (
<Badge
success={environment === CONST.ENVIRONMENT.STAGING || environment === CONST.ENVIRONMENT.ADHOC}
error={environment !== CONST.ENVIRONMENT.STAGING && environment !== CONST.ENVIRONMENT.ADHOC}
success={success}
error={error}
text={text}
badgeStyles={[styles.alignSelfStart, styles.headerEnvBadge]}
badgeStyles={[styles.alignSelfStart, styles.headerEnvBadge, styles.environmentBadge, badgeEnviromentStyle]}
textStyles={[styles.headerEnvBadgeText, {fontWeight: '700'}]}
environment={environment}
pressable
Expand Down
9 changes: 1 addition & 8 deletions src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,7 @@ function MenuItem(
{badgeText && (
<Badge
text={badgeText}
textStyles={styles.textStrong}
badgeStyles={[
styles.alignSelfCenter,
styles.badgeBordered,
brickRoadIndicator ? styles.mr2 : undefined,
focused || isHovered || pressed ? styles.activeItemBadge : {},
badgeStyle,
]}
badgeStyles={badgeStyle}
/>
)}
{/* Since subtitle can be of type number, we should allow 0 to be shown */}
Expand Down
12 changes: 2 additions & 10 deletions src/pages/NewChatConfirmPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import InviteMemberListItem from '@components/SelectionList/InviteMemberListItem
import type {ListItem} from '@components/SelectionList/types';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -41,7 +40,6 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
const fileRef = useRef<File | CustomRNImageManipulatorResult | undefined>();
const {translate} = useLocalize();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const personalData = useCurrentUserPersonalDetails();
const participantAccountIDs = (newGroupDraft?.participants ?? []).map((participant) => participant.accountID);
const selectedOptions = useMemo((): Participant[] => {
Expand Down Expand Up @@ -70,18 +68,12 @@ function NewChatConfirmPage({newGroupDraft, allPersonalDetails}: NewChatConfirmP
accountID,
icons: selectedOption?.icons,
alternateText: selectedOption?.login ?? '',
rightElement: isAdmin ? (
<Badge
text={translate('common.admin')}
textStyles={styles.textStrong}
badgeStyles={[styles.justifyContentCenter, StyleUtils.getMinimumWidth(60), styles.badgeBordered]}
/>
) : undefined,
rightElement: isAdmin ? <Badge text={translate('common.admin')} /> : undefined,
};
return section;
})
.sort((a, b) => a.text?.toLowerCase().localeCompare(b.text?.toLowerCase() ?? '') ?? -1),
[selectedOptions, personalData.accountID, translate, StyleUtils, styles],
[selectedOptions, personalData.accountID, translate],
);

/**
Expand Down
10 changes: 2 additions & 8 deletions src/pages/ReportParticipantsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ function ReportParticipantsPage({report, personalDetails, session}: ReportPartic
const isAdmin = role === CONST.REPORT.ROLE.ADMIN;
let roleBadge = null;
if (isAdmin) {
roleBadge = (
<Badge
text={translate('common.admin')}
textStyles={styles.textStrong}
badgeStyles={[styles.justifyContentCenter, StyleUtils.getMinimumWidth(60), styles.badgeBordered, isSelected && styles.activeItemBadge]}
/>
);
roleBadge = <Badge text={translate('common.admin')} />;
}

result.push({
Expand All @@ -115,7 +109,7 @@ function ReportParticipantsPage({report, personalDetails, session}: ReportPartic

result = result.sort((a, b) => (a.text ?? '').toLowerCase().localeCompare((b.text ?? '').toLowerCase()));
return result;
}, [formatPhoneNumber, personalDetails, report, selectedMembers, currentUserAccountID, translate, styles, StyleUtils, isGroupChat]);
}, [formatPhoneNumber, personalDetails, report, selectedMembers, currentUserAccountID, translate, isGroupChat]);

const participants = useMemo(() => getUsers(), [getUsers]);

Expand Down
13 changes: 1 addition & 12 deletions src/pages/workspace/WorkspaceMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,7 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft,
const isAdmin = policyEmployee.role === CONST.POLICY.ROLE.ADMIN;
let roleBadge = null;
if (isOwner || isAdmin) {
roleBadge = (
<Badge
text={isOwner ? translate('common.owner') : translate('common.admin')}
textStyles={styles.textStrong}
badgeStyles={[styles.justifyContentCenter, StyleUtils.getMinimumWidth(60), styles.badgeBordered, isSelected && styles.activeItemBadge]}
/>
);
roleBadge = <Badge text={isOwner ? translate('common.owner') : translate('common.admin')} />;
}

result.push({
Expand Down Expand Up @@ -374,7 +368,6 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft,
result = result.sort((a, b) => (a.text ?? '').toLowerCase().localeCompare((b.text ?? '').toLowerCase()));
return result;
}, [
StyleUtils,
currentUserLogin,
formatPhoneNumber,
invitedPrimaryToSecondaryLogins,
Expand All @@ -388,10 +381,6 @@ function WorkspaceMembersPage({personalDetails, invitedEmailsToAccountIDsDraft,
policyOwner,
selectedEmployees,
session?.accountID,
styles.activeItemBadge,
styles.badgeBordered,
styles.justifyContentCenter,
styles.textStrong,
translate,
]);

Expand Down
2 changes: 0 additions & 2 deletions src/pages/workspace/WorkspacesListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ function WorkspacesListRow({
>
<Badge
text={translate('workspace.common.requested')}
textStyles={styles.textStrong}
badgeStyles={[styles.alignSelfCenter, styles.badgeBordered]}
icon={Expensicons.Hourglass}
/>
</View>
Expand Down
14 changes: 2 additions & 12 deletions src/pages/workspace/workflows/WorkspaceWorkflowsApproverPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import type {ListItem, Section} from '@components/SelectionList/types';
import UserListItem from '@components/SelectionList/UserListItem';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -46,8 +44,6 @@ function WorkspaceWorkflowsApproverPage({policy, personalDetails, isLoadingRepor
const policyName = policy?.name ?? '';
const [searchTerm, setSearchTerm] = useState('');
const {isOffline} = useNetwork();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

const isDeletedPolicyEmployee = useCallback(
(policyEmployee: PolicyEmployee) => !isOffline && policyEmployee.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && isEmptyObject(policyEmployee.errors),
Expand Down Expand Up @@ -78,13 +74,7 @@ function WorkspaceWorkflowsApproverPage({policy, personalDetails, isLoadingRepor

let roleBadge = null;
if (isOwner || isAdmin) {
roleBadge = (
<Badge
text={isOwner ? translate('common.owner') : translate('common.admin')}
textStyles={styles.textStrong}
badgeStyles={[styles.justifyContentCenter, StyleUtils.getMinimumWidth(60), styles.badgeBordered]}
/>
);
roleBadge = <Badge text={isOwner ? translate('common.owner') : translate('common.admin')} />;
}

const formattedMember = {
Expand Down Expand Up @@ -114,7 +104,7 @@ function WorkspaceWorkflowsApproverPage({policy, personalDetails, isLoadingRepor
}
});
return [policyMemberDetails, approverDetails];
}, [personalDetails, translate, policy?.approver, StyleUtils, isDeletedPolicyEmployee, policy?.owner, styles, policy?.employeeList]);
}, [personalDetails, translate, policy?.approver, isDeletedPolicyEmployee, policy?.owner, policy?.employeeList]);

const sections: MembersSection[] = useMemo(() => {
const sectionsArray: MembersSection[] = [];
Expand Down
14 changes: 2 additions & 12 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import type {ListItem, Section} from '@components/SelectionList/types';
import UserListItem from '@components/SelectionList/UserListItem';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -44,8 +42,6 @@ type MembersSection = SectionListData<MemberOption, Section<MemberOption>>;

function WorkspaceWorkflowsPayerPage({route, policy, personalDetails, isLoadingReportData = true}: WorkspaceWorkflowsPayerPageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const policyName = policy?.name ?? '';
const {isOffline} = useNetwork();

Expand Down Expand Up @@ -78,13 +74,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, personalDetails, isLoadingR
return;
}

const roleBadge = (
<Badge
text={isOwner ? translate('common.owner') : translate('common.admin')}
textStyles={styles.textStrong}
badgeStyles={[styles.justifyContentCenter, StyleUtils.getMinimumWidth(60), styles.badgeBordered]}
/>
);
const roleBadge = <Badge text={isOwner ? translate('common.owner') : translate('common.admin')} />;

const isAuthorizedPayer = policy?.achAccount?.reimburser === details?.login;

Expand Down Expand Up @@ -115,7 +105,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, personalDetails, isLoadingR
}
});
return [policyAdminDetails, authorizedPayerDetails];
}, [personalDetails, policy?.employeeList, translate, policy?.achAccount?.reimburser, isDeletedPolicyEmployee, policy?.owner, styles, StyleUtils, policy?.pendingFields?.reimburser]);
}, [personalDetails, policy?.employeeList, translate, policy?.achAccount?.reimburser, isDeletedPolicyEmployee, policy?.owner, policy?.pendingFields?.reimburser]);

const sections: MembersSection[] = useMemo(() => {
const sectionsArray: MembersSection[] = [];
Expand Down
36 changes: 33 additions & 3 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Styles = Record<
// touchCallout is an iOS safari only property that controls the display of the callout information when you touch and hold a target
const touchCalloutNone: Pick<ViewStyle, 'WebkitTouchCallout'> = Browser.isMobileSafari() ? {WebkitTouchCallout: 'none'} : {};
// to prevent vertical text offset in Safari for badges, new lineHeight values have been added
const lineHeightBadge: Pick<ViewStyle, 'lineHeight'> = Browser.isSafari() ? {lineHeight: variables.lineHeightXSmall} : {lineHeight: variables.lineHeightNormal};
const lineHeightBadge: Pick<TextStyle, 'lineHeight'> = Browser.isSafari() ? {lineHeight: variables.lineHeightXSmall} : {lineHeight: variables.lineHeightNormal};

const picker = (theme: ThemeColors) =>
({
Expand Down Expand Up @@ -842,28 +842,57 @@ const styles = (theme: ThemeColors) =>
alignItems: 'center',
},

defaultBadge: {
backgroundColor: theme.transparent,
borderWidth: 1,
borderRadius: variables.componentBorderRadiusSmall,
borderColor: theme.buttonHoveredBG,
paddingHorizontal: 12,
minHeight: 28,
height: variables.iconSizeNormal,
flexDirection: 'row',
alignItems: 'center',
},

environmentBadge: {
minHeight: 12,
borderRadius: 14,
paddingHorizontal: 7,
minWidth: 22,
borderWidth: 0,
},

badgeSuccess: {
borderColor: theme.success,
},

badgeEnvironmentSuccess: {
backgroundColor: theme.success,
},

badgeSuccessPressed: {
backgroundColor: theme.successHover,
borderColor: theme.successHover,
},

badgeAdHocSuccess: {
backgroundColor: theme.badgeAdHoc,
minWidth: 28,
},

badgeAdHocSuccessPressed: {
backgroundColor: theme.badgeAdHocHover,
},

badgeDanger: {
borderColor: theme.danger,
},

badgeEnvironmentDanger: {
backgroundColor: theme.danger,
},

badgeDangerPressed: {
backgroundColor: theme.dangerPressed,
borderColor: theme.dangerPressed,
},

badgeBordered: {
Expand Down Expand Up @@ -4000,6 +4029,7 @@ const styles = (theme: ThemeColors) =>
fontSize: 7,
fontWeight: FontUtils.fontWeight.bold,
lineHeight: undefined,
color: theme.textLight,
},

expensifyQrLogo: {
Expand Down
1 change: 1 addition & 0 deletions src/styles/theme/themes/dark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const darkTheme = {
iconHovered: colors.productDark900,
iconMenuHovered: colors.green400,
iconSuccessFill: colors.green400,
iconDangerFill: colors.red,
iconReversed: colors.productDark100,
iconColorfulBackground: `${colors.ivory}cc`,
textSupporting: colors.productDark800,
Expand Down
1 change: 1 addition & 0 deletions src/styles/theme/themes/light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const lightTheme = {
iconHovered: colors.productLight900,
iconMenuHovered: colors.green400,
iconSuccessFill: colors.green400,
iconDangerFill: colors.red,
iconReversed: colors.productLight100,
iconColorfulBackground: `${colors.ivory}cc`,
textSupporting: colors.productLight800,
Expand Down
1 change: 1 addition & 0 deletions src/styles/theme/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ThemeColors = {
iconHovered: Color;
iconMenuHovered: Color;
iconSuccessFill: Color;
iconDangerFill: Color;
iconReversed: Color;
iconColorfulBackground: Color;
textSupporting: Color;
Expand Down
Loading

0 comments on commit 3a3cef6

Please sign in to comment.