From 4ee6ae929a467f103eb55035da35def47d4f5e66 Mon Sep 17 00:00:00 2001 From: Danny Delott Date: Fri, 13 Dec 2024 09:30:16 -0800 Subject: [PATCH] Unify all tooltip styling --- .../src/ui/base/components/LabelValue.tsx | 30 +++--- .../src/ui/base/components/MultiStat.tsx | 98 ------------------- .../src/ui/base/components/PrimaryStat.tsx | 18 ++-- .../src/ui/base/components/Stat.tsx | 66 ------------- .../components/Tooltip/TextWithTooltip.tsx | 24 ----- .../ui/base/components/Tooltip/Tooltip.tsx | 37 +++++++ .../src/ui/base/components/WarningButton.tsx | 24 ----- .../shorts/OpenShortForm/OpenShortForm.tsx | 12 +-- .../src/ui/markets/AssetStack.tsx | 17 ++-- .../src/ui/markets/PoolDetails.tsx | 19 ++-- .../src/ui/markets/PoolRow/PoolStat.tsx | 10 +- .../longs/OpenLongsTable/CurrentValueCell.tsx | 30 +++--- .../LpCurrentValueCell.tsx | 37 ++++--- .../CurrentShortsValueCell.tsx | 30 +++--- .../OpenShortsTable/CurrentValueCell.tsx | 26 +++-- .../OpenShortsTable/ShortRateAndSizeCell.tsx | 11 +-- .../src/ui/token/SlippageSettings.tsx | 8 +- 17 files changed, 154 insertions(+), 343 deletions(-) delete mode 100644 apps/hyperdrive-trading/src/ui/base/components/MultiStat.tsx delete mode 100644 apps/hyperdrive-trading/src/ui/base/components/Stat.tsx delete mode 100644 apps/hyperdrive-trading/src/ui/base/components/Tooltip/TextWithTooltip.tsx create mode 100644 apps/hyperdrive-trading/src/ui/base/components/Tooltip/Tooltip.tsx delete mode 100644 apps/hyperdrive-trading/src/ui/base/components/WarningButton.tsx diff --git a/apps/hyperdrive-trading/src/ui/base/components/LabelValue.tsx b/apps/hyperdrive-trading/src/ui/base/components/LabelValue.tsx index 5c9be7f94..3ea22f3bc 100644 --- a/apps/hyperdrive-trading/src/ui/base/components/LabelValue.tsx +++ b/apps/hyperdrive-trading/src/ui/base/components/LabelValue.tsx @@ -1,6 +1,7 @@ import { InformationCircleIcon } from "@heroicons/react/24/outline"; import classNames from "classnames"; import { ReactNode } from "react"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; export function LabelValue({ size = "medium", @@ -29,25 +30,20 @@ export function LabelValue({ "text-sm": size === "small", })} > -
- {label} - {tooltipContent ? ( + })} + tooltip={tooltipContent} + > + {label} - ) : null} -
+ + ) : ( +
{label}
+ )}
{value}
); diff --git a/apps/hyperdrive-trading/src/ui/base/components/MultiStat.tsx b/apps/hyperdrive-trading/src/ui/base/components/MultiStat.tsx deleted file mode 100644 index 39ce96389..000000000 --- a/apps/hyperdrive-trading/src/ui/base/components/MultiStat.tsx +++ /dev/null @@ -1,98 +0,0 @@ -import { InformationCircleIcon } from "@heroicons/react/24/outline"; -import classNames from "classnames"; -import { ReactElement } from "react"; -import { Stat, StatProps } from "src/ui/base/components/Stat"; -import { useActiveItem } from "src/ui/base/hooks/useActiveItem"; - -export interface MultiStatProps extends StatProps { - id: string; -} - -export function MultiStat({ - stats, - activeStatId, - onTabChange, -}: { - stats: MultiStatProps[]; - onTabChange: (stat: MultiStatProps) => void; - activeStatId: string; -}): ReactElement { - const { activeItem, setActiveItemId } = useActiveItem({ - items: stats, - idField: "id", - defaultActiveItemId: stats.find((stat) => activeStatId === stat.id) - ?.id as string, - }); - - return ( - - ); -} diff --git a/apps/hyperdrive-trading/src/ui/base/components/PrimaryStat.tsx b/apps/hyperdrive-trading/src/ui/base/components/PrimaryStat.tsx index 688f8af37..f1394eb5a 100644 --- a/apps/hyperdrive-trading/src/ui/base/components/PrimaryStat.tsx +++ b/apps/hyperdrive-trading/src/ui/base/components/PrimaryStat.tsx @@ -2,6 +2,7 @@ import { InformationCircleIcon } from "@heroicons/react/24/outline"; import classNames from "classnames"; import { ReactNode } from "react"; import Skeleton from "react-loading-skeleton"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; export function PrimaryStat({ label, @@ -36,20 +37,13 @@ export function PrimaryStat({

{label}

{tooltipContent && ( -
-
+ )}
diff --git a/apps/hyperdrive-trading/src/ui/base/components/Stat.tsx b/apps/hyperdrive-trading/src/ui/base/components/Stat.tsx deleted file mode 100644 index acf344aa5..000000000 --- a/apps/hyperdrive-trading/src/ui/base/components/Stat.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import { InformationCircleIcon } from "@heroicons/react/24/outline"; -import classNames from "classnames"; -import { ReactElement, ReactNode } from "react"; - -export interface StatProps { - label: ReactNode; - value: ReactNode; - description?: string; - size?: "xsmall" | "small" | "large"; - horizontal?: boolean; - tooltipPosition?: "top" | "bottom" | "left" | "right"; -} - -export function Stat({ - label, - value, - size = "large", - description, - horizontal, - tooltipPosition = "bottom", -}: StatProps): ReactElement { - return ( -
-
- {value} -
- {description ? ( -

- {label} - -

- ) : ( -
{label}
- )} -
- ); -} diff --git a/apps/hyperdrive-trading/src/ui/base/components/Tooltip/TextWithTooltip.tsx b/apps/hyperdrive-trading/src/ui/base/components/Tooltip/TextWithTooltip.tsx deleted file mode 100644 index 8e3fd1536..000000000 --- a/apps/hyperdrive-trading/src/ui/base/components/Tooltip/TextWithTooltip.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import classNames from "classnames"; -import { ReactElement, ReactNode } from "react"; - -interface CellWithTooltipProps { - label: ReactNode; - tooltip: string; -} - -export function TextWithTooltip({ - label, - tooltip, -}: CellWithTooltipProps): ReactElement { - return ( -
-

{label}

-
- ); -} diff --git a/apps/hyperdrive-trading/src/ui/base/components/Tooltip/Tooltip.tsx b/apps/hyperdrive-trading/src/ui/base/components/Tooltip/Tooltip.tsx new file mode 100644 index 000000000..814421d7f --- /dev/null +++ b/apps/hyperdrive-trading/src/ui/base/components/Tooltip/Tooltip.tsx @@ -0,0 +1,37 @@ +import classNames from "classnames"; +import { PropsWithChildren, ReactElement } from "react"; + +interface CellWithTooltipProps extends PropsWithChildren { + className?: string; + tooltip?: string; + position?: "top" | "bottom" | "left" | "right"; +} + +export function Tooltip({ + children, + className, + tooltip, + position = "top", +}: CellWithTooltipProps): ReactElement { + if (!tooltip) { + return
{children}
; + } + return ( +
+ {children} +
+ ); +} diff --git a/apps/hyperdrive-trading/src/ui/base/components/WarningButton.tsx b/apps/hyperdrive-trading/src/ui/base/components/WarningButton.tsx deleted file mode 100644 index e051df08c..000000000 --- a/apps/hyperdrive-trading/src/ui/base/components/WarningButton.tsx +++ /dev/null @@ -1,24 +0,0 @@ -export function WarningButton({ - label, - icon, - tooltip, -}: { - label: string; - icon: React.ReactNode; - tooltip?: string; -}): JSX.Element { - return ( -
- -
- ); -} diff --git a/apps/hyperdrive-trading/src/ui/hyperdrive/shorts/OpenShortForm/OpenShortForm.tsx b/apps/hyperdrive-trading/src/ui/hyperdrive/shorts/OpenShortForm/OpenShortForm.tsx index 5c68079f5..eea11a871 100644 --- a/apps/hyperdrive-trading/src/ui/hyperdrive/shorts/OpenShortForm/OpenShortForm.tsx +++ b/apps/hyperdrive-trading/src/ui/hyperdrive/shorts/OpenShortForm/OpenShortForm.tsx @@ -19,6 +19,7 @@ import { getHasEnoughAllowance } from "src/token/getHasEnoughAllowance"; import { getHasEnoughBalance } from "src/token/getHasEnoughBalance"; import { LoadingButton } from "src/ui/base/components/LoadingButton"; import { PrimaryStat } from "src/ui/base/components/PrimaryStat"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; import { formatBalance } from "src/ui/base/formatting/formatBalance"; import { formatDate } from "src/ui/base/formatting/formatDate"; import { useNumericInput } from "src/ui/base/hooks/useNumericInput"; @@ -495,15 +496,14 @@ export function OpenShortForm({ } unitClassName="mb-1 font-bold" subValue={ -
What am I paying for?{" "} -
+ } />
diff --git a/apps/hyperdrive-trading/src/ui/markets/AssetStack.tsx b/apps/hyperdrive-trading/src/ui/markets/AssetStack.tsx index 6b0efb190..0f877829f 100644 --- a/apps/hyperdrive-trading/src/ui/markets/AssetStack.tsx +++ b/apps/hyperdrive-trading/src/ui/markets/AssetStack.tsx @@ -5,6 +5,7 @@ import { getToken, } from "@delvtech/hyperdrive-appconfig"; import { ReactElement } from "react"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; import { Address } from "viem"; export function AssetStack({ @@ -37,20 +38,20 @@ export function AssetStack({ } > {hyperdrive.depositOptions.isBaseTokenDepositEnabled ? ( -
-
+ ) : null} {sharesToken && hyperdrive.depositOptions.isShareTokenDepositsEnabled ? ( -
-
+ ) : null} ); diff --git a/apps/hyperdrive-trading/src/ui/markets/PoolDetails.tsx b/apps/hyperdrive-trading/src/ui/markets/PoolDetails.tsx index a5aad0239..457573df1 100644 --- a/apps/hyperdrive-trading/src/ui/markets/PoolDetails.tsx +++ b/apps/hyperdrive-trading/src/ui/markets/PoolDetails.tsx @@ -15,6 +15,7 @@ import { ExternalLink } from "src/ui/analytics/ExternalLink"; import { AccordionSection2 } from "src/ui/base/components/AccordionSection/AccordionSection"; import CustomBanner from "src/ui/base/components/CustomBanner"; import { LabelValue } from "src/ui/base/components/LabelValue"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; import { formatAddress } from "src/ui/base/formatting/formatAddress"; import { useMarketState } from "src/ui/hyperdrive/hooks/useMarketState"; import { OpenLongForm } from "src/ui/hyperdrive/longs/OpenLongForm/OpenLongForm"; @@ -164,9 +165,10 @@ function AboutThisPool({ className="daisy-link" newTab > -
{formatAddress(baseToken.address)} -
+ } /> @@ -187,9 +189,10 @@ function AboutThisPool({ newTab className="daisy-link" > -
{formatAddress(sharesToken.address)} -
+ } /> diff --git a/apps/hyperdrive-trading/src/ui/markets/PoolRow/PoolStat.tsx b/apps/hyperdrive-trading/src/ui/markets/PoolRow/PoolStat.tsx index a235191a4..c94936524 100644 --- a/apps/hyperdrive-trading/src/ui/markets/PoolRow/PoolStat.tsx +++ b/apps/hyperdrive-trading/src/ui/markets/PoolRow/PoolStat.tsx @@ -1,6 +1,7 @@ import classNames from "classnames"; import { ReactElement, ReactNode } from "react"; import Skeleton from "react-loading-skeleton"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; export interface PoolStatProps { label: string; @@ -32,14 +33,15 @@ export function PoolStat({ return (
-

{label} -

+ +
- + ) : ( "" )}{" "} {currentValueLabel} -
{isPositiveChangeInValue ? "+" : ""} {baseAmountOut ? `${profitLoss === "-0" ? "0" : profitLoss}` : undefined} -
+
); } diff --git a/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpCurrentValueCell.tsx b/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpCurrentValueCell.tsx index bd9ffe976..2200cd6db 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpCurrentValueCell.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/lp/LpAndWithdrawalSharesTable/LpCurrentValueCell.tsx @@ -9,6 +9,7 @@ import { ReactElement } from "react"; import Skeleton from "react-loading-skeleton"; import { calculateRatio } from "src/base/calculateRatio"; import { formatRate } from "src/base/formatRate"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; import { formatBalance } from "src/ui/base/formatting/formatBalance"; import { useOpenLpPosition } from "src/ui/hyperdrive/lp/hooks/useOpenLpPosition"; import { usePreviewRemoveLiquidity } from "src/ui/hyperdrive/lp/hooks/usePreviewRemoveLiquidity"; @@ -89,25 +90,23 @@ export function LpCurrentValueCell({ <> {openLpPositionStatus === "loading" ? ( - ) : ( - baseValue && ( -
- {isPositiveChangeInValue ? "+" : "-"} - {profitLoss === null ? : profitLoss.toString()} -
- ) - )} + ) : baseValue ? ( + + {isPositiveChangeInValue ? "+" : "-"} + {profitLoss === null ? : profitLoss.toString()} + + ) : null} diff --git a/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/CurrentShortsValueCell.tsx b/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/CurrentShortsValueCell.tsx index 58965d608..aeeb4e45e 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/CurrentShortsValueCell.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/CurrentShortsValueCell.tsx @@ -8,6 +8,7 @@ import { ExclamationTriangleIcon } from "@heroicons/react/16/solid"; import classNames from "classnames"; import { ReactElement } from "react"; import Skeleton from "react-loading-skeleton"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; import { formatBalance } from "src/ui/base/formatting/formatBalance"; import { useIsTailwindSmallScreen } from "src/ui/base/mediaBreakpoints"; import { useEstimateShortMarketValue } from "src/ui/hyperdrive/shorts/hooks/useEstimateShortMarketValue"; @@ -79,32 +80,29 @@ export function CurrentShortsValueCell({
{previewCloseShortError ? ( - - + ) : ( "" )}{" "} {currentValueLabel} -
{isPositiveChangeInValue ? "+" : ""} {profitLoss} -
+
); } diff --git a/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/CurrentValueCell.tsx b/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/CurrentValueCell.tsx index 42b44f1c1..3f3f22efc 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/CurrentValueCell.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/CurrentValueCell.tsx @@ -8,6 +8,7 @@ import { ExclamationTriangleIcon } from "@heroicons/react/20/solid"; import classNames from "classnames"; import { ReactElement } from "react"; import Skeleton from "react-loading-skeleton"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; import { formatBalance } from "src/ui/base/formatting/formatBalance"; import { useIsTailwindSmallScreen } from "src/ui/base/mediaBreakpoints"; import { useEstimateShortMarketValue } from "src/ui/hyperdrive/shorts/hooks/useEstimateShortMarketValue"; @@ -80,12 +81,12 @@ export function CurrentValueCell({ TODO: Add "Current withdrawabale amount: xxx" to the tooltip once we have calcMaxCloseShort */} {previewCloseShortError ? ( - - + ) : ( "" )}{" "} @@ -94,22 +95,19 @@ export function CurrentValueCell({ {/* the current value of the user's position */} {currentValueInBase && openShort.bondAmount !== 0n ? ( -
{/* the Profit/Loss badge indicator */} {isPositiveChangeInValue ? "+" : ""} {profitLoss ? `${profitLoss === "-0" ? "" : `${profitLoss} ${baseToken.symbol}`}` : undefined} -
+ ) : ( "" )} diff --git a/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/ShortRateAndSizeCell.tsx b/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/ShortRateAndSizeCell.tsx index 80b471254..ee7dff9d8 100644 --- a/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/ShortRateAndSizeCell.tsx +++ b/apps/hyperdrive-trading/src/ui/portfolio/shorts/OpenShortsTable/ShortRateAndSizeCell.tsx @@ -7,6 +7,7 @@ import { OpenShort } from "@delvtech/hyperdrive-js"; import classNames from "classnames"; import { ReactElement } from "react"; import { formatRate } from "src/base/formatRate"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; import { formatBalance } from "src/ui/base/formatting/formatBalance"; import { useFixedRate } from "src/ui/hyperdrive/longs/hooks/useFixedRate"; import { useBlock } from "wagmi"; @@ -43,12 +44,10 @@ export function ShortRateAndSizeCell({

{`${formatRate({ rate: short.fixedRatePaid })} APR`}

-
{isPositiveChangeInValue ? "+" : ""} {formatRate({ rate: rateDifference })} -
+

{`${formatBalance({ balance: short.bondAmount, diff --git a/apps/hyperdrive-trading/src/ui/token/SlippageSettings.tsx b/apps/hyperdrive-trading/src/ui/token/SlippageSettings.tsx index a0497bc68..11ca73334 100644 --- a/apps/hyperdrive-trading/src/ui/token/SlippageSettings.tsx +++ b/apps/hyperdrive-trading/src/ui/token/SlippageSettings.tsx @@ -5,6 +5,7 @@ import { import classNames from "classnames"; import { ReactElement, useState } from "react"; import { PercentInput } from "src/ui/base/components/PercentInput"; +import { Tooltip } from "src/ui/base/components/Tooltip/Tooltip"; export const DEFAULT_SLIPPAGE_AMOUNT = "0.5"; @@ -45,12 +46,9 @@ export function SlippageSettings({

Max. Slippage -
+ -
+