From 7cd26e9da5e297fb3fe4857bb8b97ae29859051a Mon Sep 17 00:00:00 2001 From: saml33 Date: Fri, 24 Mar 2023 23:22:29 +1100 Subject: [PATCH 1/3] add focus states and improve keyboard navigation --- components/BorrowForm.tsx | 31 +-- components/DepositForm.tsx | 31 +-- components/RepayForm.tsx | 29 +-- components/SideNav.tsx | 218 +++++++++----------- components/WithdrawForm.tsx | 31 +-- components/forms/ButtonGroup.tsx | 1 + components/forms/DateRangePicker.tsx | 4 +- components/forms/Input.tsx | 2 +- components/forms/Select.tsx | 28 ++- components/forms/Switch.tsx | 5 +- components/modals/TradeVolumeAlertModal.tsx | 2 +- components/modals/UserSetupModal.tsx | 2 +- components/settings/DisplaySettings.tsx | 8 +- components/shared/Button.tsx | 31 ++- components/shared/FavoriteMarketButton.tsx | 4 +- components/shared/IconDropMenu.tsx | 2 +- components/shared/MaxAmountButton.tsx | 2 +- components/shared/TabUnderline.tsx | 2 +- components/shared/TokenListButton.tsx | 34 +++ components/swap/SwapForm.tsx | 20 +- components/swap/SwapFormTokenList.tsx | 10 +- components/swap/SwapReviewRouteInfo.tsx | 9 + components/swap/SwapSettings.tsx | 16 +- components/swap/TokenSelect.tsx | 7 +- components/trade/AdvancedTradeForm.tsx | 60 +++--- components/trade/FavoriteMarketsBar.tsx | 25 +-- components/trade/MarketSelectDropdown.tsx | 34 +-- components/wallet/ConnectWalletButton.tsx | 56 +++-- components/wallet/ConnectedMenu.tsx | 162 +++++++-------- components/wallet/WalletSelect.tsx | 2 +- styles/globals.css | 2 +- 31 files changed, 406 insertions(+), 464 deletions(-) create mode 100644 components/shared/TokenListButton.tsx diff --git a/components/BorrowForm.tsx b/components/BorrowForm.tsx index fbd89872..c1785f0f 100644 --- a/components/BorrowForm.tsx +++ b/components/BorrowForm.tsx @@ -3,13 +3,11 @@ import { ArrowLeftIcon, ArrowUpLeftIcon, ArrowUpTrayIcon, - ChevronDownIcon, ExclamationCircleIcon, LinkIcon, } from '@heroicons/react/20/solid' import Decimal from 'decimal.js' import { useTranslation } from 'next-i18next' -import Image from 'next/legacy/image' import React, { useCallback, useMemo, useState } from 'react' import NumberFormat, { NumberFormatValues, @@ -44,6 +42,7 @@ import { floorToDecimal } from 'utils/numbers' import BankAmountWithValue from './shared/BankAmountWithValue' import useBanksWithBalances from 'hooks/useBanksWithBalances' import { isMangoError } from 'types' +import TokenListButton from './shared/TokenListButton' interface BorrowFormProps { onSuccess: () => void @@ -234,26 +233,12 @@ function BorrowForm({ onSuccess, token }: BorrowFormProps) { /> ) : null} -
- +
+
void @@ -222,26 +221,12 @@ function DepositForm({ onSuccess, token }: DepositFormProps) { value={tokenMax.maxAmount} />
-
- +
+
{ diff --git a/components/RepayForm.tsx b/components/RepayForm.tsx index 0065b06f..d9131d70 100644 --- a/components/RepayForm.tsx +++ b/components/RepayForm.tsx @@ -1,14 +1,11 @@ import { ArrowDownRightIcon, ArrowLeftIcon, - ChevronDownIcon, ExclamationCircleIcon, - QuestionMarkCircleIcon, } from '@heroicons/react/20/solid' import { useWallet } from '@solana/wallet-adapter-react' import Decimal from 'decimal.js' import { useTranslation } from 'next-i18next' -import Image from 'next/legacy/image' import React, { useCallback, useEffect, useMemo, useState } from 'react' import NumberFormat, { NumberFormatValues } from 'react-number-format' import mangoStore from '@store/mangoStore' @@ -35,6 +32,7 @@ import ConnectEmptyState from './shared/ConnectEmptyState' import BankAmountWithValue from './shared/BankAmountWithValue' import useBanksWithBalances from 'hooks/useBanksWithBalances' import { isMangoError } from 'types' +import TokenListButton from './shared/TokenListButton' interface RepayFormProps { onSuccess: () => void @@ -233,23 +231,12 @@ function RepayForm({ onSuccess, token }: RepayFormProps) { /> ) : null}
-
- +
+
{ diff --git a/components/SideNav.tsx b/components/SideNav.tsx index b22e8671..2fc13a3b 100644 --- a/components/SideNav.tsx +++ b/components/SideNav.tsx @@ -10,14 +10,13 @@ import { Cog8ToothIcon, ArrowsRightLeftIcon, ArrowTrendingUpIcon, - XMarkIcon, MagnifyingGlassIcon, BanknotesIcon, NewspaperIcon, } from '@heroicons/react/20/solid' import { useRouter } from 'next/router' import { useTranslation } from 'next-i18next' -import { Fragment, ReactNode, useState } from 'react' +import { Fragment, ReactNode } from 'react' import { Disclosure, Popover, Transition } from '@headlessui/react' import MangoAccountSummary from './account/MangoAccountSummary' import Tooltip from './shared/Tooltip' @@ -27,7 +26,6 @@ import mangoStore from '@store/mangoStore' import HealthHeart from './account/HealthHeart' import useMangoAccount from 'hooks/useMangoAccount' import { useTheme } from 'next-themes' -import { IconButton } from './shared/Button' const SideNav = ({ collapsed }: { collapsed: boolean }) => { const { t } = useTranslation(['common', 'search']) @@ -182,7 +180,6 @@ const SideNav = ({ collapsed }: { collapsed: boolean }) => { size={32} /> } - isOpen panelTitle={mangoAccount?.name ? mangoAccount.name : t('account')} title={
@@ -200,7 +197,6 @@ const SideNav = ({ collapsed }: { collapsed: boolean }) => { } alignBottom hideIconBg - showClose >
@@ -293,8 +289,6 @@ export const ExpandableMenuItem = ({ hideIconBg, icon, panelTitle, - isOpen, - showClose, title, }: { alignBottom?: boolean @@ -303,134 +297,114 @@ export const ExpandableMenuItem = ({ hideIconBg?: boolean icon: ReactNode panelTitle?: string - isOpen?: boolean - showClose?: boolean title: string | ReactNode }) => { - const [showMenu, setShowMenu] = useState(isOpen || false) const { theme } = useTheme() - const toggleMenu = () => { - setShowMenu(!showMenu) - } - return collapsed ? ( - -
+ - toggleMenu()} +
-
- {icon} + {icon} +
+ + +
+
+ {panelTitle ? ( +

{panelTitle}

+ ) : null}
- - - {showMenu ? ( - -
-
- {panelTitle ? ( -

{panelTitle}

- ) : null} - {showClose ? ( - setShowMenu(false)} - hideBg - size="small" - > - - - ) : null} -
- {children} -
-
- ) : null} -
+ {children} +
+ ) : ( -
setShowMenu(!showMenu)} - role="button" - className={`w-full px-4 py-2 ${ - alignBottom ? 'h-[64px] hover:bg-th-bkg-2' : '' - }`} - > - -
-
( + <> +
+ - {icon} -
- - {title} - +
+
+ {icon} +
+ + {title} + +
+ +
- - -
- - -
{children}
-
-
+ + +
+ {children} +
+
+
+ + )} ) } diff --git a/components/WithdrawForm.tsx b/components/WithdrawForm.tsx index 857dbb81..3ae9249f 100644 --- a/components/WithdrawForm.tsx +++ b/components/WithdrawForm.tsx @@ -2,13 +2,11 @@ import { HealthType } from '@blockworks-foundation/mango-v4' import { ArrowLeftIcon, ArrowUpTrayIcon, - ChevronDownIcon, ExclamationCircleIcon, LinkIcon, } from '@heroicons/react/20/solid' import Decimal from 'decimal.js' import { useTranslation } from 'next-i18next' -import Image from 'next/legacy/image' import { useCallback, useMemo, useState } from 'react' import NumberFormat, { NumberFormatValues } from 'react-number-format' @@ -39,6 +37,7 @@ import { floorToDecimal } from 'utils/numbers' import BankAmountWithValue from './shared/BankAmountWithValue' import useBanksWithBalances from 'hooks/useBanksWithBalances' import { isMangoError } from 'types' +import TokenListButton from './shared/TokenListButton' interface WithdrawFormProps { onSuccess: () => void @@ -211,26 +210,12 @@ function WithdrawForm({ onSuccess, token }: WithdrawFormProps) { /> ) : null}
-
- +
+
diff --git a/components/forms/ButtonGroup.tsx b/components/forms/ButtonGroup.tsx index d7b38e12..2802760e 100644 --- a/components/forms/ButtonGroup.tsx +++ b/components/forms/ButtonGroup.tsx @@ -52,6 +52,7 @@ const ButtonGroup = ({ style={{ width: `${100 / values.length}%`, }} + type="button" > {names ? (unit ? names[i] + unit : names[i]) : unit ? v + unit : v} diff --git a/components/forms/DateRangePicker.tsx b/components/forms/DateRangePicker.tsx index 0eb1b6a1..b08ae05a 100644 --- a/components/forms/DateRangePicker.tsx +++ b/components/forms/DateRangePicker.tsx @@ -34,7 +34,7 @@ const MangoDateRangePicker = ({