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

Fix mobile page header buttons #3491

Merged
merged 9 commits into from
Sep 24, 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions packages/desktop-client/src/components/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ export function MobilePageHeader({
<View
style={{
alignItems: 'center',
backgroundColor: theme.mobileHeaderBackground,
color: theme.mobileHeaderText,
flexDirection: 'row',
flexShrink: 0,
height: HEADER_HEIGHT,
backgroundColor: theme.mobileHeaderBackground,
'& *': {
color: theme.mobileHeaderText,
},
'& button[data-pressed]': {
backgroundColor: theme.mobileHeaderTextHover,
},
...style,
}}
>
Expand Down
101 changes: 39 additions & 62 deletions packages/desktop-client/src/components/common/Button2.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, {
forwardRef,
useMemo,
type ComponentPropsWithoutRef,
type ComponentType,
type ReactNode,
type SVGProps,
} from 'react';
import {
type ButtonRenderProps as ReactAriaButtonRenderProps,
Expand Down Expand Up @@ -104,6 +103,13 @@ const _getPadding = (variant: ButtonVariant): string => {
}
};

const _getHoveredStyles = (variant: ButtonVariant): CSSProperties => ({
...(variant !== 'bare' && styles.shadow),
backgroundColor: backgroundColorHover[variant],
color: textColorHover[variant],
cursor: 'pointer',
});

const _getActiveStyles = (
variant: ButtonVariant,
bounce: boolean,
Expand All @@ -127,78 +133,56 @@ const _getActiveStyles = (
type ButtonProps = ComponentPropsWithoutRef<typeof ReactAriaButton> & {
variant?: ButtonVariant;
bounce?: boolean;
Icon?: ComponentType<SVGProps<SVGSVGElement>>;
children?: ReactNode;
};

type ButtonVariant = 'normal' | 'primary' | 'bare' | 'menu' | 'menuSelected';

export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
(props, ref) => {
const {
children,
variant = 'normal',
bounce = true,
Icon,
...restProps
} = props;
const { children, variant = 'normal', bounce = true, ...restProps } = props;

const variantWithDisabled: ButtonVariant | `${ButtonVariant}Disabled` =
props.isDisabled ? `${variant}Disabled` : variant;

const hoveredStyle = {
...(variant !== 'bare' && styles.shadow),
backgroundColor: backgroundColorHover[variant],
color: textColorHover[variant],
cursor: 'pointer',
};
const activeStyle = {
..._getActiveStyles(variant, bounce),
};

const defaultButtonClassName: ReactAriaButtonClassNameFn = renderProps =>
String(
css({
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
padding: _getPadding(variant),
margin: 0,
overflow: 'hidden',
display: 'flex',
borderRadius: 4,
backgroundColor: backgroundColor[variantWithDisabled],
border: _getBorder(variant, variantWithDisabled),
color: textColor[variantWithDisabled],
transition: 'box-shadow .25s',
WebkitAppRegion: 'no-drag',
...styles.smallText,
...(renderProps.isDisabled
? {}
: {
'&[data-hovered]': hoveredStyle,
'&[data-pressed]': activeStyle,
}),
...(Icon ? { paddingLeft: 0 } : {}),
}),
);
const defaultButtonClassName: string = useMemo(
() =>
String(
css({
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
padding: _getPadding(variant),
margin: 0,
overflow: 'hidden',
display: 'flex',
borderRadius: 4,
backgroundColor: backgroundColor[variantWithDisabled],
border: _getBorder(variant, variantWithDisabled),
color: textColor[variantWithDisabled],
transition: 'box-shadow .25s',
WebkitAppRegion: 'no-drag',
...styles.smallText,
'&[data-hovered]': _getHoveredStyles(variant),
'&[data-pressed]': _getActiveStyles(variant, bounce),
}),
),
[bounce, variant, variantWithDisabled],
);

const buttonClassName: ReactAriaButtonClassNameFn = renderProps =>
typeof props.className === 'function'
? props.className(renderProps)
: props.className || '';
const className = restProps.className;

return (
<ReactAriaButton
ref={ref}
{...restProps}
className={renderProps =>
`${renderProps.defaultClassName} ${defaultButtonClassName(renderProps)} ${buttonClassName(renderProps)}`
className={
typeof className === 'function'
? renderProps =>
`${defaultButtonClassName} ${className(renderProps)}`
: `${defaultButtonClassName} ${className || ''}`
}
>
{Icon && (
<Icon style={{ height: 15, paddingLeft: 5, paddingRight: 3 }} />
)}
Comment on lines -199 to -201
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ question: ‏intentionally removing this? If so: might as well remove the Icon prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just remove this Icon since we can just pass the Icon as part of the children prop:

<Button>
   <Icon />
    ....
</Button>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can definitely remove it now since it's not used.

The main reason for adding it as a prop instead of passing in children was the visual appearance. The icon didn't really look nice because of the large left margin the button automatically applies.

{children}
</ReactAriaButton>
);
Expand Down Expand Up @@ -254,10 +238,3 @@ export const ButtonWithLoading = forwardRef<
});

ButtonWithLoading.displayName = 'ButtonWithLoading';

type ReactAriaButtonClassNameFn = Extract<
ComponentPropsWithoutRef<typeof ReactAriaButton>['className'],
(
renderProps: ReactAriaButtonRenderProps & { defaultClassName: string },
) => string
>;
22 changes: 5 additions & 17 deletions packages/desktop-client/src/components/mobile/MobileBackButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React, { type ComponentPropsWithoutRef } from 'react';

import { css } from 'glamor';

import { useNavigate } from '../../hooks/useNavigate';
import { SvgCheveronLeft } from '../../icons/v1';
import { styles, theme } from '../../style';
import { styles } from '../../style';
import { Button } from '../common/Button2';
import { Text } from '../common/Text';

Expand All @@ -19,20 +17,10 @@ export function MobileBackButton({
return (
<Button
variant="bare"
className={String(
css({
color: theme.mobileHeaderText,
justifyContent: 'center',
margin: 10,
paddingLeft: 5,
paddingRight: 3,
'&[data-hovered]': {
color: theme.mobileHeaderText,
background: theme.mobileHeaderTextHover,
},
...style,
}),
)}
style={{
margin: 10,
...style,
}}
onPress={onPress || (() => navigate(-1))}
{...props}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export function MobileNavTabs() {
<View>
<div
style={{
background: theme.pillBorder,
backgroundColor: theme.pillBorder,
borderRadius: 10,
width: 30,
marginTop: 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { useDateFormat } from '../../../hooks/useDateFormat';
import { useNavigate } from '../../../hooks/useNavigate';
import { usePreviewTransactions } from '../../../hooks/usePreviewTransactions';
import { styles, theme } from '../../../style';
import { Button } from '../../common/Button2';
import { Text } from '../../common/Text';
import { View } from '../../common/View';
import { MobilePageHeader, Page } from '../../Page';
Expand Down Expand Up @@ -125,16 +126,18 @@ function AccountName({ account, pending, failed }) {
}}
/>
)}
<Text
style={{
userSelect: 'none',
...styles.underlinedText,
...styles.lineClamp(2),
}}
onClick={onClick}
>
{`${account.closed ? 'Closed: ' : ''}${account.name}`}
</Text>
<Button variant="bare" onPress={onClick}>
<Text
style={{
fontSize: 17,
fontWeight: 500,
...styles.underlinedText,
...styles.lineClamp(2),
}}
>
{`${account.closed ? 'Closed: ' : ''}${account.name}`}
</Text>
</Button>
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';

import { css } from 'glamor';

import { replaceModal, syncAndDownload } from 'loot-core/src/client/actions';
import * as queries from 'loot-core/src/client/queries';

Expand Down Expand Up @@ -172,17 +170,7 @@ function AccountList({
<Button
variant="bare"
aria-label="Add account"
className={String(
css({
justifyContent: 'center',
color: theme.mobileHeaderText,
margin: 10,
':hover': {
color: theme.mobileHeaderText,
background: theme.mobileHeaderTextHover,
},
}),
)}
style={{ margin: 10 }}
onPress={onAddAccount}
>
<SvgAdd width={20} height={20} />
Expand Down
Loading
Loading