@@ -2,31 +2,39 @@ import { type JSX, useState } from 'react'
22import { twMerge } from 'tailwind-merge'
33import type { VariantProps } from 'tailwind-variants'
44import { badgeCVA , typeColors , typeIcons } from '@/components/design'
5+ import type { CommentTableRow } from '@/entrypoints/background'
56
6- import { CodePreview } from './BadgePreviews/CodePreview'
7- import { ImagePreview } from './BadgePreviews/ImagePreview'
8- import { LinkPreview } from './BadgePreviews/LinkPreview'
9- import { TextPreview } from './BadgePreviews/TextPreview'
10- import { TimePreview } from './BadgePreviews/TimePreview'
7+ import { CodePreview } from './BadgePopups/CodePreview'
8+ import { ImagePreview } from './BadgePopups/ImagePreview'
9+ import { LinkPreview } from './BadgePopups/LinkPreview'
10+ import { OpenTabPopup } from './BadgePopups/OpenTabPopup'
11+ import { TextPreview } from './BadgePopups/TextPreview'
12+ import { TimePreview } from './BadgePopups/TimePreview'
1113
12- const typeTooltips = {
14+ const typePopups = {
1315 code : CodePreview ,
1416 image : ImagePreview ,
1517 link : LinkPreview ,
18+ open : OpenTabPopup ,
1619 text : TextPreview ,
1720 time : TimePreview ,
18- } satisfies Partial < Record < keyof typeof typeIcons , ( ) => JSX . Element > >
21+ } satisfies Partial < Record < keyof typeof typeIcons , ( props : BadgePopupProps ) => JSX . Element > >
22+
23+ export interface BadgePopupProps {
24+ row : CommentTableRow
25+ }
1926
2027export type BadgeProps = VariantProps < typeof badgeCVA > & {
2128 type : keyof typeof typeIcons
2229 text ?: number | string
30+ data ?: CommentTableRow
2331}
2432
25- const Badge = ( { text, type } : BadgeProps ) => {
33+ const Badge = ( { text, type, data } : BadgeProps ) => {
2634 const Icon = typeIcons [ type ]
2735 const [ showTooltip , setShowTooltip ] = useState ( false )
28- const TooltipComponent =
29- showTooltip && type in typeTooltips && typeTooltips [ type as keyof typeof typeTooltips ]
36+ const PopupComponent =
37+ showTooltip && type in typePopups && typePopups [ type as keyof typeof typePopups ]
3038 return (
3139 < button
3240 type = 'button'
@@ -37,22 +45,22 @@ const Badge = ({ text, type }: BadgeProps) => {
3745 < span
3846 className = { twMerge (
3947 badgeCVA ( {
40- clickable : type in typeTooltips ,
48+ clickable : type in typePopups ,
4149 type,
4250 } ) ,
4351 ) }
4452 >
4553 { type === 'blank' || < Icon className = 'h-3 w-3' /> }
4654 { text || type }
4755 </ span >
48- { TooltipComponent && (
56+ { PopupComponent && data && (
4957 < div
5058 className = { twMerge (
5159 'absolute top-full z-10 w-30 rounded border px-2 py-1 text-left text-xs shadow-lg' ,
5260 typeColors [ type ] ,
5361 ) }
5462 >
55- < TooltipComponent />
63+ < PopupComponent row = { data } />
5664 </ div >
5765 ) }
5866 </ button >
0 commit comments