Skip to content

A local-first personal finance app

React Aria Button on Accounts and Payees page (#2914)

Joel Jeremy Marquez76cdad4fe628
diff --git a/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-1-chromium-linux.png b/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-1-chromium-linux.png
index f677aafa81..07d834a864 100644
Binary files a/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-1-chromium-linux.png and b/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-2-chromium-linux.png b/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-2-chromium-linux.png
index c3620db1d2..6d301b5e47 100644
Binary files a/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-2-chromium-linux.png and b/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-2-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/accounts/Account.jsx b/packages/desktop-client/src/components/accounts/Account.jsx
index 5ae43fe427..ef660cbefc 100644
--- a/packages/desktop-client/src/components/accounts/Account.jsx
+++ b/packages/desktop-client/src/components/accounts/Account.jsx
@@ -40,7 +40,7 @@ import {
useSplitsExpanded,
} from '../../hooks/useSplitsExpanded';
import { styles, theme } from '../../style';
-import { Button } from '../common/Button';
+import { Button } from '../common/Button2';
import { Text } from '../common/Text';
import { View } from '../common/View';
import { TransactionList } from '../transactions/TransactionList';
@@ -73,7 +73,7 @@ function EmptyMessage({ onAdd }) {
manage it locally yourself.
</Text>
- <Button type="primary" style={{ marginTop: 20 }} onClick={onAdd}>
+ <Button variant="primary" style={{ marginTop: 20 }} onPress={onAdd}>
Add account
</Button>
diff --git a/packages/desktop-client/src/components/accounts/AccountSyncCheck.jsx b/packages/desktop-client/src/components/accounts/AccountSyncCheck.jsx
index 989e585c76..9894ae6eaa 100644
--- a/packages/desktop-client/src/components/accounts/AccountSyncCheck.jsx
+++ b/packages/desktop-client/src/components/accounts/AccountSyncCheck.jsx
@@ -7,7 +7,7 @@ import { useAccounts } from '../../hooks/useAccounts';
import { useActions } from '../../hooks/useActions';
import { SvgExclamationOutline } from '../../icons/v1';
import { theme } from '../../style';
-import { Button } from '../common/Button';
+import { Button } from '../common/Button2';
import { Link } from '../common/Link';
import { Popover } from '../common/Popover';
import { View } from '../common/View';
@@ -94,7 +94,7 @@ export function AccountSyncCheck() {
<View>
<Button
ref={triggerRef}
- type="bare"
+ variant="bare"
style={{
flexDirection: 'row',
alignItems: 'center',
@@ -103,7 +103,7 @@ export function AccountSyncCheck() {
padding: '4px 8px',
borderRadius: 4,
}}
- onClick={() => setOpen(true)}
+ onPress={() => setOpen(true)}
>
<SvgExclamationOutline
style={{ width: 14, height: 14, marginRight: 5 }}
@@ -129,13 +129,17 @@ export function AccountSyncCheck() {
<View style={{ justifyContent: 'flex-end', flexDirection: 'row' }}>
{showAuth ? (
<>
- <Button onClick={unlink}>Unlink</Button>
- <Button type="primary" onClick={reauth} style={{ marginLeft: 5 }}>
+ <Button onPress={unlink}>Unlink</Button>
+ <Button
+ variant="primary"
+ onPress={reauth}
+ style={{ marginLeft: 5 }}
+ >
Reauthorize
</Button>
</>
) : (
- <Button onClick={unlink}>Unlink account</Button>
+ <Button onPress={unlink}>Unlink account</Button>
)}
</View>
</Popover>
diff --git a/packages/desktop-client/src/components/accounts/Balance.jsx b/packages/desktop-client/src/components/accounts/Balance.jsx
index f2db1f2e63..91a5008662 100644
--- a/packages/desktop-client/src/components/accounts/Balance.jsx
+++ b/packages/desktop-client/src/components/accounts/Balance.jsx
@@ -1,4 +1,6 @@
-import React from 'react';
+import React, { useRef } from 'react';
+
+import { useHover } from 'usehooks-ts';
import { isPreviewId } from 'loot-core/shared/transactions';
import { useCachedSchedules } from 'loot-core/src/client/data-hooks/schedules';
@@ -8,7 +10,7 @@ import { getScheduledAmount } from 'loot-core/src/shared/schedules';
import { useSelectedItems } from '../../hooks/useSelected';
import { SvgArrowButtonRight1 } from '../../icons/v2';
import { theme } from '../../style';
-import { Button } from '../common/Button';
+import { Button } from '../common/Button2';
import { Text } from '../common/Text';
import { View } from '../common/View';
import { PrivacyFilter } from '../PrivacyFilter';
@@ -141,6 +143,8 @@ export function Balances({
filteredAmount,
}) {
const selectedItems = useSelectedItems();
+ const buttonRef = useRef(null);
+ const isButtonHovered = useHover(buttonRef);
return (
<View
@@ -152,14 +156,11 @@ export function Balances({
}}
>
<Button
+ ref={buttonRef}
data-testid="account-balance"
- type="bare"
- onClick={onToggleExtraBalances}
+ variant="bare"
+ onPress={onToggleExtraBalances}
style={{
- '& svg': {
- opacity: selectedItems.size > 0 || showExtraBalances ? 1 : 0,
- },
- '&:hover svg': { opacity: 1 },
paddingTop: 1,
paddingBottom: 1,
}}
@@ -188,6 +189,10 @@ export function Balances({
marginLeft: 10,
color: theme.pillText,
transform: showExtraBalances ? 'rotateZ(180deg)' : 'rotateZ(0)',
+ opacity:
+ isButtonHovered || selectedItems.size > 0 || showExtraBalances
+ ? 1
+ : 0,
}}
/>
</Button>
diff --git a/packages/desktop-client/src/components/accounts/Header.jsx b/packages/desktop-client/src/components/accounts/Header.jsx
index 4506034fcd..00e247473d 100644
--- a/packages/desktop-client/src/components/accounts/Header.jsx
+++ b/packages/desktop-client/src/components/accounts/Header.jsx
@@ -14,7 +14,7 @@ import {
} from '../../icons/v2';
import { theme, styles } from '../../style';
import { AnimatedRefresh } from '../AnimatedRefresh';
-import { Button } from '../common/Button';
+import { Button } from '../common/Button2';
import { InitialFocus } from '../common/InitialFocus';
import { Input } from '../common/Input';
import { Menu } from '../common/Menu';
@@ -214,10 +214,10 @@ export function AccountHeader({
/>
)}
<Button
- type="bare"
+ variant="bare"
aria-label="Edit account name"
className="hover-visible"
- onClick={() => onExposeName(true)}
+ onPress={() => onExposeName(true)}
>
<SvgPencil1
style={{
@@ -258,9 +258,9 @@ export function AccountHeader({
>
{((account && !account.closed) || canSync) && (
<Button
- type="bare"
- onClick={canSync ? onSync : onImport}
- disabled={canSync && isServerOffline}
+ variant="bare"
+ onPress={canSync ? onSync : onImport}
+ isDisabled={canSync && isServerOffline}
>
{canSync ? (
<>
@@ -289,7 +289,7 @@ export function AccountHeader({
</Button>
)}
{!showEmptyMessage && (
- <Button type="bare" onClick={onAddTransaction}>
+ <Button variant="bare" onPress={onAddTransaction}>
<SvgAdd width={10} height={10} style={{ marginRight: 3 }} /> Add
New
</Button>
@@ -326,21 +326,29 @@ export function AccountHeader({
/>
)}
<Button
- type="bare"
- disabled={search !== '' || filterConditions.length > 0}
- style={{ padding: 6, marginLeft: 10 }}
- onClick={onToggleSplits}
- title={
+ variant="bare"
+ aria-label={
splitsExpanded.state.mode === 'collapse'
? 'Collapse split transactions'
: 'Expand split transactions'
}
+ isDisabled={search !== '' || filterConditions.length > 0}
+ style={{ padding: 6, marginLeft: 10 }}
+ onPress={onToggleSplits}
>
- {splitsExpanded.state.mode === 'collapse' ? (
- <SvgArrowsShrink3 style={{ width: 14, height: 14 }} />
- ) : (
- <SvgArrowsExpand3 style={{ width: 14, height: 14 }} />
- )}
+ <View
+ title={
+ splitsExpanded.state.mode === 'collapse'
+ ? 'Collapse split transactions'
+ : 'Expand split transactions'
+ }
+ >
+ {splitsExpanded.state.mode === 'collapse' ? (
+ <SvgArrowsShrink3 style={{ width: 14, height: 14 }} />
+ ) : (
+ <SvgArrowsExpand3 style={{ width: 14, height: 14 }} />
+ )}
+ </View>
</Button>
{account ? (
<View>
diff --git a/packages/desktop-client/src/components/accounts/Reconcile.jsx b/packages/desktop-client/src/components/accounts/Reconcile.jsx
index d80668b8e1..ab7127858e 100644
--- a/packages/desktop-client/src/components/accounts/Reconcile.jsx
+++ b/packages/desktop-client/src/components/accounts/Reconcile.jsx
@@ -1,11 +1,11 @@
-import React from 'react';
+import React, { useState } from 'react';
import * as queries from 'loot-core/src/client/queries';
import { currencyToInteger } from 'loot-core/src/shared/util';
import { SvgCheckCircle1 } from '../../icons/v2';
import { styles, theme } from '../../style';
-import { Button } from '../common/Button';
+import { Button } from '../common/Button2';
import { InitialFocus } from '../common/InitialFocus';
import { Input } from '../common/Input';
import { Text } from '../common/Text';
@@ -78,13 +78,13 @@ export function ReconcilingMessage({
</View>
)}
<View style={{ marginLeft: 15 }}>
- <Button type="primary" onClick={onDone}>
+ <Button variant="primary" onPress={onDone}>
Done Reconciling
</Button>
</View>
{targetDiff !== 0 && (
<View style={{ marginLeft: 15 }}>
- <Button onClick={() => onCreateTransaction(targetDiff)}>
+ <Button onPress={() => onCreateTransaction(targetDiff)}>
Create Reconciliation Transaction
</Button>
</View>
@@ -102,17 +102,20 @@ export function ReconcileMenu({ account, onReconcile, onClose }) {
query: balanceQuery.query.filter({ cleared: true }),
});
const format = useFormat();
+ const [inputValue, setInputValue] = useState(null);
+ const [inputFocused, setInputFocused] = useState(false);
- function onSubmit(e) {
- e.preventDefault();
- const input = e.target.elements[0];
- const amount = currencyToInteger(input.value);
- if (amount != null) {
- onReconcile(amount == null ? clearedBalance : amount);
- onClose();
- } else {
- input.select();
+ function onSubmit() {
+ if (inputValue === '') {
+ setInputFocused(true);
+ return;
}
+
+ const amount =
+ inputValue != null ? currencyToInteger(inputValue) : clearedBalance;
+
+ onReconcile(amount);
+ onClose();
}
return (
@@ -121,17 +124,20 @@ export function ReconcileMenu({ account, onReconcile, onClose }) {
Enter the current balance of your bank account that you want to
reconcile with:
</Text>
- <form onSubmit={onSubmit}>
- {clearedBalance != null && (
- <InitialFocus>
- <Input
- defaultValue={format(clearedBalance, 'financial')}
- style={{ margin: '7px 0' }}
- />
- </InitialFocus>
- )}
- <Button type="primary">Reconcile</Button>
- </form>
+ {clearedBalance != null && (
+ <InitialFocus>
+ <Input
+ defaultValue={format(clearedBalance, 'financial')}
+ onChangeValue={setInputValue}
+ style={{ margin: '7px 0' }}
+ focused={inputFocused}
+ onEnter={onSubmit}
+ />
+ </InitialFocus>
+ )}
+ <Button variant="primary" onPress={onSubmit}>
+ Reconcile
+ </Button>
</View>
);
}
diff --git a/packages/desktop-client/src/components/payees/ManagePayees.jsx b/packages/desktop-client/src/components/payees/ManagePayees.jsx
index 79449a6cb7..83f5bada3e 100644
--- a/packages/desktop-client/src/components/payees/ManagePayees.jsx
+++ b/packages/desktop-client/src/components/payees/ManagePayees.jsx
@@ -22,7 +22,7 @@ import {
import { useStableCallback } from '../../hooks/useStableCallback';
import { SvgExpandArrow } from '../../icons/v0';
import { theme } from '../../style';
-import { Button } from '../common/Button';
+import { Button } from '../common/Button2';
import { Popover } from '../common/Popover';
import { Search } from '../common/Search';
import { View } from '../common/View';
@@ -236,10 +236,10 @@ export const ManagePayees = forwardRef(
<View style={{ flexShrink: 0 }}>
<Button
ref={triggerRef}
- type="bare"
+ variant="bare"
style={{ marginRight: 10 }}
- disabled={buttonsDisabled}
- onClick={() => setMenuOpen(true)}
+ isDisabled={buttonsDisabled}
+ onPress={() => setMenuOpen(true)}
>
{buttonsDisabled
? 'No payees selected'
@@ -273,9 +273,9 @@ export const ManagePayees = forwardRef(
{(orphanedOnly ||
(orphanedPayees && orphanedPayees.length > 0)) && (
<Button
- type="bare"
+ variant="bare"
style={{ marginRight: 10 }}
- onClick={() => {
+ onPress={() => {
setOrphanedOnly(!orphanedOnly);
applyFilter(filter);
tableNavigator.onEdit(null);
diff --git a/upcoming-release-notes/2914.md b/upcoming-release-notes/2914.md
new file mode 100644
index 0000000000..c149dc11d1
--- /dev/null
+++ b/upcoming-release-notes/2914.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [joel-jeremy]
+---
+
+Use new react-aria-components based Button on accounts and payees page.