-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathblocks-to-context.tsx
52 lines (47 loc) · 1.11 KB
/
blocks-to-context.tsx
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
"use client"
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip"
import React from "react"
const BlocksContext = React.createContext<any>(null)
export function BlocksToContext({
children,
...rest
}: {
children: React.ReactNode
rest: any
}) {
return (
<BlocksContext.Provider value={rest}>{children}</BlocksContext.Provider>
)
}
export function useBlocksContext(name: string) {
return React.useContext(BlocksContext)[name]
}
export function WithTooltip({
children,
name,
}: {
children: React.ReactNode
name: string
}) {
const block = useBlocksContext(name)
const className = block.isCode
? "p-0 [&>*]:my-0 border-none overflow-auto rounded-none"
: ""
return (
<TooltipProvider delayDuration={100}>
<Tooltip>
<TooltipTrigger asChild>
<span className="underline decoration-dotted underline-offset-4 cursor-help">
{children}
</span>
</TooltipTrigger>
<TooltipContent className={className}>{block?.children}</TooltipContent>
</Tooltip>
</TooltipProvider>
)
}