| 3 | import cn from 'mxcn'; |
| 4 | |
| 5 | export function CTAButtons({ |
| 6 | primary, |
| 7 | secondary, |
| 8 | example, |
| 9 | className |
| 10 | }: { |
| 11 | example?: boolean; |
| 12 | primary?: { |
| 13 | text: string; |
| 14 | sub?: string; |
| 15 | href: string; |
| 16 | }; |
| 17 | secondary?: { |
| 18 | text: string; |
| 19 | href: string; |
| 20 | }; |
| 21 | className?: string; |
| 22 | }) { |
| 23 | const isInternalLink = (href: string) => |
| 24 | href.startsWith('https://langbase.com/docs') || href.startsWith('/'); |
| 25 | |
| 26 | const LinkWrapper = ({ |
| 27 | href, |
| 28 | children, |
| 29 | ...props |
| 30 | }: React.AnchorHTMLAttributes<HTMLAnchorElement> & { href: string }) => { |
| 31 | if (isInternalLink(href)) { |
| 32 | return ( |
| 33 | <Link href={href} {...props}> |
| 34 | {children} |
| 35 | </Link> |
| 36 | ); |
| 37 | } |
| 38 | return ( |
| 39 | <a href={href} target="_blank" rel="noopener noreferrer" {...props}> |
| 40 | {children} |
| 41 | </a> |
| 42 | ); |
| 43 | }; |
| 44 | |
| 45 | return ( |
| 46 | <div className={cn('not-prose mb-16 mt-12 flex gap-3 flex-wrap', className)}> |
| 47 | {primary && ( |
| 48 | <LinkWrapper href={primary.href}> |
| 49 | <Button |
| 50 | arrow="right" |
| 51 | className="flex w-full justify-center sm:w-auto" |
| 52 | variant={example ? 'outline-background' : 'default'} |
| 53 | > |
| 54 | {primary.text} |
| 55 | <span className="ml-1 hidden text-background transition-colors duration-200 hover:text-background sm:inline dark:text-background dark:hover:text-muted"> |
| 56 | {primary.sub} |
| 57 | </span> |
| 58 | </Button> |
| 59 | </LinkWrapper> |
| 60 | )} |
| 61 | {secondary && ( |
| 62 | <LinkWrapper href={secondary.href}> |