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

Function ChoiceAdBanner

cli/src/components/choice-ad-banner.tsx:65–181  ·  view source on GitHub ↗
({
  ads,
  onClick,
  onImpression,
})

Source from the content-addressed store, hash-verified

63}
64
65export const ChoiceAdBanner: React.FC<ChoiceAdBannerProps> = ({
66 ads,
67 onClick,
68 onImpression,
69}) => {
70 const theme = useTheme()
71 const { terminalWidth } = useTerminalDimensions()
72 const [hoveredIndex, setHoveredIndex] = useState<number | null>(null)
73
74 // Available width for cards (terminal minus left/right margin of 1 each)
75 const colAvail = terminalWidth - 2
76
77 // Only show as many ads as fit with a healthy minimum width; hide the rest
78 const maxVisible = Math.max(1, Math.floor(colAvail / MIN_CARD_WIDTH))
79 const visibleAds = useMemo(
80 () => (ads.length > maxVisible ? ads.slice(0, maxVisible) : ads),
81 [ads, maxVisible],
82 )
83
84 const widths = useMemo(() => columnWidths(visibleAds.length, colAvail), [visibleAds.length, colAvail])
85
86 // Fire impressions only for visible ads
87 useEffect(() => {
88 if (onImpression) {
89 for (const ad of visibleAds) {
90 onImpression(ad)
91 }
92 }
93 }, [visibleAds, onImpression])
94
95 const hoverBorderColor = theme.primary
96
97 return (
98 <box
99 style={{
100 width: '100%',
101 flexDirection: 'column',
102 }}
103 >
104 {/* Card columns */}
105 <box
106 style={{
107 marginLeft: 1,
108 marginRight: 1,
109 flexDirection: 'row',
110 }}
111 >
112 {visibleAds.map((ad, i) => {
113 const isHovered = hoveredIndex === i
114 const ctaText = ad.cta || ad.title || 'Learn more'
115 const label = getAdDisplayLabel(ad)
116 const labelMaxWidth = Math.max(0, widths[i] - ctaText.length - 5)
117 const labelText = truncateToWidth(label.text, labelMaxWidth)
118
119 return (
120 <Button
121 key={ad.impUrl}
122 onClick={() => {

Callers

nothing calls this directly

Calls 7

useThemeFunction · 0.90
useTerminalDimensionsFunction · 0.90
safeOpenFunction · 0.90
columnWidthsFunction · 0.85
getAdDisplayLabelFunction · 0.85
truncateToWidthFunction · 0.85
truncateToLinesFunction · 0.70

Tested by

no test coverage detected