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

Function CopyButton

cli/src/components/copy-button.tsx:127–178  ·  view source on GitHub ↗
({
  textToCopy,
  children,
  leadingSpace = true,
  style,
})

Source from the content-addressed store, hash-verified

125 * ```
126 */
127export const CopyButton: React.FC<CopyButtonProps> = ({
128 textToCopy,
129 children,
130 leadingSpace = true,
131 style,
132}) => {
133 const [isCopied, setIsCopied] = useState(false)
134 const [isHovered, setIsHovered] = useState(false)
135 const { setTimeout } = useTimeout()
136
137 const handleCopy = async () => {
138 try {
139 await copyTextToClipboard(textToCopy, {
140 suppressGlobalMessage: true,
141 })
142 const newState = copyButtonHandlers.handleCopy()
143 setIsCopied(newState.isCopied)
144 setIsHovered(newState.isHovered)
145 setTimeout('reset-copied', () => setIsCopied(false), COPIED_RESET_DELAY_MS)
146 } catch (_error) {
147 // Error is already logged and displayed by copyTextToClipboard
148 }
149 }
150
151 const handleMouseOver = () => {
152 const shouldHover = copyButtonHandlers.handleMouseOver(isCopied)
153 if (shouldHover) {
154 setIsHovered(true)
155 }
156 }
157
158 const handleMouseOut = () => {
159 setIsHovered(copyButtonHandlers.handleMouseOut())
160 }
161
162 return (
163 <Clickable
164 as="text"
165 style={style}
166 onMouseDown={handleCopy}
167 onMouseOver={handleMouseOver}
168 onMouseOut={handleMouseOut}
169 >
170 {children}
171 <CopyIcon
172 isCopied={isCopied}
173 isHovered={isHovered}
174 leadingSpace={leadingSpace}
175 />
176 </Clickable>
177 )
178}

Callers

nothing calls this directly

Calls 1

useTimeoutFunction · 0.90

Tested by

no test coverage detected