Badge
scrollxui/badgeFreeComponent
A small badge component with customizable variants and shiny animation effects.
Live preview
live · rendered by the registry
Rendered by scrollxui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://scrollxui.dev/registry/badge.jsonSource
1import * as React from 'react';2import { cva, type VariantProps } from 'class-variance-authority';3import { cn } from '@/lib/utils';45const badgeVariants = cva(6 'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2',7 {8 variants: {9 variant: {10 default:11 'border-transparent bg-primary text-primary-foreground hover:bg-primary/80',12 secondary:13 'border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80',14 destructive:15 'border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80',16 outline: 'text-foreground',17 },18 shiny: {19 true: 'relative overflow-hidden',20 false: '',21 },22 },23 defaultVariants: {24 variant: 'default',25 shiny: false,26 },27 },28);2930export interface BadgeProps31 extends32 React.HTMLAttributes<HTMLDivElement>,33 VariantProps<typeof badgeVariants> {34 shiny?: boolean;35 shinySpeed?: number;36}3738function Badge({39 className,40 variant,41 shiny = false,42 shinySpeed = 5,43 children,44 ...props45}: BadgeProps) {46 const animationDuration = `${shinySpeed}s`;4748 return (49 <div50 className={cn(badgeVariants({ variant, shiny }), className)}51 {...props}52 >53 <span className={shiny ? 'relative z-10' : ''}>{children}</span>5455 {shiny && (56 <span57 className='absolute inset-0 pointer-events-none animate-shine dark:hidden'58 style={{59 background:60 'linear-gradient(120deg, transparent 40%, rgba(255,255,255,0.6) 50%, transparent 60%)',61 backgroundSize: '200% 100%',62 animationDuration,63 mixBlendMode: 'screen',64 }}65 />66 )}6768 {shiny && (69 <span70 className='absolute inset-0 pointer-events-none animate-shine hidden dark:block'71 style={{72 background:73 'linear-gradient(120deg, transparent 40%, rgba(0,0,150,0.25) 50%, transparent 60%)',74 backgroundSize: '200% 100%',75 animationDuration,76 mixBlendMode: 'multiply',77 }}78 />79 )}80 </div>81 );82}8384export { Badge, badgeVariants };
What it pulls in
npm packages
Other registry items
Files it writes
More from scrollxui
All 180 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | scrollxui | Components | Free | 4 deps | |
| Alert Dialogalert-dialog | scrollxui | Components | Free | 7 deps | |
| Animated Buttonanimated-button | scrollxui | Components | Free | 4 deps | |
| Animated Tabsanimated-tabs | scrollxui | Components | Free | 1 dep | |
| Animated Testimonialsanimated-testimonials | scrollxui | Components | Free | 2 deps | |
| Animated TextGenerateanimated-textgenerate | scrollxui | Components | Free | 3 deps | |
| Announcementannouncement | scrollxui | Components | Free | 5 deps | |
| Aspect Ratioaspect-ratio | scrollxui | Components | Free | 1 dep |
