Skip to content

Commit 63657a8

Browse files
Replace usage of deprecated Button component in MobileForms with new Button component (#4559)
* Update mobile forms TapField to use the new Button component * Release notes * Fix typecheck error * Cleanup * Update VRT * Dummy commit --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b3e82c5 commit 63657a8

11 files changed

+58
-55
lines changed
Loading
Loading
Loading
Loading
Loading
Loading

packages/desktop-client/src/components/mobile/MobileForms.tsx

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import React, {
66
type CSSProperties,
77
} from 'react';
88

9+
import { Button } from '@actual-app/components/button';
910
import { styles } from '@actual-app/components/styles';
1011
import { Text } from '@actual-app/components/text';
12+
import { theme } from '@actual-app/components/theme';
1113
import { Toggle } from '@actual-app/components/toggle';
12-
import { View } from '@actual-app/components/view';
1314
import { css } from '@emotion/css';
1415

15-
import { theme } from '../../style';
16-
import { Button } from '../common/Button';
1716
import { Input } from '../common/Input';
1817

1918
type FieldLabelProps = {
@@ -77,57 +76,59 @@ InputField.displayName = 'InputField';
7776

7877
type TapFieldProps = ComponentPropsWithRef<typeof Button> & {
7978
rightContent?: ReactNode;
79+
textStyle?: CSSProperties;
8080
};
8181

82+
const defaultTapFieldStyle: ComponentPropsWithoutRef<
83+
typeof Button
84+
>['style'] = ({ isDisabled, isPressed, isHovered }) => ({
85+
...valueStyle,
86+
flexDirection: 'row',
87+
alignItems: 'center',
88+
backgroundColor: theme.tableBackground,
89+
...(isDisabled && {
90+
backgroundColor: theme.formInputTextReadOnlySelection,
91+
}),
92+
...(isPressed
93+
? {
94+
opacity: 0.5,
95+
boxShadow: 'none',
96+
}
97+
: {}),
98+
...(isHovered
99+
? {
100+
boxShadow: 'none',
101+
}
102+
: {}),
103+
});
104+
82105
export const TapField = forwardRef<HTMLButtonElement, TapFieldProps>(
83-
(
84-
{
85-
value,
86-
children,
87-
disabled,
88-
rightContent,
89-
style,
90-
textStyle,
91-
onClick,
92-
...props
93-
},
94-
ref,
95-
) => {
106+
({ value, children, rightContent, style, textStyle, ...props }, ref) => {
96107
return (
97108
<Button
98-
// @ts-expect-error fix this later
99-
as={View}
100109
ref={ref}
101-
onClick={!disabled ? onClick : undefined}
102-
style={{
103-
flexDirection: 'row',
104-
alignItems: 'center',
105-
...style,
106-
...valueStyle,
107-
backgroundColor: theme.tableBackground,
108-
...(disabled && {
109-
backgroundColor: theme.formInputTextReadOnlySelection,
110-
}),
111-
}}
112110
bounce={false}
113-
activeStyle={{
114-
opacity: 0.5,
115-
boxShadow: 'none',
116-
}}
117-
hoveredStyle={{
118-
boxShadow: 'none',
119-
}}
120-
// activeOpacity={0.05}
111+
style={renderProps => ({
112+
...defaultTapFieldStyle(renderProps),
113+
...(typeof style === 'function' ? style(renderProps) : style),
114+
})}
121115
{...props}
122116
>
123117
{children ? (
124118
children
125119
) : (
126-
<Text style={{ flex: 1, userSelect: 'none', ...textStyle }}>
120+
<Text
121+
style={{
122+
flex: 1,
123+
userSelect: 'none',
124+
textAlign: 'left',
125+
...textStyle,
126+
}}
127+
>
127128
{value}
128129
</Text>
129130
)}
130-
{!disabled && rightContent}
131+
{!props.isDisabled && rightContent}
131132
</Button>
132133
);
133134
},

packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,12 @@ const ChildTransactionEdit = forwardRef(
320320
<View style={{ flexBasis: '75%' }}>
321321
<FieldLabel title={t('Payee')} />
322322
<TapField
323-
disabled={
323+
isDisabled={
324324
editingField &&
325325
editingField !== getFieldName(transaction.id, 'payee')
326326
}
327327
value={prettyPayee}
328-
onClick={() => onEditField(transaction.id, 'payee')}
328+
onPress={() => onEditField(transaction.id, 'payee')}
329329
data-testid={`payee-field-${transaction.id}`}
330330
/>
331331
</View>
@@ -376,13 +376,13 @@ const ChildTransactionEdit = forwardRef(
376376
}),
377377
}}
378378
value={getCategory(transaction, isOffBudget)}
379-
disabled={
379+
isDisabled={
380380
(editingField &&
381381
editingField !== getFieldName(transaction.id, 'category')) ||
382382
isOffBudget ||
383383
isBudgetTransfer(transaction)
384384
}
385-
onClick={() => onEditField(transaction.id, 'category')}
385+
onPress={() => onEditField(transaction.id, 'category')}
386386
data-testid={`category-field-${transaction.id}`}
387387
/>
388388
</View>
@@ -848,11 +848,11 @@ const TransactionEditInner = memo(function TransactionEditInner({
848848
}),
849849
}}
850850
value={title}
851-
disabled={
851+
isDisabled={
852852
editingField &&
853853
editingField !== getFieldName(transaction.id, 'payee')
854854
}
855-
onClick={() => onEditFieldInner(transaction.id, 'payee')}
855+
onPress={() => onEditFieldInner(transaction.id, 'payee')}
856856
data-testid="payee-field"
857857
/>
858858
</View>
@@ -869,13 +869,13 @@ const TransactionEditInner = memo(function TransactionEditInner({
869869
}),
870870
}}
871871
value={getCategory(transaction, isOffBudget)}
872-
disabled={
872+
isDisabled={
873873
(editingField &&
874874
editingField !== getFieldName(transaction.id, 'category')) ||
875875
isOffBudget ||
876876
isBudgetTransfer(transaction)
877877
}
878-
onClick={() => onEditFieldInner(transaction.id, 'category')}
878+
onPress={() => onEditFieldInner(transaction.id, 'category')}
879879
data-testid="category-field"
880880
/>
881881
</View>
@@ -940,12 +940,12 @@ const TransactionEditInner = memo(function TransactionEditInner({
940940
<View>
941941
<FieldLabel title={t('Account')} />
942942
<TapField
943-
disabled={
943+
isDisabled={
944944
editingField &&
945945
editingField !== getFieldName(transaction.id, 'account')
946946
}
947947
value={account?.name}
948-
onClick={() => onEditFieldInner(transaction.id, 'account')}
948+
onPress={() => onEditFieldInner(transaction.id, 'account')}
949949
data-testid="account-field"
950950
/>
951951
</View>

packages/desktop-client/src/components/modals/CoverModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function CoverModal({
8383
/>
8484
<View>
8585
<FieldLabel title={t('Cover from a category:')} />
86-
<TapField value={fromCategory?.name} onClick={onCategoryClick} />
86+
<TapField value={fromCategory?.name} onPress={onCategoryClick} />
8787
</View>
8888

8989
<View

packages/desktop-client/src/components/modals/TransferModal.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,7 @@ export function TransferModal({
112112
</View>
113113

114114
<FieldLabel title="To:" />
115-
<TapField
116-
tabIndex={0}
117-
value={toCategory?.name}
118-
onClick={openCategoryModal}
119-
/>
115+
<TapField value={toCategory?.name} onPress={openCategoryModal} />
120116

121117
<View
122118
style={{

0 commit comments

Comments
 (0)