Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add support for icons and warning variant in Badge component#17350

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
brettkolodny merged 5 commits intomainfromjaaydenh/badge-update
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletionssite/src/components/Badge/Badge.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import { Settings, TriangleAlert } from "lucide-react";
import { Badge } from "./Badge";

const meta: Meta<typeof Badge> = {
Expand All@@ -13,3 +14,25 @@ export default meta;
type Story = StoryObj<typeof Badge>;

export const Default: Story = {};

export const Warning: Story = {
args: {
variant: "warning",
},
};

export const SmallWithIcon: Story = {
args: {
variant: "default",
size: "sm",
children: <>{<Settings />} Preset</>,
},
};

export const MediumWithIcon: Story = {
args: {
variant: "warning",
size: "md",
children: <>{<TriangleAlert />} Immutable</>,
},
};
43 changes: 25 additions & 18 deletionssite/src/components/Badge/Badge.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,21 +2,26 @@
* Copied from shadc/ui on 11/13/2024
* @see {@link https://ui.shadcn.com/docs/components/badge}
*/
import { Slot } from "@radix-ui/react-slot";
import { type VariantProps, cva } from "class-variance-authority";
importtype { FC } from "react";
import{ forwardRef } from "react";
import { cn } from "utils/cn";

export const badgeVariants = cva(
"inline-flex items-center rounded-md border px-2 py-1 transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
`inline-flex items-center rounded-md border px-2 py-1 transition-colors
focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2
[&_svg]:pointer-events-none [&_svg]:pr-0.5 [&_svg]:py-0.5 [&_svg]:mr-0.5`,
{
variants: {
variant: {
default:
"border-transparent bg-surface-secondary text-content-secondary shadow",
warning:
"border-transparent bg-surface-orange text-content-warning shadow",
},
size: {
sm: "text-2xs font-regular",
md: "text-xs font-medium",
sm: "text-2xs font-regular h-5.5 [&_svg]:size-icon-xs",
md: "text-xs font-medium [&_svg]:size-icon-sm",
},
},
defaultVariants: {
Expand All@@ -28,18 +33,20 @@ export const badgeVariants = cva(

export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}
VariantProps<typeof badgeVariants> {
asChild?: boolean;
}

export const Badge: FC<BadgeProps> = ({
className,
variant,
size,
...props
}) => {
return (
<div
className={cn(badgeVariants({ variant, size }), className)}
{...props}
/>
);
};
export const Badge = forwardRef<HTMLDivElement,BadgeProps>(
({className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "div";

return (
<Comp
{...props}
ref={ref}
className={cn(badgeVariants({ variant, size }), className)}
/>
);
},
);
Loading

[8]ページ先頭

©2009-2025 Movatter.jp