mirror of
https://github.com/hanzoai/shadcn.git
synced 2026-10-30 18:22:59 +00:00
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import * as React from "react"
|
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
import { X } from "lucide-react"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
|
|
const pillVariants = cva(
|
|
"inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-sm font-medium transition-colors",
|
|
{
|
|
variants: {
|
|
variant: {
|
|
default: "bg-primary/10 text-primary hover:bg-primary/20",
|
|
secondary:
|
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
outline:
|
|
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
success:
|
|
"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
|
|
warning:
|
|
"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400",
|
|
error: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
variant: "default",
|
|
},
|
|
}
|
|
)
|
|
|
|
export interface PillProps
|
|
extends React.HTMLAttributes<HTMLSpanElement>,
|
|
VariantProps<typeof pillVariants> {
|
|
onRemove?: () => void
|
|
}
|
|
|
|
const Pill = React.forwardRef<HTMLSpanElement, PillProps>(
|
|
({ className, variant, onRemove, children, ...props }, ref) => {
|
|
return (
|
|
<span
|
|
ref={ref}
|
|
className={cn(pillVariants({ variant }), className)}
|
|
{...props}
|
|
>
|
|
{children}
|
|
{onRemove && (
|
|
<button
|
|
type="button"
|
|
onClick={onRemove}
|
|
className="ml-0.5 rounded-full p-0.5 hover:bg-black/10 dark:hover:bg-white/10"
|
|
>
|
|
<X className="h-3 w-3" />
|
|
<span className="sr-only">Remove</span>
|
|
</button>
|
|
)}
|
|
</span>
|
|
)
|
|
}
|
|
)
|
|
Pill.displayName = "Pill"
|
|
|
|
export { Pill, pillVariants }
|