Badge
solid-ui/badgeFreeComponent
A badge component
Live preview
live · rendered by the registry
Rendered by solid-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.solid-ui.com/r/badge.jsonSource
1import type { Component, ComponentProps } from "solid-js"2import { splitProps } from "solid-js"34import type { VariantProps } from "class-variance-authority"5import { cva } from "class-variance-authority"67import { cn } from "~/lib/utils"89const badgeVariants = cva(10 "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",11 {12 variants: {13 variant: {14 default: "border-transparent bg-primary text-primary-foreground",15 secondary: "border-transparent bg-secondary text-secondary-foreground",16 outline: "text-foreground",17 success: "border-success-foreground bg-success text-success-foreground",18 warning: "border-warning-foreground bg-warning text-warning-foreground",19 error: "border-error-foreground bg-error text-error-foreground"20 }21 },22 defaultVariants: {23 variant: "default"24 }25 }26)2728type BadgeProps = ComponentProps<"div"> &29 VariantProps<typeof badgeVariants> & {30 round?: boolean31 }3233const Badge: Component<BadgeProps> = (props) => {34 const [local, others] = splitProps(props, ["class", "variant", "round"])35 return (36 <div37 class={cn(38 badgeVariants({ variant: local.variant }),39 local.round && "rounded-full",40 local.class41 )}42 {...others}43 />44 )45}4647export type { BadgeProps }48export { Badge, badgeVariants }
What it pulls in
npm packages
Files it writes
More from solid-ui
All 55 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | solid-ui | Components | Free | 2 deps | |
| Alertalert | solid-ui | Components | Free | 3 deps | |
| Alert Dialogalert-dialog | solid-ui | Components | Free | 2 deps | |
| Aspect Ratioaspect-ratio | solid-ui | Components | Free | 1 dep | |
| Avataravatar | solid-ui | Components | Free | 2 deps | |
| Badge Deltabadge-delta | solid-ui | Components | Free | 2 deps | |
| Bar Listbar-list | solid-ui | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | solid-ui | Components | Free | 2 deps |
