({
text,
className,
}: ShareOnXButtonProps)
| 12 | } |
| 13 | |
| 14 | export default function ShareOnXButton({ |
| 15 | text, |
| 16 | className, |
| 17 | }: ShareOnXButtonProps) { |
| 18 | const [shareUrl, setShareUrl] = React.useState(""); |
| 19 | |
| 20 | React.useEffect(() => { |
| 21 | setShareUrl(window.location.href); |
| 22 | }, []); |
| 23 | |
| 24 | const onClick = React.useCallback(() => { |
| 25 | const intentUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent( |
| 26 | text |
| 27 | )}&url=${encodeURIComponent(shareUrl)}`; |
| 28 | window.open(intentUrl, "_blank", "noopener,noreferrer"); |
| 29 | }, [shareUrl, text]); |
| 30 | |
| 31 | return ( |
| 32 | <Button |
| 33 | variant="outline" |
| 34 | size="sm" |
| 35 | aria-label="Share on X" |
| 36 | className={className} |
| 37 | onClick={onClick} |
| 38 | disabled={!shareUrl} |
| 39 | > |
| 40 | <HugeiconsIcon icon={NewTwitterFreeIcons} /> |
| 41 | </Button> |
| 42 | ); |
| 43 | } |
nothing calls this directly
no outgoing calls
no test coverage detected