2026-04-23 15:33:11 +03:30
|
|
|
import React from 'react';
|
|
|
|
|
|
2026-05-06 02:20:19 +03:30
|
|
|
export type BadgeVariant = 'success' | 'warning' | 'danger' | 'default';
|
2026-04-23 15:33:11 +03:30
|
|
|
|
|
|
|
|
interface BadgeProps {
|
2026-05-06 02:20:19 +03:30
|
|
|
children: React.ReactNode;
|
|
|
|
|
variant?: BadgeVariant;
|
|
|
|
|
className?: string;
|
|
|
|
|
/**
|
|
|
|
|
* Same pixel width for every badge (table columns).
|
|
|
|
|
* Set false only when the pill should shrink to the label.
|
|
|
|
|
*/
|
|
|
|
|
fixedWidth?: boolean;
|
2026-04-23 15:33:11 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const variantStyles: Record<BadgeVariant, string> = {
|
2026-05-06 02:20:19 +03:30
|
|
|
success: 'bg-emerald-900/30 text-emerald-300 border-emerald-700/60',
|
|
|
|
|
warning: 'bg-amber-900/30 text-amber-300 border-amber-700/60',
|
|
|
|
|
danger: 'bg-red-950/30 text-red-300 border-red-700/60',
|
|
|
|
|
default: 'bg-background-secondary text-text-secondary border-border',
|
2026-04-23 15:33:11 +03:30
|
|
|
};
|
|
|
|
|
|
2026-05-06 02:20:19 +03:30
|
|
|
/** Explicit width + height so every row matches; flex centers label optically. */
|
|
|
|
|
const FIXED_LAYOUT_CLASS =
|
|
|
|
|
'w-[8rem] min-w-[8rem] max-w-[8rem] shrink-0 h-7 px-2 py-0';
|
|
|
|
|
|
2026-04-23 15:33:11 +03:30
|
|
|
export function Badge({
|
2026-05-06 02:20:19 +03:30
|
|
|
children,
|
|
|
|
|
variant = 'default',
|
|
|
|
|
className,
|
|
|
|
|
fixedWidth = true,
|
2026-04-23 15:33:11 +03:30
|
|
|
}: BadgeProps) {
|
2026-05-06 02:20:19 +03:30
|
|
|
const layoutClass = fixedWidth
|
|
|
|
|
? `${FIXED_LAYOUT_CLASS} justify-center text-center`
|
|
|
|
|
: 'min-h-[1.75rem] px-2.5 py-1 justify-center';
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<span
|
|
|
|
|
className={`inline-flex items-center box-border rounded-md border text-xs font-medium leading-none whitespace-nowrap ${variantStyles[variant]} ${layoutClass} ${className ?? ''}`}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Map organization link / invitation row status to badge variant. */
|
|
|
|
|
export function organizationLinkStatusVariant(status: string): BadgeVariant {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case 'ACTIVE':
|
|
|
|
|
return 'success';
|
|
|
|
|
case 'PENDING':
|
|
|
|
|
return 'warning';
|
|
|
|
|
case 'REJECTED':
|
|
|
|
|
case 'EXPIRED':
|
|
|
|
|
return 'danger';
|
|
|
|
|
default:
|
|
|
|
|
return 'default';
|
|
|
|
|
}
|
|
|
|
|
}
|