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'
12import { twMerge } from 'tailwind-merge'
23import type { VariantProps } from 'tailwind-variants'
3- import { badgeCVA , typeIcons } from '@/components/design'
4+ import { badgeCVA , typeIcons , typeTooltips } from '@/components/design'
45
56export type BadgeProps = VariantProps < typeof badgeCVA > & {
67 type : keyof typeof typeIcons
@@ -9,17 +10,36 @@ export type BadgeProps = VariantProps<typeof badgeCVA> & {
910
1011const Badge = ( { text, type } : BadgeProps ) => {
1112 const Icon = typeIcons [ type ]
13+ const [ showTooltip , setShowTooltip ] = useState ( false )
14+ const TooltipComponent = showTooltip && typeTooltips [ type ]
1215 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 ) }
1921 >
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 >
2343 )
2444}
2545
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 {
1111 TextSelect ,
1212 Trash2 ,
1313} from 'lucide-react'
14+ import type { JSX } from 'react'
1415import { 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'
1521
1622// TV configuration for stat badges
1723export const badgeCVA = tv ( {
@@ -60,3 +66,11 @@ export const typeIcons = {
6066 trashed : Trash2 ,
6167 unsent : MessageSquareDashed ,
6268} 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