forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfoTip.tsx
More file actions
52 lines (44 loc) · 1.37 KB
/
Copy pathInfoTip.tsx
File metadata and controls
52 lines (44 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// src/components/ui/InfoTip.tsx
import { InfoIcon, QuestionIcon } from "@icons"
import { cva, type VariantProps } from "class-variance-authority"
import type { ReactNode } from "react"
import type { DocsEntry } from "@/lib/constants"
import { Tooltip } from "./Tooltip"
const infoTipVariants = cva(
"inline-flex items-center text-muted hover:text-secondary cursor-help transition-colors duration-150 bg-transparent border-0 p-0 outline-none focus-visible:text-secondary",
{
variants: {
size: {
sm: "[&>svg]:w-3 [&>svg]:h-3",
md: "[&>svg]:w-3.5 [&>svg]:h-3.5",
lg: "[&>svg]:w-4 [&>svg]:h-4",
},
},
defaultVariants: {
size: "md",
},
}
)
type InfoTipIcon = "info" | "question"
interface InfoTipProps extends VariantProps<typeof infoTipVariants> {
content: ReactNode
icon?: InfoTipIcon
docs?: DocsEntry
className?: string
}
const iconMap: Record<InfoTipIcon, typeof InfoIcon> = {
info: InfoIcon,
question: QuestionIcon,
}
function InfoTip({ content, docs, icon = "info", size, className }: InfoTipProps) {
const Icon = iconMap[icon]
return (
<Tooltip content={content} docs={docs}>
<button type="button" className={infoTipVariants({ size, className })} aria-label="More info">
<Icon />
</button>
</Tooltip>
)
}
export type { InfoTipIcon, InfoTipProps }
export { InfoTip, infoTipVariants }