interface Props { className ? : string ; } export const CopyableCode = ( { children , className } ) => { const onSelect = ( event ) => { const selection = globalThis . getSelection ( ) ; if ( selection === null ) { return ; } const range = globalThis . document . createRange ( ) ; range . selectNode ( event . currentTarget ) ; selection . removeAllRanges ( ) ; selection . addRange ( range ) ; } ; const onDeselect = ( ) => { globalThis . getSelection ( ) ?. removeAllRanges ( ) ; } ; const onCopy = async ( event ) => { onSelect ( event ) ; } ; return ( < code className = { className } onClick = { onCopy } onMouseEnter = { onSelect } onMouseLeave = { onDeselect } children = { children } / > ) ; } ;