Skip to content

Commit 69752fe

Browse files
committed
Add tool tips that link to issues.
1 parent 7118f7b commit 69752fe

File tree

7 files changed

+59
-10
lines changed

7 files changed

+59
-10
lines changed

src/components/Badge.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { useState } from 'react'
12
import { twMerge } from 'tailwind-merge'
23
import type { VariantProps } from 'tailwind-variants'
3-
import { badgeCVA, typeIcons } from '@/components/design'
4+
import { badgeCVA, typeIcons, typeTooltips } from '@/components/design'
45

56
export type BadgeProps = VariantProps<typeof badgeCVA> & {
67
type: keyof typeof typeIcons
@@ -9,17 +10,36 @@ export type BadgeProps = VariantProps<typeof badgeCVA> & {
910

1011
const 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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function CodePreview() {
2+
return <a href='https://github.com/diffplug/gitcasso/issues/81'>TODO #81</a>
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function ImagePreview() {
2+
return <a href='https://github.com/diffplug/gitcasso/issues/80'>TODO #80</a>
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function LinkPreview() {
2+
return <a href='https://github.com/diffplug/gitcasso/issues/79'>TODO #79</a>
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function TextPreview() {
2+
return <a href='https://github.com/diffplug/gitcasso/issues/82'>TODO #82</a>
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function TimePreview() {
2+
return <a href='https://github.com/diffplug/gitcasso/issues/83'>TODO #83</a>
3+
}

src/components/design.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import {
1111
TextSelect,
1212
Trash2,
1313
} from 'lucide-react'
14+
import type { JSX } from 'react'
1415
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'
1521

1622
// TV configuration for stat badges
1723
export 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+
}

0 commit comments

Comments
 (0)