Skip to content

Commit

Permalink
feat: allow to pass button variants to alert dialog buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxi-ream committed Jan 7, 2025
1 parent 1081536 commit be864d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
20 changes: 9 additions & 11 deletions apps/www/registry/default/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from "react"
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"

import { cn } from "@/lib/utils"
import { buttonVariants } from "@/registry/default/ui/button"
import { buttonVariants, type ButtonProps } from "@/registry/default/ui/button"

const AlertDialog = AlertDialogPrimitive.Root

Expand Down Expand Up @@ -100,27 +100,25 @@ AlertDialogDescription.displayName =

const AlertDialogAction = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Action>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
>(({ className, ...props }, ref) => (
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action> &
Pick<ButtonProps, "variant" | "size">
>(({ className, variant = "default", size = "default", ...props }, ref) => (
<AlertDialogPrimitive.Action
ref={ref}
className={cn(buttonVariants(), className)}
className={cn(buttonVariants({ variant, size }), className)}
{...props}
/>
))
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName

const AlertDialogCancel = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
>(({ className, ...props }, ref) => (
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel> &
Pick<ButtonProps, "variant" | "size">
>(({ className, variant = "outline", size = "default", ...props }, ref) => (
<AlertDialogPrimitive.Cancel
ref={ref}
className={cn(
buttonVariants({ variant: "outline" }),
"mt-2 sm:mt-0",
className
)}
className={cn(buttonVariants({ variant, size }), "mt-2 sm:mt-0", className)}
{...props}
/>
))
Expand Down
20 changes: 9 additions & 11 deletions apps/www/registry/new-york/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from "react"
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"

import { cn } from "@/lib/utils"
import { buttonVariants } from "@/registry/new-york/ui/button"
import { buttonVariants, type ButtonProps } from "@/registry/new-york/ui/button"

const AlertDialog = AlertDialogPrimitive.Root

Expand Down Expand Up @@ -100,27 +100,25 @@ AlertDialogDescription.displayName =

const AlertDialogAction = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Action>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
>(({ className, ...props }, ref) => (
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action> &
Pick<ButtonProps, "variant" | "size">
>(({ className, variant = "default", size = "default", ...props }, ref) => (
<AlertDialogPrimitive.Action
ref={ref}
className={cn(buttonVariants(), className)}
className={cn(buttonVariants({ variant, size }), className)}
{...props}
/>
))
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName

const AlertDialogCancel = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
>(({ className, ...props }, ref) => (
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel> &
Pick<ButtonProps, "variant" | "size">
>(({ className, variant = "outline", size = "default", ...props }, ref) => (
<AlertDialogPrimitive.Cancel
ref={ref}
className={cn(
buttonVariants({ variant: "outline" }),
"mt-2 sm:mt-0",
className
)}
className={cn(buttonVariants({ variant, size }), "mt-2 sm:mt-0", className)}
{...props}
/>
))
Expand Down

0 comments on commit be864d2

Please sign in to comment.