mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-23 04:35:46 +00:00
72 lines
1.2 KiB
Plaintext
72 lines
1.2 KiB
Plaintext
---
|
|
title: Badge
|
|
description: Displays a badge or a component that looks like a badge.
|
|
component: true
|
|
---
|
|
|
|
<ComponentPreview
|
|
name="badge-demo"
|
|
title="Badge"
|
|
description="A default badge"
|
|
/>
|
|
|
|
## Installation
|
|
|
|
<CodeTabs>
|
|
|
|
<TabsList>
|
|
<TabsTrigger value="cli">CLI</TabsTrigger>
|
|
<TabsTrigger value="manual">Manual</TabsTrigger>
|
|
</TabsList>
|
|
<TabsContent value="cli">
|
|
|
|
```bash
|
|
npx shadcn@latest add badge
|
|
```
|
|
|
|
</TabsContent>
|
|
|
|
<TabsContent value="manual">
|
|
|
|
<Steps>
|
|
|
|
<Step>Copy and paste the following code into your project.</Step>
|
|
|
|
<ComponentSource name="badge" title="components/ui/badge.tsx" />
|
|
|
|
<Step>Update the import paths to match your project setup.</Step>
|
|
|
|
</Steps>
|
|
|
|
</TabsContent>
|
|
|
|
</CodeTabs>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import { Badge } from "@/components/ui/badge"
|
|
```
|
|
|
|
```tsx
|
|
<Badge variant="default | outline | secondary | destructive">Badge</Badge>
|
|
```
|
|
|
|
### Link
|
|
|
|
You can use the `asChild` prop to make another component look like a badge. Here's an example of a link that looks like a badge.
|
|
|
|
```tsx showLineNumbers
|
|
import Link from "next/link"
|
|
|
|
import { Badge } from "@/components/ui/badge"
|
|
|
|
export function LinkAsBadge() {
|
|
return (
|
|
<Badge asChild>
|
|
<Link href="/">Badge</Link>
|
|
</Badge>
|
|
)
|
|
}
|
|
```
|