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

Updated button specification with Icon #37966

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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
1 change: 1 addition & 0 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ function AttachmentModal({
<Animated.View style={[StyleUtils.fade(confirmButtonFadeAnimation), safeAreaPaddingBottomStyle]}>
<Button
success
large
style={[styles.buttonConfirm, isSmallScreenWidth ? {} : styles.attachmentButtonBigScreen]}
textStyles={[styles.buttonConfirmText]}
text={translate('common.send')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function CarouselButtons({page, attachments, shouldShowArrows, onBack, onForward
innerStyles={[styles.arrowIcon]}
icon={Expensicons.BackArrow}
iconFill={theme.text}
iconStyles={[styles.mr0]}
onPress={onBack}
onPressIn={cancelAutoHideArrow}
onPressOut={autoHideArrow}
Expand All @@ -70,7 +69,6 @@ function CarouselButtons({page, attachments, shouldShowArrows, onBack, onForward
innerStyles={[styles.arrowIcon]}
icon={Expensicons.ArrowRight}
iconFill={theme.text}
iconStyles={[styles.mr0]}
onPress={onForward}
onPressIn={cancelAutoHideArrow}
onPressOut={autoHideArrow}
Expand Down
2 changes: 1 addition & 1 deletion src/components/AvatarCropModal/AvatarCropModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ function AvatarCropModal({imageUri = '', imageName = '', imageType = '', onClose
medium
icon={Expensicons.Rotate}
iconFill={theme.inverse}
iconStyles={[styles.mr0]}
onPress={rotateImage}
/>
</View>
Expand All @@ -421,6 +420,7 @@ function AvatarCropModal({imageUri = '', imageName = '', imageType = '', onClose
style={[styles.m5]}
onPress={cropAndSaveImage}
pressOnEnter
large
text={translate('common.save')}
/>
</ScreenWrapper>
Expand Down
39 changes: 20 additions & 19 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Text from '@components/Text';
import withNavigationFallback from '@components/withNavigationFallback';
import useActiveElementRole from '@hooks/useActiveElementRole';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import HapticFeedback from '@libs/HapticFeedback';
Expand All @@ -18,18 +19,7 @@ import type ChildrenProps from '@src/types/utils/ChildrenProps';
import type IconAsset from '@src/types/utils/IconAsset';
import validateSubmitShortcut from './validateSubmitShortcut';

type ButtonWithText = {
/** The text for the button label */
text?: string;

/** Boolean whether to display the right icon */
shouldShowRightIcon?: boolean;

/** The icon asset to display to the left of the text */
icon?: IconAsset | null;
};

type ButtonProps = (ButtonWithText | ChildrenProps) & {
type ButtonProps = Partial<ChildrenProps> & {
/** Should the press event bubble across multiple instances when Enter key triggers it. */
allowBubble?: boolean;

Expand Down Expand Up @@ -116,6 +106,15 @@ type ButtonProps = (ButtonWithText | ChildrenProps) & {

/** Accessibility label for the component */
accessibilityLabel?: string;

/** The icon asset to display to the left of the text */
icon?: IconAsset | null;

/** The text for the button label */
text?: string;

/** Boolean whether to display the right icon */
shouldShowRightIcon?: boolean;
};

type KeyboardShortcutComponentProps = Pick<ButtonProps, 'isDisabled' | 'isLoading' | 'onPress' | 'pressOnEnter' | 'allowBubble' | 'enterKeyEventListenerPriority'>;
Expand Down Expand Up @@ -162,8 +161,10 @@ function Button(

iconRight = Expensicons.ArrowRight,
iconFill,
icon = null,
iconStyles = [],
iconRightStyles = [],
text = '',

small = false,
large = false,
Expand Down Expand Up @@ -193,6 +194,7 @@ function Button(
shouldRemoveLeftBorderRadius = false,
shouldEnableHapticFeedback = false,
isLongPressDisabled = false,
shouldShowRightIcon = false,

id = '',
accessibilityLabel = '',
Expand All @@ -202,14 +204,13 @@ function Button(
) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

const renderContent = () => {
if ('children' in rest) {
return rest.children;
}

const {text = '', icon = null, shouldShowRightIcon = false} = rest;

const textComponent = (
<Text
numberOfLines={1}
Expand Down Expand Up @@ -237,11 +238,13 @@ function Button(
<View style={[styles.justifyContentBetween, styles.flexRow]}>
<View style={[styles.alignItemsCenter, styles.flexRow, styles.flexShrink1]}>
{icon && (
<View style={[styles.mr1, iconStyles]}>
<View style={[large ? styles.mr2 : styles.mr1, !text && styles.mr0, iconStyles]}>
<Icon
src={icon}
fill={iconFill ?? (success || danger ? theme.textLight : theme.icon)}
small={small}
medium={medium}
large={large}
/>
</View>
)}
Expand Down Expand Up @@ -310,17 +313,15 @@ function Button(
]}
style={[
styles.button,
small ? styles.buttonSmall : undefined,
medium ? styles.buttonMedium : undefined,
large ? styles.buttonLarge : undefined,
StyleUtils.getButtonStyleWithIcon(styles, small, medium, large, Boolean(icon), Boolean(text?.length > 0)),
success ? styles.buttonSuccess : undefined,
danger ? styles.buttonDanger : undefined,
isDisabled ? styles.buttonOpacityDisabled : undefined,
isDisabled && !danger && !success ? styles.buttonDisabled : undefined,
shouldRemoveRightBorderRadius ? styles.noRightBorderRadius : undefined,
shouldRemoveLeftBorderRadius ? styles.noLeftBorderRadius : undefined,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
'text' in rest && rest?.shouldShowRightIcon ? styles.alignItemsStretch : undefined,
text && shouldShowRightIcon ? styles.alignItemsStretch : undefined,
innerStyles,
]}
hoverStyle={[
Expand Down
2 changes: 2 additions & 0 deletions src/components/ConfirmContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ function ConfirmContent({
style={[styles.mt4]}
onPress={onConfirm}
pressOnEnter
large
text={confirmText || translate('common.yes')}
isDisabled={isOffline && shouldDisableConfirmButtonWhenOffline}
/>
{shouldShowCancelButton && (
<Button
style={[styles.mt3, styles.noSelect]}
onPress={onCancel}
large
text={cancelText || translate('common.no')}
/>
)}
Expand Down
1 change: 1 addition & 0 deletions src/components/ConfirmationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function ConfirmationPage({animation = LottieAnimations.Fireworks, heading, desc
<FixedFooter>
<Button
success
large
text={buttonText}
style={styles.mt6}
pressOnEnter
Expand Down
3 changes: 0 additions & 3 deletions src/components/ConnectBankAccountButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import * as ReimbursementAccount from '@userActions/ReimbursementAccount';
import Button from './Button';
Expand All @@ -19,7 +18,6 @@ type ConnectBankAccountButtonProps = {
};

function ConnectBankAccountButton({style, policyID}: ConnectBankAccountButtonProps) {
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const activeRoute = Navigation.getActiveRouteWithoutParams();
Expand All @@ -34,7 +32,6 @@ function ConnectBankAccountButton({style, policyID}: ConnectBankAccountButtonPro
onPress={() => ReimbursementAccount.navigateToBankAccountRoute(policyID, activeRoute)}
icon={Expensicons.Bank}
style={style}
iconStyles={styles.buttonCTAIcon}
shouldShowRightIcon
large
success
Expand Down
1 change: 1 addition & 0 deletions src/components/DistanceRequest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ function DistanceRequest({transactionID = '', report, transaction, route, isEdit
<Button
success
allowBubble
large
pressOnEnter
style={[styles.w100, styles.mb4, styles.ph4, styles.flexShrink0]}
onPress={submitWaypoints}
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeatureList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ function FeatureList({
icon={icon}
iconWidth={variables.avatarSizeMedium}
iconHeight={variables.avatarSizeMedium}
iconStyles={styles.mr2}
interactive={false}
displayInDefaultIconColor
wrapperStyle={[styles.p0, styles.cursorAuto]}
Expand All @@ -96,6 +95,7 @@ function FeatureList({
accessibilityLabel={ctaAccessibilityLabel}
style={styles.w100}
success
large
/>
</View>
</Section>
Expand Down
2 changes: 2 additions & 0 deletions src/components/FormAlertWithSubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function FormAlertWithSubmitButton({
style={style}
danger={isSubmitActionDangerous}
medium={useSmallerSubmitButtonSize}
large={!useSmallerSubmitButtonSize}
/>
) : (
<Button
Expand All @@ -108,6 +109,7 @@ function FormAlertWithSubmitButton({
isLoading={isLoading}
danger={isSubmitActionDangerous}
medium={useSmallerSubmitButtonSize}
large={!useSmallerSubmitButtonSize}
/>
)}
{footerContent}
Expand Down
11 changes: 9 additions & 2 deletions src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ type IconProps = {
/** Is small icon */
small?: boolean;

/** Is large icon */
large?: boolean;

/** Is medium icon */
medium?: boolean;

/** Is inline icon */
inline?: boolean;

Expand All @@ -50,6 +56,8 @@ function Icon({
height = variables.iconSizeNormal,
fill = undefined,
small = false,
large = false,
medium = false,
inline = false,
additionalStyles = [],
hovered = false,
Expand All @@ -59,8 +67,7 @@ function Icon({
}: IconProps) {
const StyleUtils = useStyleUtils();
const styles = useThemeStyles();
const iconWidth = small ? variables.iconSizeSmall : width;
const iconHeight = small ? variables.iconSizeSmall : height;
const {width: iconWidth, height: iconHeight} = StyleUtils.getIconWidthAndHeightStyle(small, medium, large, width, height);
const iconStyles = [StyleUtils.getWidthAndHeightStyle(width ?? 0, height), IconWrapperStyles, styles.pAbsolute, additionalStyles];

if (inline) {
Expand Down
1 change: 1 addition & 0 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ class BaseOptionsSelector extends Component {
{shouldShowDefaultConfirmButton && (
<Button
success
large
style={[this.props.themeStyles.w100]}
text={defaultConfirmButtonText}
onPress={this.props.onConfirmSelection}
Expand Down
1 change: 1 addition & 0 deletions src/components/PDFView/PDFPasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function PDFPasswordForm({isFocused, isPasswordInvalid, shouldShowLoadingIndicat
style={styles.mt4}
isLoading={shouldShowLoadingIndicator}
pressOnEnter
large
/>
</ScrollView>
) : (
Expand Down
1 change: 1 addition & 0 deletions src/components/ProcessMoneyRequestHoldMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function ProcessMoneyRequestHoldMenu({isVisible, onClose, onConfirm, anchorPosit
style={[styles.mt5]}
text={translate('common.buttonConfirm')}
onPress={onConfirm}
large
/>
</View>
</Popover>
Expand Down
1 change: 1 addition & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ function BaseSelectionList<TItem extends ListItem>(
<FixedFooter style={[styles.mtAuto]}>
<Button
success
large
style={[styles.w100]}
text={confirmButtonText || translate('common.confirm')}
onPress={onConfirm}
Expand Down
3 changes: 3 additions & 0 deletions src/components/TimePicker/TimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ function TimePicker({forwardedRef, defaultValue, onSubmit, onInputChange}) {
shouldEnableHapticFeedback
innerStyles={styleForAM}
medium={isExtraSmallScreenHeight}
large={!isExtraSmallScreenHeight}
text={translate('common.am')}
onLongPress={() => {}}
onPress={() => {
Expand All @@ -523,6 +524,7 @@ function TimePicker({forwardedRef, defaultValue, onSubmit, onInputChange}) {
shouldEnableHapticFeedback
innerStyles={[...styleForPM, styles.ml1]}
medium={isExtraSmallScreenHeight}
large={!isExtraSmallScreenHeight}
text={translate('common.pm')}
onLongPress={() => {}}
onPress={() => {
Expand Down Expand Up @@ -551,6 +553,7 @@ function TimePicker({forwardedRef, defaultValue, onSubmit, onInputChange}) {
<Button
success
medium={isExtraSmallScreenHeight}
large={!isExtraSmallScreenHeight}
style={[styles.mb5, styles.mh5]}
onPress={handleSubmit}
pressOnEnter
Expand Down
1 change: 1 addition & 0 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ function NewChatPage({isGroupChat, reports, isSearchingForReports}: NewChatPageP
text={selectedOptions.length > 1 ? translate('newChatPage.createGroup') : translate('newChatPage.createChat')}
onPress={createGroup}
pressOnEnter
large
/>
)}
</>
Expand Down
1 change: 1 addition & 0 deletions src/pages/OnboardEngagement/ExpensifyClassicPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function ExpensifyClassicModal() {
success
pressOnEnter
medium={isExtraSmallScreenHeight}
large={!isExtraSmallScreenHeight}
style={[styles.w100, styles.mtAuto]}
text={translate('expensifyClassic.buttonText')}
onPress={navigateToOldDot}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/OnboardEngagement/ManageTeamsExpensesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ function ManageTeamsExpensesModal() {
<View style={styles.flexRow}>
<Button
medium={isExtraSmallScreenHeight}
large={!isExtraSmallScreenHeight}
style={[styles.flexGrow1, styles.mr1, styles.mtAuto]}
text={translate('common.no')}
onPress={completeEngagement}
/>
<Button
pressOnEnter
medium={isExtraSmallScreenHeight}
large={!isExtraSmallScreenHeight}
style={[styles.flexGrow1, styles.ml1, styles.mtAuto]}
text={translate('common.yes')}
onPress={navigateToExpensifyClassicPage}
Expand Down
1 change: 1 addition & 0 deletions src/pages/ProcessMoneyRequestHoldPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function ProcessMoneyRequestHoldPage() {
success
text={translate('common.buttonConfirm')}
onPress={onConfirm}
large
/>
),
[onConfirm, translate],
Expand Down
1 change: 0 additions & 1 deletion src/pages/ReimbursementAccount/BankAccountStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ function BankAccountStep(props) {
}}
isDisabled={props.isPlaidDisabled || !props.user.validated}
style={[styles.mt4]}
iconStyles={[styles.buttonCTAIcon]}
shouldShowRightIcon
success
large
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function Confirmation({reimbursementAccount, reimbursementAccountDraft, onNext,
success
style={[styles.w100]}
onPress={onNext}
large
text={translate('common.confirm')}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function ConfirmationUBO({reimbursementAccount, reimbursementAccountDraft, onNex
<Button
isDisabled={isOffline}
success
large
style={[styles.w100, styles.mt2, styles.pb5]}
onPress={onNext}
text={translate('common.confirm')}
Expand Down
Loading
Loading