File tree Expand file tree Collapse file tree 7 files changed +59
-10
lines changed Expand file tree Collapse file tree 7 files changed +59
-10
lines changed Original file line number Diff line number Diff line change
1
+ import { useState } from 'react'
1
2
import { twMerge } from 'tailwind-merge'
2
3
import type { VariantProps } from 'tailwind-variants'
3
- import { badgeCVA , typeIcons } from '@/components/design'
4
+ import { badgeCVA , typeIcons , typeTooltips } from '@/components/design'
4
5
5
6
export type BadgeProps = VariantProps < typeof badgeCVA > & {
6
7
type : keyof typeof typeIcons
@@ -9,17 +10,36 @@ export type BadgeProps = VariantProps<typeof badgeCVA> & {
9
10
10
11
const Badge = ( { text, type } : BadgeProps ) => {
11
12
const Icon = typeIcons [ type ]
13
+ const [ showTooltip , setShowTooltip ] = useState ( false )
14
+ const TooltipComponent = showTooltip && typeTooltips [ type ]
12
15
return (
13
- < span
14
- className = { twMerge (
15
- badgeCVA ( {
16
- type,
17
- } ) ,
18
- ) }
16
+ < button
17
+ type = 'button'
18
+ className = 'relative'
19
+ onMouseEnter = { ( ) => setShowTooltip ( true ) }
20
+ onMouseLeave = { ( ) => setShowTooltip ( false ) }
19
21
>
20
- { type === 'blank' || < Icon className = 'h-3 w-3' /> }
21
- { text || type }
22
- </ span >
22
+ < span
23
+ className = { twMerge (
24
+ badgeCVA ( {
25
+ clickable : ! ! typeTooltips [ type ] ,
26
+ type,
27
+ } ) ,
28
+ ) }
29
+ >
30
+ { type === 'blank' || < Icon className = 'h-3 w-3' /> }
31
+ { text || type }
32
+ </ span >
33
+ { TooltipComponent && (
34
+ < div
35
+ className = {
36
+ 'absolute top-full w-max rounded bg-gray-800 px-2 py-1 text-white text-xs shadow-lg z-10'
37
+ }
38
+ >
39
+ < TooltipComponent />
40
+ </ div >
41
+ ) }
42
+ </ button >
23
43
)
24
44
}
25
45
Original file line number Diff line number Diff line change
1
+ export function CodePreview ( ) {
2
+ return < a href = 'https://github.com/diffplug/gitcasso/issues/81' > TODO #81</ a >
3
+ }
Original file line number Diff line number Diff line change
1
+ export function ImagePreview ( ) {
2
+ return < a href = 'https://github.com/diffplug/gitcasso/issues/80' > TODO #80</ a >
3
+ }
Original file line number Diff line number Diff line change
1
+ export function LinkPreview ( ) {
2
+ return < a href = 'https://github.com/diffplug/gitcasso/issues/79' > TODO #79</ a >
3
+ }
Original file line number Diff line number Diff line change
1
+ export function TextPreview ( ) {
2
+ return < a href = 'https://github.com/diffplug/gitcasso/issues/82' > TODO #82</ a >
3
+ }
Original file line number Diff line number Diff line change
1
+ export function TimePreview ( ) {
2
+ return < a href = 'https://github.com/diffplug/gitcasso/issues/83' > TODO #83</ a >
3
+ }
Original file line number Diff line number Diff line change @@ -11,7 +11,13 @@ import {
11
11
TextSelect ,
12
12
Trash2 ,
13
13
} from 'lucide-react'
14
+ import type { JSX } from 'react'
14
15
import { tv } from 'tailwind-variants'
16
+ import { CodePreview } from './BadgePreviews/CodePreview'
17
+ import { ImagePreview } from './BadgePreviews/ImagePreview'
18
+ import { LinkPreview } from './BadgePreviews/LinkPreview'
19
+ import { TextPreview } from './BadgePreviews/TextPreview'
20
+ import { TimePreview } from './BadgePreviews/TimePreview'
15
21
16
22
// TV configuration for stat badges
17
23
export const badgeCVA = tv ( {
@@ -60,3 +66,11 @@ export const typeIcons = {
60
66
trashed : Trash2 ,
61
67
unsent : MessageSquareDashed ,
62
68
} as const
69
+
70
+ export const typeTooltips : { [ key : string ] : ( ) => JSX . Element | undefined } = {
71
+ code : CodePreview ,
72
+ image : ImagePreview ,
73
+ link : LinkPreview ,
74
+ text : TextPreview ,
75
+ time : TimePreview ,
76
+ }
You can’t perform that action at this time.
0 commit comments