Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

2.4 KB
Raw Blame
import { ChevronRightIcon } from 'lucide-react'
import Link from 'next/link'
import React, { ReactNode } from 'react'
import { Badge, cn } from 'ui'

interface Props {
  url: string
  announcement: string | ReactNode
  /* Text or node to display on mobile */
  announcementMobile?: string | ReactNode
  badge?: string | ReactNode
  target?: '_self' | '_blank' | string
  className?: string
  hasArrow?: boolean
  style?: React.CSSProperties
}

const AnnouncementBadge = ({
  url,
  announcement,
  announcementMobile,
  badge,
  target = '_self',
  className,
  hasArrow = true,
  style,
}: Props) => (
  <div className={cn('relative w-fit max-w-xl flex justify-center', className)} style={style}>
    <Link
      href={url}
      target={target}
      className={cn(
        `
          announcement-link
          text-nowrap
          group/announcement
          relative
          flex flex-row
          items-center
          p-1 pr-0.5
          text-sm
          w-auto
          gap-1.5
          text-left
          rounded-full
          border
          border-background-surface-300
          hover:border-foreground-muted/30
          shadow-md
          overflow-hidden
          focus-ring rounded-full
          `,
        !badge && 'pl-5'
      )}
    >
      {badge && (
        <Badge variant="success" className="py-1 announcement-badge">
          {badge}
        </Badge>
      )}
      <span
        className={cn('text-foreground announcement-text line-clamp-1 w-full', {
          // only hide if announcementMobile is provided
          'hidden md:[display:-webkit-box]': announcementMobile,
        })}
      >
        {announcement}
      </span>
      {announcementMobile && (
        <span className="text-foreground announcement-text-mobile md:hidden line-clamp-1">
          {announcementMobile}
        </span>
      )}

      {hasArrow && (
        <ChevronRightIcon className="announcement-icon h-4 ml-2 -translate-x-1 text-foreground transition-transform group-hover/announcement:translate-x-0" />
      )}
      <div
        className="announcement-overlay absolute inset-0 -z-10 bg-linear-to-br
            opacity-70
            group-hover/announcement:opacity-100
            transition-opacity
            overflow-hidden rounded-full
            from-background-surface-100
            to-background-surface-300
            backdrop-blur-md
            "
      />
    </Link>
  </div>
)

export default AnnouncementBadge