Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,110 @@
|
||||
import * as React from "react";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
const badgeVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-brand-brand-border-solid-default focus-visible:shadow-focus aria-invalid:shadow-focus aria-invalid:border-surface-feedback-subtle-negative transition-[color,box-shadow] overflow-hidden",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "border-transparent bg-brand-brand-surface-solid-default text-text-neutral-on-solid [a&]:hover:bg-brand-brand-surface-solid-hover",
|
||||
secondary: "border-transparent bg-surface-neutral-secondary text-text-neutral-primary [a&]:hover:bg-surface-neutral-tertiary",
|
||||
destructive:
|
||||
"border-transparent bg-surface-feedback-solid-negative-default text-white [a&]:hover:bg-surface-feedback-solid-negative-hover focus-visible:shadow-focus dark:bg-surface-feedback-solid-negative-default",
|
||||
outline: "text-text-neutral-primary [a&]:hover:bg-surface-neutral-secondary [a&]:hover:text-text-neutral-primary",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export type BadgeColor = "green" | "red" | "yellow" | "blue" | "gray" | "orange" | "purple" | "emerald";
|
||||
|
||||
function getColorClasses(color: BadgeColor): string {
|
||||
switch (color) {
|
||||
case "green":
|
||||
case "emerald":
|
||||
return "border-green-500 bg-green-500/5 text-green-800 dark:text-green-300";
|
||||
case "red":
|
||||
return "border-red-500 bg-red-500/5 text-red-800 dark:text-red-300";
|
||||
case "yellow":
|
||||
return "border-yellow-500 bg-yellow-500/5 text-yellow-800 dark:text-yellow-300";
|
||||
case "blue":
|
||||
return "border-blue-500 bg-blue-500/5 text-blue-800 dark:text-blue-300";
|
||||
case "orange":
|
||||
return "border-orange-500 bg-orange-500/5 text-orange-800 dark:text-orange-300";
|
||||
case "purple":
|
||||
return "border-purple-500 bg-purple-500/5 text-purple-800 dark:text-purple-300";
|
||||
case "gray":
|
||||
default:
|
||||
return "border-gray-500 bg-gray-500/5 text-gray-800 dark:text-gray-300";
|
||||
}
|
||||
}
|
||||
|
||||
function getDotColor(color: BadgeColor): string {
|
||||
switch (color) {
|
||||
case "green":
|
||||
case "emerald":
|
||||
return "bg-green-400";
|
||||
case "red":
|
||||
return "bg-red-400";
|
||||
case "yellow":
|
||||
return "bg-yellow-400";
|
||||
case "blue":
|
||||
return "bg-blue-400";
|
||||
case "orange":
|
||||
return "bg-orange-400";
|
||||
case "purple":
|
||||
return "bg-purple-400";
|
||||
case "gray":
|
||||
default:
|
||||
return "bg-gray-400";
|
||||
}
|
||||
}
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant,
|
||||
color,
|
||||
withColorDot = false,
|
||||
asChild = false,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"span"> &
|
||||
VariantProps<typeof badgeVariants> & {
|
||||
asChild?: boolean;
|
||||
color?: BadgeColor;
|
||||
withColorDot?: boolean;
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "span";
|
||||
|
||||
// If color is provided, use color-based styling
|
||||
if (color) {
|
||||
return (
|
||||
<Comp
|
||||
data-slot="badge"
|
||||
className={cn(
|
||||
"inline-flex w-fit shrink-0 items-center justify-center gap-1.5 overflow-hidden rounded-md border px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow]",
|
||||
getColorClasses(color),
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{withColorDot && <span className={cn("size-2 shrink-0 rounded-full", getDotColor(color))} />}
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Comp data-slot="badge" className={cn(badgeVariants({ variant }), className)} {...props}>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants, getColorClasses, getDotColor };
|
||||
Reference in new issue
Block a user