|
| 1 | +import type { VariantProps } from "class-variance-authority"; |
| 2 | + |
| 3 | +import { cva } from "class-variance-authority"; |
| 4 | +import { StarIcon } from "lucide-react"; |
| 5 | + |
| 6 | +import type { ButtonProps as ButtonPrimitiveProps } from "@/components/animate-ui/primitives/buttons/button"; |
| 7 | +import type { GithubStarsProps } from "@/components/animate-ui/primitives/animate/github-stars"; |
| 8 | + |
| 9 | +import { |
| 10 | + GithubStars, |
| 11 | + GithubStarsIcon, |
| 12 | + GithubStarsLogo, |
| 13 | + GithubStarsNumber, |
| 14 | + GithubStarsParticles, |
| 15 | +} from "@/components/animate-ui/primitives/animate/github-stars"; |
| 16 | +import { Button as ButtonPrimitive } from "@/components/animate-ui/primitives/buttons/button"; |
| 17 | +import { cn } from "@/lib/utils"; |
| 18 | + |
| 19 | +const buttonVariants = cva( |
| 20 | + "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-[box-shadow,_color,_background-color,_border-color,_outline-color,_text-decoration-color,_fill,_stroke] disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive", |
| 21 | + { |
| 22 | + variants: { |
| 23 | + variant: { |
| 24 | + default: "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90", |
| 25 | + accent: "bg-accent text-accent-foreground shadow-xs hover:bg-accent/90", |
| 26 | + outline: |
| 27 | + "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50", |
| 28 | + ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50", |
| 29 | + }, |
| 30 | + size: { |
| 31 | + default: "h-9 px-4 py-2 has-[>svg]:px-3", |
| 32 | + sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5", |
| 33 | + lg: "h-10 rounded-md px-6 has-[>svg]:px-4", |
| 34 | + }, |
| 35 | + }, |
| 36 | + defaultVariants: { |
| 37 | + variant: "default", |
| 38 | + size: "default", |
| 39 | + }, |
| 40 | + }, |
| 41 | +); |
| 42 | + |
| 43 | +const buttonStarVariants = cva("", { |
| 44 | + variants: { |
| 45 | + variant: { |
| 46 | + default: "fill-neutral-700 stroke-neutral-700 dark:fill-neutral-300 dark:stroke-neutral-300", |
| 47 | + accent: "fill-neutral-300 stroke-neutral-300 dark:fill-neutral-700 dark:stroke-neutral-700", |
| 48 | + outline: "fill-neutral-300 stroke-neutral-300 dark:fill-neutral-700 dark:stroke-neutral-700", |
| 49 | + ghost: "fill-neutral-300 stroke-neutral-300 dark:fill-neutral-700 dark:stroke-neutral-700", |
| 50 | + }, |
| 51 | + }, |
| 52 | + defaultVariants: { |
| 53 | + variant: "default", |
| 54 | + }, |
| 55 | +}); |
| 56 | + |
| 57 | +type GitHubStarsButtonProps = Omit<ButtonPrimitiveProps & GithubStarsProps, "asChild" | "children"> |
| 58 | + & VariantProps<typeof buttonVariants>; |
| 59 | + |
| 60 | +function GitHubStarsButton({ |
| 61 | + className, |
| 62 | + username, |
| 63 | + repo, |
| 64 | + value, |
| 65 | + delay, |
| 66 | + inView, |
| 67 | + inViewMargin, |
| 68 | + inViewOnce, |
| 69 | + variant, |
| 70 | + size, |
| 71 | + ...props |
| 72 | +}: GitHubStarsButtonProps) { |
| 73 | + return ( |
| 74 | + <GithubStars |
| 75 | + asChild |
| 76 | + username={username} |
| 77 | + repo={repo} |
| 78 | + value={value} |
| 79 | + delay={delay} |
| 80 | + inView={inView} |
| 81 | + inViewMargin={inViewMargin} |
| 82 | + inViewOnce={inViewOnce} |
| 83 | + > |
| 84 | + <ButtonPrimitive className={cn(buttonVariants({ variant, size, className }))} {...props}> |
| 85 | + <GithubStarsLogo /> |
| 86 | + <GithubStarsNumber /> |
| 87 | + <GithubStarsParticles className="text-yellow-500"> |
| 88 | + <GithubStarsIcon |
| 89 | + icon={StarIcon} |
| 90 | + data-variant={variant} |
| 91 | + className={cn(buttonStarVariants({ variant }))} |
| 92 | + activeClassName="text-yellow-500" |
| 93 | + size={18} |
| 94 | + /> |
| 95 | + </GithubStarsParticles> |
| 96 | + </ButtonPrimitive> |
| 97 | + </GithubStars> |
| 98 | + ); |
| 99 | +} |
| 100 | + |
| 101 | +export { GitHubStarsButton, type GitHubStarsButtonProps }; |
0 commit comments