MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / RenderUIButton

Function RenderUIButton

cli/src/components/tools/render-ui.tsx:54–117  ·  view source on GitHub ↗
({ widget }: { widget: RenderUIButtonWidget })

Source from the content-addressed store, hash-verified

52const CLICK_FLASH_DURATION_MS = 150
53
54const RenderUIButton = ({ widget }: { widget: RenderUIButtonWidget }) => {
55 const theme = useTheme()
56 const [isHovered, setIsHovered] = useState(false)
57 const [isClicked, setIsClicked] = useState(false)
58 const clickTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
59 const variant = widget.variant ?? 'primary'
60 const { backgroundColor, foregroundColor } = getButtonColors(
61 theme,
62 variant,
63 isHovered,
64 )
65
66 useEffect(() => {
67 return () => {
68 if (clickTimeoutRef.current) {
69 clearTimeout(clickTimeoutRef.current)
70 }
71 }
72 }, [])
73
74 const handleClick = useCallback(() => {
75 if (clickTimeoutRef.current) {
76 clearTimeout(clickTimeoutRef.current)
77 }
78 setIsClicked(true)
79 safeOpen(widget.link)
80 clickTimeoutRef.current = setTimeout(
81 () => setIsClicked(false),
82 CLICK_FLASH_DURATION_MS,
83 )
84 }, [widget.link])
85
86 const textAttributes = isClicked
87 ? TextAttributes.DIM
88 : isHovered
89 ? TextAttributes.BOLD
90 : undefined
91
92 return (
93 <box
94 style={{
95 flexDirection: 'row',
96 alignItems: 'center',
97 }}
98 >
99 <Button
100 onClick={handleClick}
101 onMouseOver={() => setIsHovered(true)}
102 onMouseOut={() => setIsHovered(false)}
103 style={{
104 backgroundColor,
105 paddingLeft: 1,
106 paddingRight: 1,
107 }}
108 >
109 <text>
110 <span fg={foregroundColor} attributes={textAttributes}>
111 {widget.text}

Callers

nothing calls this directly

Calls 4

useThemeFunction · 0.90
safeOpenFunction · 0.90
getButtonColorsFunction · 0.85
setTimeoutFunction · 0.85

Tested by

no test coverage detected