Skip to content

Commit

Permalink
chore: transaction tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDinh committed Mar 21, 2024
1 parent 4991b6e commit ccacdcf
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 15 deletions.
35 changes: 35 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.7",
"@tauri-apps/api": "^1.5.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
Expand Down
9 changes: 6 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import { routes } from './App.routes'
import { RouterProvider, createBrowserRouter } from 'react-router-dom'
import { ThemeProvider } from './features/theme/context/theme-provider'
import { LayoutProvider } from './features/layout/context/layout-provider'
import { TooltipProvider } from './features/common/components/tooltip'

const router = createBrowserRouter(routes)

function App() {
return (
<ThemeProvider defaultTheme="system" storageKey="vite-ui-theme">
<LayoutProvider>
<RouterProvider router={router} />
</LayoutProvider>
<TooltipProvider>
<LayoutProvider>
<RouterProvider router={router} />
</LayoutProvider>
</TooltipProvider>
</ThemeProvider>
)
}
Expand Down
28 changes: 28 additions & 0 deletions src/features/common/components/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react'
import * as TooltipPrimitive from '@radix-ui/react-tooltip'

import { cn } from '@/features/common/utils'

const TooltipProvider = TooltipPrimitive.Provider

const Tooltip = TooltipPrimitive.Root

const TooltipTrigger = TooltipPrimitive.Trigger

const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
'z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
className
)}
{...props}
/>
))
TooltipContent.displayName = TooltipPrimitive.Content.displayName

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
48 changes: 36 additions & 12 deletions src/features/transactions/pages/group-page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import SvgCircle from '@/features/common/components/svg/circle'
import SvgPointerLeft from '@/features/common/components/svg/pointer-left'
import SvgPointerRight from '@/features/common/components/svg/pointer-right'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/features/common/components/tooltip'
import { cn } from '@/features/common/utils'
import { fixedForwardRef } from '@/utils/fixed-forward-ref'
import { isDefined } from '@/utils/is-defined'
import { useMemo } from 'react'

Expand Down Expand Up @@ -82,40 +84,42 @@ function ConnectionToChildren({ indentLevel }: { indentLevel: number | undefined
)
}

function DisplayArrow({ arrow: transactionArrow }: { arrow: Arrow }) {
const DisplayArrow = fixedForwardRef(({ arrow, ...rest }: { arrow: Arrow }, ref?: React.LegacyRef<HTMLDivElement>) => {
return (
<div
className={cn('flex items-center justify-center')}
style={{
// 2 and 3 are the number to offset the name column
gridColumnStart: transactionArrow.from + 2,
gridColumnEnd: transactionArrow.to + 3,
gridColumnStart: arrow.from + 2,
gridColumnEnd: arrow.to + 3,
}}
ref={ref}
{...rest}
>
<SvgCircle width={graphConfig.circleDimension} height={graphConfig.circleDimension}></SvgCircle>
<div
style={{
width: `calc(${(100 - 100 / (transactionArrow.to - transactionArrow.from + 1)).toFixed(2)}% - ${graphConfig.circleDimension}px)`,
width: `calc(${(100 - 100 / (arrow.to - arrow.from + 1)).toFixed(2)}% - ${graphConfig.circleDimension}px)`,
height: `${graphConfig.circleDimension}px`,
}}
className="relative text-primary"
>
{transactionArrow.direction === 'rightToLeft' && <SvgPointerLeft className={cn('absolute top-0 left-0')} />}
{arrow.direction === 'rightToLeft' && <SvgPointerLeft className={cn('absolute top-0 left-0')} />}
<div className={cn('border-primary h-1/2')} style={{ borderBottomWidth: graphConfig.lineWidth }}></div>
{transactionArrow.direction === 'leftToRight' && <SvgPointerRight className={cn('absolute top-0 right-0')} />}
{arrow.direction === 'leftToRight' && <SvgPointerRight className={cn('absolute top-0 right-0')} />}
</div>
<SvgCircle width={graphConfig.circleDimension} height={graphConfig.circleDimension}></SvgCircle>
</div>
)
}
})

function DisplaySelfTransaction() {
const DisplaySelfTransaction = fixedForwardRef((props: object, ref?: React.LegacyRef<HTMLDivElement>) => {
return (
<div className={cn('flex items-center justify-center')}>
<div ref={ref} className={cn('flex items-center justify-center')} {...props}>
<SvgCircle width={graphConfig.circleDimension} height={graphConfig.circleDimension}></SvgCircle>
</div>
)
}
})

type TransactionRowProps = {
transaction: Transaction
Expand Down Expand Up @@ -153,8 +157,28 @@ function TransactionRow({
</div>
{accounts.map((_, index) => {
if (index < arrow.from || index > arrow.to) return <div key={index}></div>
if (index === arrow.from && index === arrow.to) return <DisplaySelfTransaction key={index} />
if (index === arrow.from) return <DisplayArrow key={index} arrow={arrow} />
if (index === arrow.from && index === arrow.to)
return (
<Tooltip key={index}>
<TooltipTrigger asChild>
<DisplaySelfTransaction />
</TooltipTrigger>
<TooltipContent>
<div className={cn('p-4')}>Transaction: {transaction.name}</div>
</TooltipContent>
</Tooltip>
)
if (index === arrow.from)
return (
<Tooltip key={index}>
<TooltipTrigger asChild>
<DisplayArrow key={index} arrow={arrow} />
</TooltipTrigger>
<TooltipContent>
<div className={cn('p-4')}>Transaction: {transaction.name}</div>
</TooltipContent>
</Tooltip>
)
else return null
})}

Expand Down

0 comments on commit ccacdcf

Please sign in to comment.