minor fixes
This commit is contained in:
@@ -3,6 +3,7 @@ import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/utils/cn";
|
||||
import { Loader2 } from "lucide-react";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
||||
@@ -37,18 +38,24 @@ interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
loading?: boolean;
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
(
|
||||
{ className, variant, size, asChild = false, children, loading, disabled, ...props },
|
||||
ref,
|
||||
) => {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
return (
|
||||
// @ts-expect-error
|
||||
<Comp
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
disabled={loading ?? disabled}
|
||||
{...props}
|
||||
/>
|
||||
>
|
||||
{loading ? <Loader2 className="animate-spin" /> : <>{children}</>}
|
||||
</Comp>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -3,7 +3,9 @@ import * as React from "react"
|
||||
import { cn } from "@/utils/cn"
|
||||
|
||||
export type RadioGroupProps = React.InputHTMLAttributes<HTMLDivElement>
|
||||
export type RadioGroupItemProps = React.InputHTMLAttributes<HTMLButtonElement>
|
||||
export type RadioGroupItemProps = React.InputHTMLAttributes<HTMLButtonElement> & {
|
||||
active?: boolean
|
||||
}
|
||||
|
||||
const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(
|
||||
({ className, type, ...props }, ref) => {
|
||||
@@ -20,9 +22,9 @@ const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(
|
||||
}
|
||||
)
|
||||
|
||||
const RadioGroupItem = React.forwardRef<HTMLButtonElement, RadioGroupItemProps>(({className, ...props}, ref) => {
|
||||
const RadioGroupItem = React.forwardRef<HTMLButtonElement, RadioGroupItemProps>(({className, active, ...props}, ref) => {
|
||||
return (
|
||||
<button {...props} className={cn('flex-1 px-3 whitespace-nowrap leading-none hover:bg-slate-100 transition-colors font-medium', className)} type="button" ref={ref} />
|
||||
<button {...props} className={cn('flex-1 px-3 whitespace-nowrap leading-none hover:bg-slate-100 transition-colors font-medium', className, active && 'bg-slate-100')} type="button" ref={ref} />
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user