From 0eed1cfec1b0caac35930529dfd9ac92bf38606f Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 20 Sep 2024 11:38:51 -0500 Subject: [PATCH] [Neue] Buttons (#5406) * Re-align button sizing (cherry picked from commit bcec243bb59dfe468313d98ba61f464d9750feec) * Use large, small, tiny (cherry picked from commit 1dc333c2993ab7f2e0ac750c0670dcec9a7069d0) * Tweaks --- src/components/Button.tsx | 148 +++++++++++++----- src/components/Prompt.tsx | 4 +- .../Wizard/WizardEditListDialog.tsx | 2 +- .../StarterPack/Wizard/WizardListCard.tsx | 2 +- src/components/dialogs/BirthDateSettings.tsx | 2 +- src/components/dialogs/Embed.tsx | 2 +- src/components/dialogs/EmbedConsent.tsx | 6 +- src/components/dialogs/GifSelect.ios.tsx | 2 +- src/components/dialogs/GifSelect.tsx | 2 +- src/components/dialogs/MutedWords.tsx | 2 +- .../dialogs/PostInteractionSettingsDialog.tsx | 2 +- src/components/dms/MessagesNUX.tsx | 2 +- src/components/forms/DateField/index.tsx | 2 +- .../intents/VerifyEmailIntentDialog.tsx | 4 +- .../moderation/LabelsOnMeDialog.tsx | 4 +- src/screens/Deactivated.tsx | 6 +- .../E2E/SharedPreferencesTesterScreen.tsx | 12 +- src/screens/Home/NoFeedsPinned.tsx | 4 +- src/screens/List/ListHiddenScreen.tsx | 8 +- src/screens/Login/ChooseAccountForm.tsx | 2 +- src/screens/Login/ForgotPasswordForm.tsx | 6 +- src/screens/Login/LoginForm.tsx | 6 +- src/screens/Login/PasswordUpdatedForm.tsx | 2 +- src/screens/Login/SetNewPasswordForm.tsx | 4 +- .../Messages/Conversation/ChatDisabled.tsx | 4 +- src/screens/Messages/List/index.tsx | 2 +- .../components/DeactivateAccountDialog.tsx | 2 +- src/screens/Signup/BackNextButtons.tsx | 6 +- .../StarterPack/StarterPackLandingScreen.tsx | 2 +- src/screens/StarterPack/StarterPackScreen.tsx | 4 +- src/screens/StarterPack/Wizard/index.tsx | 2 +- src/view/com/composer/GifAltText.tsx | 2 +- .../com/composer/threadgate/ThreadgateBtn.tsx | 2 +- .../com/composer/videos/SubtitleDialog.tsx | 4 +- .../composer/videos/SubtitleFilePicker.tsx | 2 +- src/view/com/notifications/FeedItem.tsx | 2 +- src/view/com/util/post-ctrls/RepostButton.tsx | 2 +- .../web-controls/ControlButton.tsx | 2 +- src/view/screens/Storybook/Buttons.tsx | 131 ++++++++++------ src/view/screens/Storybook/index.tsx | 2 + 40 files changed, 258 insertions(+), 149 deletions(-) diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 704aa9d987..8728b88c2c 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -14,7 +14,7 @@ import { } from 'react-native' import {LinearGradient} from 'expo-linear-gradient' -import {android, atoms as a, flatten, select, tokens, useTheme} from '#/alf' +import {atoms as a, flatten, select, tokens, useTheme, web} from '#/alf' import {Props as SVGIconProps} from '#/components/icons/common' import {Text} from '#/components/Typography' @@ -30,7 +30,7 @@ export type ButtonColor = | 'gradient_sunset' | 'gradient_nordic' | 'gradient_bonfire' -export type ButtonSize = 'tiny' | 'xsmall' | 'small' | 'medium' | 'large' +export type ButtonSize = 'tiny' | 'small' | 'large' export type ButtonShape = 'round' | 'square' | 'default' export type VariantProps = { /** @@ -343,39 +343,46 @@ export const Button = React.forwardRef( if (shape === 'default') { if (size === 'large') { - baseStyles.push( - {paddingVertical: 15}, - a.px_2xl, - a.rounded_sm, - a.gap_md, - ) - } else if (size === 'medium') { - baseStyles.push( - {paddingVertical: 12}, - a.px_2xl, - a.rounded_sm, - a.gap_md, - ) + baseStyles.push({ + paddingVertical: 13, + paddingHorizontal: 20, + borderRadius: 8, + gap: 8, + }) } else if (size === 'small') { - baseStyles.push({paddingVertical: 9}, a.px_lg, a.rounded_sm, a.gap_sm) - } else if (size === 'xsmall') { - baseStyles.push({paddingVertical: 6}, a.px_sm, a.rounded_sm, a.gap_sm) + baseStyles.push({ + paddingVertical: 8, + paddingHorizontal: 12, + borderRadius: 6, + gap: 6, + }) } else if (size === 'tiny') { - baseStyles.push({paddingVertical: 4}, a.px_sm, a.rounded_xs, a.gap_xs) + baseStyles.push({ + paddingVertical: 4, + paddingHorizontal: 8, + borderRadius: 4, + gap: 4, + }) } } else if (shape === 'round' || shape === 'square') { if (size === 'large') { if (shape === 'round') { - baseStyles.push({height: 54, width: 54}) + baseStyles.push({height: 46, width: 46}) } else { - baseStyles.push({height: 50, width: 50}) + baseStyles.push({height: 44, width: 44}) } } else if (size === 'small') { - baseStyles.push({height: 34, width: 34}) - } else if (size === 'xsmall') { - baseStyles.push({height: 28, width: 28}) + if (shape === 'round') { + baseStyles.push({height: 36, width: 36}) + } else { + baseStyles.push({height: 34, width: 34}) + } } else if (size === 'tiny') { - baseStyles.push({height: 20, width: 20}) + if (shape === 'round') { + baseStyles.push({height: 22, width: 22}) + } else { + baseStyles.push({height: 21, width: 21}) + } } if (shape === 'round') { @@ -619,11 +626,11 @@ export function useSharedButtonTextStyles() { } if (size === 'large') { - baseStyles.push(a.text_md, android({paddingBottom: 1})) + baseStyles.push(a.text_md, a.leading_tight, web({paddingTop: 1})) + } else if (size === 'small') { + baseStyles.push(a.text_sm, a.leading_tight, web({paddingTop: 1})) } else if (size === 'tiny') { - baseStyles.push(a.text_xs, android({paddingBottom: 1})) - } else { - baseStyles.push(a.text_sm, android({paddingBottom: 1})) + baseStyles.push(a.text_xs, a.leading_tight) } return StyleSheet.flatten(baseStyles) @@ -643,31 +650,98 @@ export function ButtonText({children, style, ...rest}: ButtonTextProps) { export function ButtonIcon({ icon: Comp, position, - size: iconSize, + size, }: { icon: React.ComponentType position?: 'left' | 'right' size?: SVGIconProps['size'] }) { - const {size, disabled} = useButtonContext() + const {size: buttonSize, disabled} = useButtonContext() const textStyles = useSharedButtonTextStyles() + const {iconSize, iconContainerSize} = React.useMemo(() => { + /** + * Pre-set icon sizes for different button sizes + */ + const iconSizeShorthand = + size ?? + (({ + large: 'sm', + small: 'xs', + tiny: 'xs', + }[buttonSize || 'small'] || 'sm') as Exclude< + SVGIconProps['size'], + undefined + >) + + /* + * Copied here from icons/common.tsx so we can tweak if we need to, but + * also so that we can calculate transforms. + */ + const iconSize = { + xs: 12, + sm: 16, + md: 20, + lg: 24, + xl: 28, + '2xl': 32, + }[iconSizeShorthand] + + /* + * Goal here is to match rendered text size so that different size icons + * don't increase button size + */ + const iconContainerSize = { + large: 18, + small: 16, + tiny: 13, + }[buttonSize || 'small'] + + return { + iconSize, + iconContainerSize, + } + }, [buttonSize, size]) return ( - + + + ) } diff --git a/src/components/Prompt.tsx b/src/components/Prompt.tsx index 7836bbef95..8765cdee31 100644 --- a/src/components/Prompt.tsx +++ b/src/components/Prompt.tsx @@ -120,7 +120,7 @@ export function Cancel({ diff --git a/src/screens/Login/ForgotPasswordForm.tsx b/src/screens/Login/ForgotPasswordForm.tsx index 8588888b87..7acaae5101 100644 --- a/src/screens/Login/ForgotPasswordForm.tsx +++ b/src/screens/Login/ForgotPasswordForm.tsx @@ -129,7 +129,7 @@ export const ForgotPasswordForm = ({ label={_(msg`Back`)} variant="solid" color="secondary" - size="medium" + size="large" onPress={onPressBack}> Back @@ -143,7 +143,7 @@ export const ForgotPasswordForm = ({ label={_(msg`Next`)} variant="solid" color={'primary'} - size="medium" + size="large" onPress={onPressNext}> Next @@ -170,7 +170,7 @@ export const ForgotPasswordForm = ({ onPress={onEmailSent} label={_(msg`Go to next`)} accessibilityHint={_(msg`Navigates to the next screen`)} - size="medium" + size="large" variant="ghost" color="secondary"> diff --git a/src/screens/Login/LoginForm.tsx b/src/screens/Login/LoginForm.tsx index 9a01c04990..c2038b2879 100644 --- a/src/screens/Login/LoginForm.tsx +++ b/src/screens/Login/LoginForm.tsx @@ -285,7 +285,7 @@ export const LoginForm = ({ label={_(msg`Back`)} variant="solid" color="secondary" - size="medium" + size="large" onPress={onPressBack}> Back @@ -299,7 +299,7 @@ export const LoginForm = ({ accessibilityHint={_(msg`Retries login`)} variant="solid" color="secondary" - size="medium" + size="large" onPress={onPressRetryConnect}> Retry @@ -319,7 +319,7 @@ export const LoginForm = ({ accessibilityHint={_(msg`Navigates to the next screen`)} variant="solid" color="primary" - size="medium" + size="large" onPress={onPressNext}> Next diff --git a/src/screens/Login/PasswordUpdatedForm.tsx b/src/screens/Login/PasswordUpdatedForm.tsx index 5407f3f1e3..03e7d86696 100644 --- a/src/screens/Login/PasswordUpdatedForm.tsx +++ b/src/screens/Login/PasswordUpdatedForm.tsx @@ -39,7 +39,7 @@ export const PasswordUpdatedForm = ({ accessibilityHint={_(msg`Closes password update alert`)} variant="solid" color="primary" - size="medium"> + size="large"> Okay diff --git a/src/screens/Login/SetNewPasswordForm.tsx b/src/screens/Login/SetNewPasswordForm.tsx index 88f7ec5416..a6658621cc 100644 --- a/src/screens/Login/SetNewPasswordForm.tsx +++ b/src/screens/Login/SetNewPasswordForm.tsx @@ -160,7 +160,7 @@ export const SetNewPasswordForm = ({ label={_(msg`Back`)} variant="solid" color="secondary" - size="medium" + size="large" onPress={onPressBack}> Back @@ -174,7 +174,7 @@ export const SetNewPasswordForm = ({ label={_(msg`Next`)} variant="solid" color="primary" - size="medium" + size="large" onPress={onPressNext}> Next diff --git a/src/screens/Messages/Conversation/ChatDisabled.tsx b/src/screens/Messages/Conversation/ChatDisabled.tsx index 23acc41cde..c768d2504b 100644 --- a/src/screens/Messages/Conversation/ChatDisabled.tsx +++ b/src/screens/Messages/Conversation/ChatDisabled.tsx @@ -128,7 +128,7 @@ function DialogInner() { testID="backBtn" variant="solid" color="secondary" - size="medium" + size="large" onPress={onBack} label={_(msg`Back`)}> {_(msg`Back`)} @@ -137,7 +137,7 @@ function DialogInner() { testID="submitBtn" variant="solid" color="primary" - size="medium" + size="large" onPress={onSubmit} label={_(msg`Submit`)}> {_(msg`Submit`)} diff --git a/src/screens/Messages/List/index.tsx b/src/screens/Messages/List/index.tsx index e782395808..efd717f0b4 100644 --- a/src/screens/Messages/List/index.tsx +++ b/src/screens/Messages/List/index.tsx @@ -198,7 +198,7 @@ export function MessagesScreen({navigation, route}: Props) { - - - ), - )} - - */} + + + + + + + + + + + + + + + + + + - + + + + - - +