-
-
Notifications
You must be signed in to change notification settings - Fork 55
Badge component #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
afrussel
wants to merge
2
commits into
afsar-dev:main
Choose a base branch
from
afrussel:badges-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Badge component #191
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // components/nurui/badge-demo.tsx | ||
| import { Badge } from "@/components/nurui/badge"; | ||
|
|
||
| export function BadgeDemo({ className }: { className?: string }) { | ||
| return ( | ||
| <div className={`flex flex-wrap items-center justify-center gap-3 p-8 ${className || ""}`}> | ||
| <Badge variant="default">Primary</Badge> | ||
| <Badge variant="secondary">Secondary</Badge> | ||
| <Badge variant="success">Success</Badge> | ||
| <Badge variant="danger">Danger</Badge> | ||
| <Badge variant="warning">Warning</Badge> | ||
| <Badge variant="info">Info</Badge> | ||
| <Badge variant="light">Light</Badge> | ||
| <Badge variant="dark">Dark</Badge> | ||
| <Badge variant="outline">Outline</Badge> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // components/nurui/badge.tsx | ||
| import * as React from "react"; | ||
| import { cva, type VariantProps } from "class-variance-authority"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| const badgeVariants = cva( | ||
| "inline-flex items-center rounded-full px-3 py-1 text-sm font-medium transition-colors", | ||
| { | ||
| variants: { | ||
| variant: { | ||
| default: "bg-blue-100 text-blue-800 hover:bg-blue-200 dark:bg-blue-900 dark:text-blue-100", | ||
| secondary: "bg-gray-100 text-gray-800 hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-100", | ||
| success: "bg-green-100 text-green-800 hover:bg-green-200 dark:bg-green-900 dark:text-green-100", | ||
| danger: "bg-red-100 text-red-800 hover:bg-red-200 dark:bg-red-900 dark:text-red-100", | ||
| warning: "bg-yellow-100 text-yellow-800 hover:bg-yellow-200 dark:bg-yellow-900 dark:text-yellow-100", | ||
| info: "bg-cyan-100 text-cyan-800 hover:bg-cyan-200 dark:bg-cyan-900 dark:text-cyan-100", | ||
| light: "bg-gray-50 text-gray-700 hover:bg-gray-100 dark:bg-gray-700 dark:text-gray-200", | ||
| dark: "bg-gray-900 text-gray-100 hover:bg-gray-800 dark:bg-gray-100 dark:text-gray-900", | ||
| outline: "border border-gray-300 text-gray-700 hover:bg-gray-50 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-800", | ||
| }, | ||
| }, | ||
| defaultVariants: { | ||
| variant: "default", | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| export interface BadgeProps | ||
| extends React.HTMLAttributes<HTMLDivElement>, | ||
| VariantProps<typeof badgeVariants> {} | ||
|
|
||
| function Badge({ className, variant, ...props }: BadgeProps) { | ||
| return ( | ||
| <div className={cn(badgeVariants({ variant }), className)} {...props} /> | ||
| ); | ||
| } | ||
|
|
||
| export { Badge, badgeVariants }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| --- | ||
| title: "Badge" | ||
| description: "Displays a badge or a component that looks like a badge." | ||
| --- | ||
|
|
||
| <ComponentPreview componentName="badge" /> | ||
|
|
||
| ## Installation | ||
|
|
||
| <Tabs defaultValue="cli"> | ||
|
|
||
| <TabsList> | ||
| <TabsTrigger value="cli">CLI</TabsTrigger> | ||
| <TabsTrigger value="manual">Manual</TabsTrigger> | ||
| </TabsList> | ||
|
|
||
| <TabsContent value="cli"> | ||
| <Cli /> | ||
| </TabsContent> | ||
|
|
||
| <TabsContent value="manual"> | ||
|
|
||
| <Steps> | ||
|
|
||
| <Step>Install dependencies</Step> | ||
|
|
||
| <Cli isManual /> | ||
|
|
||
| <Step>Add util file</Step> | ||
|
|
||
| `lib/utils.ts` | ||
|
|
||
| <CodeBlock snippetKey="utils-ts" /> | ||
|
|
||
| <Step>Copy and paste the following code into your project.</Step> | ||
|
|
||
| `components/nurui/badge.tsx` | ||
|
|
||
| <CodeBlock componentName="badge" fileName="badge" /> | ||
|
|
||
| <Step>Update the import paths to match your project setup.</Step> | ||
|
|
||
| </Steps> | ||
|
|
||
| </TabsContent> | ||
|
|
||
| </Tabs> | ||
|
|
||
| ### Props | ||
|
|
||
| | Prop | Type | Default | Description | | ||
| | ----------- | -------- | ----------- | -------------------------------------------------------------- | | ||
| | `variant` | `string` | `"default"` | The visual variant of the badge. Options: `default`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark`, `outline`. | | ||
| | `className` | `string` | `""` | Additional custom classes for positioning or styling the badge.| | ||
|
|
||
| ### Variants | ||
|
|
||
| | Variant | Description | | ||
| | ----------- | ------------------------------ | | ||
| | `default` | Primary badge with blue color | | ||
| | `secondary` | Secondary badge with gray color| | ||
| | `success` | Success badge with green color | | ||
| | `danger` | Danger badge with red color | | ||
| | `warning` | Warning badge with yellow color| | ||
| | `info` | Info badge with cyan color | | ||
| | `light` | Light badge with light gray | | ||
| | `dark` | Dark badge with dark gray | | ||
| | `outline` | Outlined badge with border | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.